Commits

Juan Carlos Picado Herrera  committed 7c03bbd

LinkedIn Provider Test Cases, In progress

  • Participants
  • Parent commits a0712ea

Comments (0)

Files changed (8)

File encuestame-business/pom.xml

                 <groupId>org.springframework.social</groupId>
                 <artifactId>spring-social-core</artifactId>
             </dependency>
+            <dependency>
+                <groupId>org.springframework.social</groupId>
+                <artifactId>spring-social-facebook</artifactId>
+            </dependency>
+            <dependency>
+                <groupId>org.springframework.social</groupId>
+                <artifactId>spring-social-twitter</artifactId>
+            </dependency>
+            <dependency>
+                <groupId>org.springframework.social</groupId>
+                <artifactId>spring-social-linkedin</artifactId>
+            </dependency>
+            <dependency>
+                <groupId>org.springframework.social</groupId>
+                <artifactId>spring-social-github</artifactId>
+            </dependency>
+            <dependency>
+                <groupId>org.springframework.social</groupId>
+                <artifactId>spring-social-tripit</artifactId>
+            </dependency>
+            <dependency>
+                <groupId>org.springframework.social</groupId>
+                <artifactId>spring-social-web</artifactId>
+            </dependency>
+            <dependency>
+                <groupId>org.springframework.social</groupId>
+                <artifactId>spring-social-gowalla</artifactId>
+            </dependency>
               <!-- Spring Security -->
              <dependency>
                 <groupId>org.springframework.security</groupId>

File encuestame-business/src/main/java/org/encuestame/business/service/social/connect/AbstractISocialService.java

 import org.encuestame.persistence.exception.EnMeExpcetion;
 import org.encuestame.utils.oauth.AuthorizedRequestToken;
 import org.encuestame.utils.oauth.OAuthToken;
-import org.springframework.social.twitter.TwitterOperations;
 
 /**
  * Description Class.
         void disconnect(Long accountId);
 
 
-        String fetchProviderAccountId(TwitterOperations serviceOperations);
+        //String fetchProviderAccountId(TwitterOperations serviceOperations);
 
         /**
          * The key used to identify the local application with the remote service provider.

File encuestame-business/src/main/java/org/encuestame/business/service/social/connect/FacebookSocialService.java

 
 import org.encuestame.utils.oauth.OAuthToken;
 import org.springframework.beans.factory.annotation.Value;
-import org.springframework.social.facebook.FacebookOperations;
+import org.springframework.social.facebook.FacebookApi;
 import org.springframework.social.facebook.FacebookTemplate;
-import org.springframework.social.twitter.TwitterOperations;
 import org.springframework.social.twitter.TwitterTemplate;
 
 /**
  * @since Dec 25, 2010 5:57:35 PM
  * @version $Id:$
  */
-public class FacebookSocialService extends AbstractSocialProvider<FacebookOperations> implements IFacebookSocialService{
+public class FacebookSocialService extends AbstractSocialProvider<FacebookApi> implements IFacebookSocialService{
 
 
     /**
     }
 
     @Override
-    protected FacebookOperations createServiceOperations(OAuthToken accessToken) {
+    protected FacebookApi createServiceOperations(OAuthToken accessToken) {
         if (accessToken == null) {
             throw new IllegalStateException("Cannot access Facebook without an access token");
         }
     }
 
     @Override
-    protected String fetchProviderAccountId(FacebookOperations serviceOperations) {
+    protected String fetchProviderAccountId(FacebookApi serviceOperations) {
       return serviceOperations.getProfileId();
     }
 
     @Override
     protected String buildProviderProfileUrl(String providerAccountId,
-            FacebookOperations serviceOperations) {
+            FacebookApi serviceOperations) {
         return "http://www.facebook.com/profile.php?id=" + providerAccountId;
     }
 
         return null;
     }
 
-    public String fetchProviderAccountId(TwitterOperations serviceOperations) {
-        // TODO Auto-generated method stub
-        return null;
-    }
 }

File encuestame-business/src/main/java/org/encuestame/business/service/social/connect/LinkedInSocialService.java

 
 import org.encuestame.utils.oauth.OAuthToken;
 import org.springframework.beans.factory.annotation.Value;
-import org.springframework.social.linkedin.LinkedInOperations;
+import org.springframework.social.linkedin.LinkedInApi;
+import org.springframework.social.linkedin.LinkedInApi;
 import org.springframework.social.linkedin.LinkedInTemplate;
 
 /**
  * @since Dec 25, 2010 5:57:35 PM
  * @version $Id:$
  */
-public class LinkedInSocialService extends AbstractSocialProvider<LinkedInOperations>{
+public class LinkedInSocialService extends AbstractSocialProvider<LinkedInApi>{
 
     /**
      * Social Account Provider;
     }
 
     @Override
-    protected LinkedInOperations createServiceOperations(OAuthToken accessToken) {
+    protected LinkedInApi createServiceOperations(OAuthToken accessToken) {
         log.debug("Twitter Operations createServiceOperations "+accessToken.toString());
         if(this.linkedInTemplate == null){
             log.debug("Creando Provider");
      * Fetch Provider Account Id.
      */
     @Override
-    public String fetchProviderAccountId(LinkedInOperations serviceOperations) {
+    public String fetchProviderAccountId(LinkedInApi serviceOperations) {
       log.debug("MEAN fetchNewRequestToken "+serviceOperations.getProfileId());
       return serviceOperations.getProfileId();
     }
      */
     @Override
     protected String buildProviderProfileUrl(String providerAccountId,
-            LinkedInOperations serviceOperations) {
+            LinkedInApi serviceOperations) {
         return "url-" + providerAccountId;
     }
 

File encuestame-business/src/main/java/org/encuestame/business/service/social/connect/TwitterSocialService.java

 package org.encuestame.business.service.social.connect;
 
 import org.encuestame.utils.oauth.OAuthToken;
+import org.scribe.builder.api.TwitterApi;
 import org.springframework.beans.factory.annotation.Value;
-import org.springframework.social.twitter.TwitterOperations;
 import org.springframework.social.twitter.TwitterTemplate;
 
 /**
  * @since Dec 25, 2010 5:57:35 PM
  * @version $Id:$
  */
-public class TwitterSocialService extends AbstractSocialProvider<TwitterOperations> implements ITwitterSocialProvider{
+public class TwitterSocialService extends AbstractSocialProvider<TwitterApi> implements ITwitterSocialProvider{
 
     /**
      * Social Account Provider;
     }
 
     @Override
-    protected TwitterOperations createServiceOperations(OAuthToken accessToken) {
+    protected TwitterApi createServiceOperations(OAuthToken accessToken) {
         log.debug("Twitter Operations createServiceOperations "+accessToken.toString());
         if(this.twitterTemplate == null){
             log.debug("Creando Provider");
             this.createTwitterTemplate(accessToken);
         }
-        return this.twitterTemplate;
+        return null;
     }
 
     /**
     /**
      * Fetch Provider Account Id.
      */
-    @Override
-    public String fetchProviderAccountId(TwitterOperations serviceOperations) {
-      log.debug("MEAN fetchNewRequestToken "+serviceOperations.getProfileId());
-      return serviceOperations.getProfileId();
+    //@Override
+    public String fetchProviderAccountId(TwitterApi serviceOperations) {
+        return TWITTER_URL;
+      //log.debug("MEAN fetchNewRequestToken "+serviceOperations.getProfileId());
+      //return serviceOperations.getProfileId();
     }
 
     /**
      */
     @Override
     protected String buildProviderProfileUrl(String providerAccountId,
-            TwitterOperations serviceOperations) {
+            TwitterApi serviceOperations) {
         return this.TWITTER_URL + providerAccountId;
     }
 

File encuestame-business/src/main/java/org/encuestame/business/service/social/provider/LinkedInService.java

     String requestTokenUrl;
 
     public LinkedInService() {
+        System.out.println("**********************LinkedInService*************************************");
     }
 
     /**
      * @return
      */
     public String getAuthorizeLinkedInUrl() {
-        OAuthService service = new ServiceBuilder().provider(LinkedInApi.class)
-                .apiKey(this.apiKey).apiSecret(this.consumerKey).build();
+        System.out.println("*****"+this.apiKey);
+        System.out.println("*****"+this.consumerSecret);
+        OAuthService service = new ServiceBuilder()
+                .provider(LinkedInApi.class)
+                .apiKey(this.apiKey)
+                .apiSecret(this.consumerSecret).build();
         Token requestToken = service.getRequestToken();
+        System.out.println("*****"+requestToken);
         String myToken = requestToken.getToken();
         String completeUrl = org.apache.commons.lang.StringUtils.replace(
                 this.authorizeUrl, "{token}", myToken);
+        System.out.println("*****"+completeUrl);
         return completeUrl;
     }
 }

File encuestame-business/src/test/java/org/encuestame/test/business/social/SocialServiceTestCase.java

 
 package org.encuestame.test.business.social;
 
-import org.encuestame.business.service.AbstractBaseService;
 import org.encuestame.business.service.imp.ILinkedInService;
+import org.encuestame.business.service.social.connect.ITwitterSocialProvider;
 import org.encuestame.business.service.social.connect.TwitterSocialService;
+import org.encuestame.test.business.service.config.AbstractServiceBase;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.social.connect.support.ConnectionRepository;
+import org.springframework.social.linkedin.connect.LinkedInServiceProvider;
+import org.springframework.social.oauth1.OAuth1Template;
+import org.springframework.social.oauth1.OAuthToken;
 import org.springframework.util.Assert;
+import org.springframework.web.context.request.WebRequest;
 
 
-public class SocialServiceTestCase extends AbstractBaseService{
+public class SocialServiceTestCase extends AbstractServiceBase{
 
     /**
      * Twitter Social Service.
      */
     @Autowired
-    private TwitterSocialService twitterSocialService;
+    private ITwitterSocialProvider twitterSocialService;
 
     /**
      *
      */
     @Test
     public void twitterSocialServiceTest(){
+        Assert.notNull(this.linkedInService);
         Assert.isTrue(true);
-        System.out.println(this.linkedInService.getAuthorizeLinkedInUrl());
+        ///System.out.println(this.linkedInService.getAuthorizeLinkedInUrl());
+
+        final String consumerKey = "5hkdPhtfkRwR0uRhIftai57FA0xbpH7m2fsBFfELvVLf6KMqw1X_FdzsgPkFORuS";
+        final String consumerSecret = "3Tuj7nXvACdCwffnbh-NkUXQ_Re0t1FPakogEPApw_3DBsfowdQuoggCCTd38a9o";
+        final String requestTokenUrl = "https://api.linkedin.com/uas/oauth/requestToken";
+        final String authorizeUrl = "https://www.linkedin.com/uas/oauth/authorize?oauth_token={requestToken}";
+        final String accessTokenUrl = "https://api.linkedin.com/uas/oauth/accessToken";
+        OAuth1Template tp =  new OAuth1Template(consumerKey, consumerSecret,
+                requestTokenUrl,
+                authorizeUrl,
+                accessTokenUrl);
+       OAuthToken requestToken = tp.fetchNewRequestToken("http://localhost:8080/encuestame/user/linkedIn");
+       System.out.println("********************************  OAuthToken * "+requestToken);
+       String url = tp.buildAuthorizeUrl(requestToken.getValue(), "http://localhost:8080/encuestame/user/linkedIn");
+       System.out.println("********URL "+url);
+        //request.setAttribute(OAUTH_TOKEN_ATTRIBUTE, requestToken, WebRequest.SCOPE_SESSION);
     }
 
 
     /**
      * @return the twitterSocialService
      */
-    public TwitterSocialService getTwitterSocialService() {
+    public ITwitterSocialProvider getTwitterSocialService() {
         return twitterSocialService;
     }
 
     /**
      * @param twitterSocialService the twitterSocialService to set
      */
-    public void setTwitterSocialService(TwitterSocialService twitterSocialService) {
+    public void setTwitterSocialService(ITwitterSocialProvider twitterSocialService) {
         this.twitterSocialService = twitterSocialService;
     }
 
     /**
      * @param linkedInService the linkedInService to set
      */
-    public void setLinkedInService(ILinkedInService linkedInService) {
+    public void setLinkedInService(final ILinkedInService linkedInService) {
         this.linkedInService = linkedInService;
     }
 }

File encuestame-war/pom.xml

                 <groupId>org.springframework.social</groupId>
                 <artifactId>spring-social-core</artifactId>
             </dependency>
+
+            <dependency>
+                <groupId>org.springframework.social</groupId>
+                <artifactId>spring-social-facebook</artifactId>
+            </dependency>
+            <dependency>
+                <groupId>org.springframework.social</groupId>
+                <artifactId>spring-social-twitter</artifactId>
+            </dependency>
+            <dependency>
+                <groupId>org.springframework.social</groupId>
+                <artifactId>spring-social-linkedin</artifactId>
+            </dependency>
+            <dependency>
+                <groupId>org.springframework.social</groupId>
+                <artifactId>spring-social-github</artifactId>
+            </dependency>
+            <dependency>
+                <groupId>org.springframework.social</groupId>
+                <artifactId>spring-social-tripit</artifactId>
+            </dependency>
+            <dependency>
+                <groupId>org.springframework.social</groupId>
+                <artifactId>spring-social-web</artifactId>
+            </dependency>
+            <dependency>
+                <groupId>org.springframework.social</groupId>
+                <artifactId>spring-social-gowalla</artifactId>
+            </dependency>
               <!-- Spring Security -->
              <dependency>
                 <groupId>org.springframework.security</groupId>