You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by wo...@apache.org on 2011/10/12 22:10:42 UTC

svn commit: r1182565 [6/9] - in /shindig/trunk: config/ content/samplecontainer/examples/commoncontainer/ content/samplecontainer/examples/oauth2/ features/src/main/javascript/features/core.io/ features/src/main/javascript/features/shindig.xhrwrapper/ ...

Added: shindig/trunk/java/gadgets/src/main/resources/org/apache/shindig/gadgets/oauth2/resource_en_US.properties
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/main/resources/org/apache/shindig/gadgets/oauth2/resource_en_US.properties?rev=1182565&view=auto
==============================================================================
--- shindig/trunk/java/gadgets/src/main/resources/org/apache/shindig/gadgets/oauth2/resource_en_US.properties (added)
+++ shindig/trunk/java/gadgets/src/main/resources/org/apache/shindig/gadgets/oauth2/resource_en_US.properties Wed Oct 12 20:10:39 2011
@@ -0,0 +1,81 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#  
+#   http://www.apache.org/licenses/LICENSE-2.0
+#  
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.  
+message_header= {0} encountered a problem :  
+authorization_code_problem=exchanging authorization_code for access_token : {0}
+authorization_code_problem.explanation=An error occured exchanging the authorization code for access_token.
+authorize_problem=initiating authorization {0}
+authorize_problem.explanation=An error occured initiating authorization.
+callback_problem=processing the redirect_uri response : {0}
+callback_problem.explanation=Error processing the redirect response from the service provider.
+client_credentials_problem=getting access_token from client_credentials : {0}
+client_credentials_problem.explanation=Error in the client_credentials flow.
+fetch_init_problem=initializing OAuth2Request : {0}
+fetch_init_problem.explanation=A low-level error occured intializing the OAuth2 request fetch.
+fetch_problem=executing OAuth2Request.fetch() : {0}
+fetch_problem.explanation=An error occurred issuing the OAuth2 request.
+gadget_spec_problem=processing the gadget spec : {0}
+gadget_spec_problem.explanation=A gadget spec was not found.  Most like your administrator has not configured your gadget to work with OAuth2.
+get_oauth2_accessor_problem=getting an OAuth2Accessor for the OAuth2Request : {0}
+get_oauth2_accessor_problem.explanation=The most common cause of this error is that your administrator has not created an OAuth2Client binding for this gadget and service.
+lookup_spec_problem=looking up the gadget spec : {0}
+lookup_spec_problem.explanation=A gadget spec was not found.  Most like your administrator has not configured your gadget to work with OAuth2.
+missing_fetch_params=there are missing required fetch params : {0} 
+missing_fetch_params.explanation=fetch() method was called with bad parameters.
+missing_server_response=problem with the OAuth2 service provider resonse : {0}
+missing_server_response.explanation=The server was able to create what it thought was a valid OAuth 2 request but was unable to issue the request or get a valid response from the service provider.
+no_response_handler=no response handler processed the response : {0}
+no_response_handler.explanation=There is no AuthorizationEndpointResponseHandler or TokenEndpointResponseHandler registered for what you are trying to do.
+no_gadget_spec=cannot find a gadget spec for {0}
+no_gadget_spec.explanation=A gadget spec was not found.  Most like your administrator has not configured your gadget to work with OAuth2.
+refresh_token_problem=exchanging the refresh_token for a new access_token : {0}
+refresh_token_problem.explanation=The system tried to exchaning a seemingly valid refresh_token for an access_token and encountered an error.
+secret_encryption_problem=encrytping token secret for persistence : {0}
+secret_encryption_problem.explanation=Error storing OAuth2 secrets with the provided encryption module.
+access_denied=access denied
+access_denied.explanation=User denied or canceled the authorization with the service provider.
+invalid_client=invalid client  : {0}
+invalid_client.explanation= Client authentication failed (e.g. unknown client, no client authentication included, or unsupported authentication method).
+invalid_grant=invalid grant : {0}
+invalid_grant.explanation=The provided authorization grant (e.g. authorization code, resource owner credentials, client credentials) is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client.
+invalid_request=invalid request : {0}
+invalid_request.explanation=The request is missing a required parameter, includes an unsupported parameter value, repeats a parameter, includes multiple credentials, utilizes more than one mechanism for authenticating the client, or is otherwise malformed.
+invalid_scope=invalid scope : {0}
+invalid_scope.explanation= The requested scope is invalid, unknown, malformed, or exceeds the scope granted by the resource owner.
+server_error=server error : {0}
+server_error.explanation=The authorization server encountered an unexpected condition which prevented it from fulfilling the request.
+server_rejected_request=server rejected request : statuscode = {0}
+server_rejected_request.explanation=The server was able to create what it thought was a valid OAuth 2 request but the OAuth 2 service provider rejected it.
+temporarily_unavailable=temporarily unavailable : {0}
+temporarily_unavailable.explanation=The authorization server is currently unable to handle the request due to a temporary overloading or maintenance of the server.
+token_response_problem=processing response from token endpoint : {0}
+token_response_problem.explanation=The token endpoint sent a response that the server could not process.
+unauthorized_client=unauthorized client : {0}
+unauthorized_client.explanation=The client is not authorized to request an access token using this method.
+unsupported_grant_type=unsupported grant type : {0}
+unsupported_grant_type.explanation=The authorization server does not support obtaining an access token using this method.
+unsupported_response_type=unsupported response type : {0}
+unsupported_response_type.explanation=The authorization server does not support obtaining an authorization code using this method.
+mac_token_problem=mac token request : {0}
+mac_token_problem.explanation=Could not add a mac token on the request to the resource server.
+bearer_token_problem=bearer token request : {0}
+bearer_token_problem.explanation=Could not add a bearer token on the request to the resource server.
+authentication_problem=adding client authentication : {0}
+authentication_problem.explanation=Could not add authentication headers to the request.
+unknown_problem=unknown problem : {0}
+unknown_problem.explanation=Please see your system administrator for help.
+code_grant_problem=getting access_token from authorization code : {0}
+code_grant_problem.explanation=Error in the authorization_code flow.
\ No newline at end of file

Modified: shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/AuthTypeTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/AuthTypeTest.java?rev=1182565&r1=1182564&r2=1182565&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/AuthTypeTest.java (original)
+++ shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/AuthTypeTest.java Wed Oct 12 20:10:39 2011
@@ -29,6 +29,8 @@ public class AuthTypeTest {
   public void testAuth() {
     assertEquals(AuthType.OAUTH, AuthType.parse("oauth"));
     assertEquals(AuthType.OAUTH, AuthType.parse("   oauth   "));
+    assertEquals(AuthType.OAUTH2, AuthType.parse("oauth2"));
+    assertEquals(AuthType.OAUTH2, AuthType.parse("   oauth2   "));
     assertEquals(AuthType.SIGNED, AuthType.parse("SiGnEd"));
     assertEquals(AuthType.NONE, AuthType.parse("NONE"));
     assertEquals(AuthType.NONE, AuthType.parse(""));
@@ -36,5 +38,6 @@ public class AuthTypeTest {
     assertEquals(AuthType.NONE, AuthType.parse("foo"));
     assertEquals("none", AuthType.NONE.toString());
     assertEquals("oauth", AuthType.OAUTH.toString());
+    assertEquals("oauth2", AuthType.OAUTH2.toString());
   }
 }

Modified: shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/DefaultInvalidationServiceTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/DefaultInvalidationServiceTest.java?rev=1182565&r1=1182564&r2=1182565&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/DefaultInvalidationServiceTest.java (original)
+++ shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/DefaultInvalidationServiceTest.java Wed Oct 12 20:10:39 2011
@@ -49,6 +49,7 @@ public class DefaultInvalidationServiceT
 
   DefaultRequestPipelineTest.FakeHttpFetcher fetcher;
   DefaultRequestPipelineTest.FakeOAuthRequestProvider oauth;
+  DefaultRequestPipelineTest.FakeOAuth2RequestProvider oauth2;
   DefaultRequestPipeline requestPipeline;
   HttpRequest signedRequest;
 
@@ -77,7 +78,7 @@ public class DefaultInvalidationServiceT
 
     fetcher = new DefaultRequestPipelineTest.FakeHttpFetcher();
     oauth = new DefaultRequestPipelineTest.FakeOAuthRequestProvider();
-    requestPipeline = new DefaultRequestPipeline(fetcher, cache, oauth,
+    requestPipeline = new DefaultRequestPipeline(fetcher, cache, oauth, oauth2,
         new DefaultResponseRewriterRegistry(null, null), service,
         new HttpResponseMetadataHelper());
   }

Modified: shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/DefaultRequestPipelineTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/DefaultRequestPipelineTest.java?rev=1182565&r1=1182564&r2=1182565&view=diff
==============================================================================
--- shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/DefaultRequestPipelineTest.java (original)
+++ shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/DefaultRequestPipelineTest.java Wed Oct 12 20:10:39 2011
@@ -28,6 +28,8 @@ import org.apache.shindig.common.util.Da
 import org.apache.shindig.gadgets.AuthType;
 import org.apache.shindig.gadgets.GadgetException;
 import org.apache.shindig.gadgets.oauth.OAuthRequest;
+import org.apache.shindig.gadgets.oauth2.BasicOAuth2Request;
+import org.apache.shindig.gadgets.oauth2.OAuth2Request;
 import org.apache.shindig.gadgets.rewrite.DefaultResponseRewriterRegistry;
 import org.junit.Before;
 import org.junit.Test;
@@ -40,6 +42,7 @@ public class DefaultRequestPipelineTest 
   private final FakeHttpFetcher fetcher = new FakeHttpFetcher();
   private final FakeHttpCache cache = new FakeHttpCache();
   private final FakeOAuthRequestProvider oauth = new FakeOAuthRequestProvider();
+  private final FakeOAuth2RequestProvider oauth2 = new FakeOAuth2RequestProvider();
 
   private final HttpResponseMetadataHelper helper = new HttpResponseMetadataHelper() {
     @Override
@@ -47,7 +50,7 @@ public class DefaultRequestPipelineTest 
       return resp.getResponseAsString();
     }
   };
-  private final RequestPipeline pipeline = new DefaultRequestPipeline(fetcher, cache, oauth,
+  private final RequestPipeline pipeline = new DefaultRequestPipeline(fetcher, cache, oauth, oauth2,
       new DefaultResponseRewriterRegistry(null, null), new NoOpInvalidationService(), helper);
 
   @Before
@@ -89,7 +92,7 @@ public class DefaultRequestPipelineTest 
 
     fetcher.response = builder.create();
 
-    RequestPipeline pipeline = new DefaultRequestPipeline(fetcher, cache, oauth,
+    RequestPipeline pipeline = new DefaultRequestPipeline(fetcher, cache, oauth, oauth2,
         new DefaultResponseRewriterRegistry(null, null), new NoOpInvalidationService(),
         new HttpResponseMetadataHelper());
     HttpResponse response = pipeline.execute(request);
@@ -115,7 +118,7 @@ public class DefaultRequestPipelineTest 
 
     fetcher.response = builder.create();
 
-    RequestPipeline pipeline = new DefaultRequestPipeline(fetcher, cache, oauth,
+    RequestPipeline pipeline = new DefaultRequestPipeline(fetcher, cache, oauth, oauth2,
         new DefaultResponseRewriterRegistry(null, null), new NoOpInvalidationService(),
         new HttpResponseMetadataHelper());
     HttpResponse response = pipeline.execute(request);
@@ -380,4 +383,28 @@ public class DefaultRequestPipelineTest 
     }
 
   }
+  
+  public static class FakeOAuth2RequestProvider implements Provider<OAuth2Request> {
+    protected int fetchCount = 0;
+    protected HttpRequest httpRequest;
+    protected HttpResponse httpResponse;
+
+    protected FakeOAuth2RequestProvider() {
+    }
+
+
+    private final OAuth2Request oauth2Request = new BasicOAuth2Request(null, null, null, null, null, null, null, false) {
+      @Override
+      public HttpResponse fetch(HttpRequest request) {
+        fetchCount++;
+        httpRequest = request;
+        return httpResponse;
+      }
+    };
+
+    public OAuth2Request get() {
+      return oauth2Request;
+    }
+
+  }
 }

Added: shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/GadgetOAuth2TokenStoreTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/GadgetOAuth2TokenStoreTest.java?rev=1182565&view=auto
==============================================================================
--- shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/GadgetOAuth2TokenStoreTest.java (added)
+++ shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/GadgetOAuth2TokenStoreTest.java Wed Oct 12 20:10:39 2011
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shindig.gadgets.oauth2;
+
+import org.apache.shindig.auth.SecurityToken;
+import org.apache.shindig.common.uri.Uri;
+import org.apache.shindig.gadgets.GadgetSpecFactory;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class GadgetOAuth2TokenStoreTest extends MockUtils {
+  private static GadgetOAuth2TokenStore gts;
+  private static SecurityToken securityToken;
+  private static Uri gadgetUri = Uri.parse(MockUtils.GADGET_URI1);
+  private static OAuth2Arguments arguments;
+
+  @Before
+  public void setUp() throws Exception {
+    GadgetOAuth2TokenStoreTest.securityToken = MockUtils.getDummySecurityToken(MockUtils.USER,
+        MockUtils.USER, MockUtils.GADGET_URI1);
+    GadgetOAuth2TokenStoreTest.arguments = MockUtils.getDummyArguments();
+
+    final OAuth2Store store = MockUtils.getDummyStore();
+    final GadgetSpecFactory specFactory = MockUtils.getDummySpecFactory();
+
+    GadgetOAuth2TokenStoreTest.gts = new GadgetOAuth2TokenStore(store, specFactory);
+  }
+
+  @Test
+  public void testGadgetOAuth2TokenStore_1() throws Exception {
+    Assert.assertNotNull(GadgetOAuth2TokenStoreTest.gts);
+  }
+
+  @Test
+  public void testGetOAuth2Accessor_1() throws Exception {
+    final OAuth2Accessor result = GadgetOAuth2TokenStoreTest.gts.getOAuth2Accessor(null,
+        GadgetOAuth2TokenStoreTest.arguments, GadgetOAuth2TokenStoreTest.gadgetUri);
+    Assert.assertNotNull(result);
+    Assert.assertTrue(result.isErrorResponse());
+    Assert.assertEquals(OAuth2Error.GET_OAUTH2_ACCESSOR_PROBLEM, result.getError());
+    Assert.assertTrue(result.getErrorContextMessage().startsWith(
+        "OAuth2Accessor missing a param"));
+  }
+
+  @Test
+  public void testGetOAuth2Accessor_2() throws Exception {
+    final OAuth2Accessor result = GadgetOAuth2TokenStoreTest.gts.getOAuth2Accessor(
+        GadgetOAuth2TokenStoreTest.securityToken, GadgetOAuth2TokenStoreTest.arguments, null);
+    Assert.assertNotNull(result);
+    Assert.assertTrue(result.isErrorResponse());
+    Assert.assertEquals(OAuth2Error.GET_OAUTH2_ACCESSOR_PROBLEM, result.getError());
+    Assert.assertTrue(result.getErrorContextMessage().startsWith(
+        "OAuth2Accessor missing a param"));
+  }
+
+  @Test
+  public void testGetOAuth2Accessor_3() throws Exception {
+    final OAuth2Accessor result = GadgetOAuth2TokenStoreTest.gts.getOAuth2Accessor(
+        GadgetOAuth2TokenStoreTest.securityToken, GadgetOAuth2TokenStoreTest.arguments,
+        Uri.parse("bad"));
+
+    Assert.assertNotNull(result);
+    Assert.assertTrue(result.isErrorResponse());
+    Assert.assertEquals(OAuth2Error.NO_GADGET_SPEC, result.getError());
+    Assert.assertTrue(result.getErrorContextMessage().startsWith("gadgetUri ="));
+  }
+
+  @Test
+  public void testGetOAuth2Accessor_4() throws Exception {
+    final OAuth2Accessor result = GadgetOAuth2TokenStoreTest.gts.getOAuth2Accessor(
+        GadgetOAuth2TokenStoreTest.securityToken, GadgetOAuth2TokenStoreTest.arguments,
+        Uri.parse(MockUtils.GADGET_URI1));
+
+    Assert.assertNotNull(result);
+    Assert.assertFalse(result.isErrorResponse());
+    Assert.assertEquals(null, result.getAccessToken());
+    Assert.assertEquals(MockUtils.AUTHORIZE_URL, result.getAuthorizationUrl());
+    Assert.assertEquals(OAuth2Message.BASIC_AUTH_TYPE, result.getClientAuthenticationType());
+    Assert.assertEquals(MockUtils.CLIENT_ID1, result.getClientId());
+    Assert.assertEquals(MockUtils.GADGET_URI1, result.getGadgetUri());
+    Assert.assertEquals(OAuth2Message.AUTHORIZATION, result.getGrantType());
+    Assert.assertEquals(MockUtils.REDIRECT_URI, result.getRedirectUri());
+    Assert.assertEquals(null, result.getRefreshToken());
+    Assert.assertEquals(MockUtils.SCOPE, result.getScope());
+    Assert.assertEquals(MockUtils.SERVICE_NAME, result.getServiceName());
+    Assert.assertEquals(MockUtils.TOKEN_URL, result.getTokenUrl());
+    Assert.assertEquals(OAuth2Accessor.Type.CONFIDENTIAL, result.getType());
+    Assert.assertEquals(MockUtils.USER, result.getUser());
+    Assert.assertTrue(result.isValid());
+    Assert.assertFalse(result.isAllowModuleOverrides());
+    Assert.assertFalse(result.isErrorResponse());
+    Assert.assertFalse(result.isRedirecting());
+    Assert.assertFalse(result.isUrlParameter());
+    Assert.assertTrue(result.isAuthorizationHeader());
+
+  }
+
+  @Test
+  public void testGetOAuth2Store_1() throws Exception {
+    final OAuth2Store result = GadgetOAuth2TokenStoreTest.gts.getOAuth2Store();
+
+    Assert.assertNotNull(result);
+    Assert.assertEquals(MockUtils.getDummyStore(), result);
+  }
+
+}
\ No newline at end of file

Added: shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/MockUtils.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/MockUtils.java?rev=1182565&view=auto
==============================================================================
--- shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/MockUtils.java (added)
+++ shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/MockUtils.java Wed Oct 12 20:10:39 2011
@@ -0,0 +1,512 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shindig.gadgets.oauth2;
+
+import com.google.common.collect.Maps;
+import com.google.inject.Provider;
+
+import org.apache.shindig.auth.SecurityToken;
+import org.apache.shindig.common.servlet.Authority;
+import org.apache.shindig.common.uri.Uri;
+import org.apache.shindig.gadgets.AuthType;
+import org.apache.shindig.gadgets.GadgetContext;
+import org.apache.shindig.gadgets.GadgetException;
+import org.apache.shindig.gadgets.GadgetSpecFactory;
+import org.apache.shindig.gadgets.http.HttpFetcher;
+import org.apache.shindig.gadgets.http.HttpRequest;
+import org.apache.shindig.gadgets.http.HttpResponse;
+import org.apache.shindig.gadgets.http.HttpResponseBuilder;
+import org.apache.shindig.gadgets.oauth2.handler.BasicAuthenticationHandler;
+import org.apache.shindig.gadgets.oauth2.handler.ClientAuthenticationHandler;
+import org.apache.shindig.gadgets.oauth2.handler.StandardAuthenticationHandler;
+import org.apache.shindig.gadgets.oauth2.handler.TokenAuthorizationResponseHandler;
+import org.apache.shindig.gadgets.oauth2.handler.TokenEndpointResponseHandler;
+import org.apache.shindig.gadgets.oauth2.persistence.OAuth2Cache;
+import org.apache.shindig.gadgets.oauth2.persistence.OAuth2Client;
+import org.apache.shindig.gadgets.oauth2.persistence.OAuth2Encrypter;
+import org.apache.shindig.gadgets.oauth2.persistence.OAuth2EncryptionException;
+import org.apache.shindig.gadgets.oauth2.persistence.OAuth2Persister;
+import org.apache.shindig.gadgets.oauth2.persistence.OAuth2TokenPersistence;
+import org.apache.shindig.gadgets.oauth2.persistence.sample.InMemoryCache;
+import org.apache.shindig.gadgets.oauth2.persistence.sample.JSONOAuth2Persister;
+import org.apache.shindig.gadgets.spec.GadgetSpec;
+
+import org.apache.commons.io.IOUtils;
+import org.json.JSONObject;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+public class MockUtils {
+  protected final static String ACCESS_SECRET = "accessSecret";
+  protected final static Integer ACCESS_TOKEN_INDEX = new Integer(760896043);
+  protected final static Integer ACCESSOR_INDEX1 = new Integer(574006657);
+  protected final static Integer ACCESSOR_INDEX2 = new Integer(-1907922677);
+  protected final static String AUTHORIZE_URL = "http://www.example.com/authorize";
+  protected final static Integer BAD_INDEX = new Integer(0);
+  protected final static String CLIENT_ID1 = "clientId1";
+  protected final static String CLIENT_ID2 = "clientId2";
+  protected final static Integer CLIENT_INDEX1 = new Integer(1588412934);
+  protected final static Integer CLIENT_INDEX2 = new Integer(1295009927);
+  protected final static String CLIENT_SECRET1 = "clientSecret1";
+  protected final static String CLIENT_SECRET2 = "clientSecret2";
+  protected final static Map<String, String> EMPTY_MAP = Collections.emptyMap();
+  protected final static OAuth2Encrypter encrypter = new DummyEncrypter();
+  protected final static String GADGET_URI1 = "http://www.example.com/1";
+  protected final static String GADGET_URI2 = "http://www.example.com/2";
+  protected final static String MAC_SECRET = "mac_secret";
+  protected final static String REDIRECT_URI = "https://www.example.com/gadgets/oauth2callback";
+  protected final static String REFRESH_SECRET = "refreshSecret";
+  protected final static Integer REFRESH_TOKEN_INDEX = new Integer(81037012);
+  protected final static String SCOPE = "testScope";
+  protected final static String SERVICE_NAME = "serviceName";
+  protected final static String STATE = "1234";
+  protected final static String TOKEN_URL = "http://www.example.com/token";
+  protected final static String USER = "testUser";
+
+  protected static OAuth2Store dummyStore = null;
+
+  static class DummyAuthority implements Authority {
+    public String getAuthority() {
+      return "authority";
+    }
+
+    public String getOrigin() {
+      return "origin";
+    }
+
+    public String getScheme() {
+      return "scheme";
+    }
+  }
+
+  static class DummyEncrypter implements OAuth2Encrypter {
+
+    public byte[] decrypt(final byte[] encryptedSecret) throws OAuth2EncryptionException {
+      final byte[] bytesOut = new byte[encryptedSecret.length];
+      for (int i = 0; i < encryptedSecret.length; i++) {
+        bytesOut[i] = (byte) (encryptedSecret[i] - 1);
+      }
+      return bytesOut;
+
+    }
+
+    public byte[] encrypt(final byte[] plainSecret) throws OAuth2EncryptionException {
+      final byte[] bytesOut = new byte[plainSecret.length];
+      for (int i = 0; i < plainSecret.length; i++) {
+        bytesOut[i] = (byte) (plainSecret[i] + 1);
+      }
+      return bytesOut;
+    }
+  }
+
+  static class DummyHostProvider implements Provider<Authority> {
+    private final static Authority authority = new DummyAuthority();
+
+    public Authority get() {
+      return DummyHostProvider.authority;
+    }
+  }
+
+  static class DummyHttpFetcher implements HttpFetcher {
+    public HttpResponse fetch(final HttpRequest request) throws GadgetException {
+      final HttpResponseBuilder builder = new HttpResponseBuilder();
+      builder.setStrictNoCache();
+      builder.setHttpStatusCode(HttpResponse.SC_OK);
+      builder.setHeader("Content-Type", "application/json");
+      builder
+          .setContent("{\"access_token\"=\"xxx\",\"token_type\"=\"Bearer\",\"expires_in\"=\"1\",\"refresh_token\"=\"yyy\",\"example_parameter\"=\"example_value\"}");
+      return builder.create();
+    }
+  }
+
+  static class DummyMessageProvider implements Provider<OAuth2Message> {
+    public OAuth2Message get() {
+      return new BasicOAuth2Message();
+    }
+  }
+
+  static class DummySecurityToken implements SecurityToken {
+    private final String ownerId;
+    private final String viewerId;
+    private final String appUrl;
+
+    public DummySecurityToken(final String ownerId, final String viewerId, final String appUrl) {
+      this.ownerId = ownerId;
+      this.viewerId = viewerId;
+      this.appUrl = appUrl;
+    }
+
+    public String getOwnerId() {
+      return this.ownerId;
+    }
+
+    public String getViewerId() {
+      return this.viewerId;
+    }
+
+    public String getAppId() {
+      return "";
+    }
+
+    public String getDomain() {
+      return "";
+    }
+
+    public String getContainer() {
+      return "";
+    }
+
+    public String getAppUrl() {
+      return this.appUrl;
+    }
+
+    public long getModuleId() {
+      return 0;
+    }
+
+    public Long getExpiresAt() {
+      return 0L;
+    }
+
+    public boolean isExpired() {
+      return false;
+    }
+
+    public String getUpdatedToken() {
+      return "";
+    }
+
+    public String getAuthenticationMode() {
+      return "";
+    }
+
+    public String getTrustedJson() {
+      return "";
+    }
+
+    public boolean isAnonymous() {
+      return false;
+    }
+
+    public String getActiveUrl() {
+      return this.appUrl;
+    }
+  }
+
+  static class DummyGadgetSpecFactory implements GadgetSpecFactory {
+    private final static String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><Module><ModulePrefs title=\"\"><OAuth2><Service name=\"serviceName\" scope=\"testScope\"></Service></OAuth2></ModulePrefs><Content type=\"html\"></Content></Module>";
+
+    public GadgetSpec getGadgetSpec(final GadgetContext context) throws GadgetException {
+      final Uri contextUri = context.getUrl();
+      if ((contextUri != null) && (contextUri.toString().equals(MockUtils.GADGET_URI1))) {
+        return new GadgetSpec(context.getUrl(), DummyGadgetSpecFactory.xml);
+      }
+
+      throw new GadgetException(GadgetException.Code.OAUTH_STORAGE_ERROR);
+    }
+  }
+
+  private static void setTokenCommons(final OAuth2TokenPersistence token) throws Exception {
+    token.setExpiresAt(1L);
+    token.setGadgetUri(MockUtils.GADGET_URI1);
+    token.setIssuedAt(0L);
+    token.setMacAlgorithm("");
+    token.setMacExt("");
+    token.setMacSecret(new byte[] {});
+    token.setProperties(MockUtils.EMPTY_MAP);
+    token.setScope(MockUtils.SCOPE);
+    token.setSecret(MockUtils.ACCESS_SECRET.getBytes("UTF-8"));
+    token.setServiceName(MockUtils.SERVICE_NAME);
+    token.setTokenType(OAuth2Message.BEARER_TOKEN_TYPE);
+    token.setUser(MockUtils.USER);
+  }
+
+  protected static OAuth2TokenPersistence getAccessToken() throws Exception {
+    final OAuth2TokenPersistence accessToken = new OAuth2TokenPersistence(
+        MockUtils.getDummyEncrypter());
+    MockUtils.setTokenCommons(accessToken);
+    accessToken.setType(OAuth2Token.Type.ACCESS);
+    return accessToken;
+  }
+
+  protected static OAuth2TokenPersistence getBadMacToken() throws Exception {
+    final OAuth2TokenPersistence accessToken = new OAuth2TokenPersistence(
+        MockUtils.getDummyEncrypter());
+    MockUtils.setTokenCommons(accessToken);
+    accessToken.setMacAlgorithm(OAuth2Message.HMAC_SHA_256);
+    accessToken.setMacExt("1 2 3");
+    accessToken.setMacSecret(MockUtils.MAC_SECRET.getBytes("UTF-8"));
+    accessToken.setTokenType(OAuth2Message.MAC_TOKEN_TYPE);
+    accessToken.setType(OAuth2Token.Type.ACCESS);
+    return accessToken;
+  }
+
+  private static void setClientCommons(final OAuth2Client client) throws Exception {
+    client.setAuthorizationUrl(MockUtils.AUTHORIZE_URL);
+    client.setGrantType(OAuth2Message.AUTHORIZATION_CODE);
+    client.setRedirectUri(MockUtils.REDIRECT_URI);
+    client.setServiceName(MockUtils.SERVICE_NAME);
+    client.setTokenUrl(MockUtils.TOKEN_URL);
+  }
+
+  protected static OAuth2Client getClient_Code_Confidential() throws Exception {
+    final OAuth2Client client = new OAuth2Client(MockUtils.getDummyEncrypter());
+    MockUtils.setClientCommons(client);
+    client.setClientAuthenticationType(OAuth2Message.BASIC_AUTH_TYPE);
+    client.setClientId(MockUtils.CLIENT_ID1);
+    client.setClientSecret(MockUtils.CLIENT_SECRET1.getBytes("UTF-8"));
+    client.setGadgetUri(MockUtils.GADGET_URI1);
+    client.setType(OAuth2Accessor.Type.CONFIDENTIAL);
+    client.setAllowModuleOverride(true);
+    client.setAuthorizationHeader(true);
+    client.setUrlParameter(false);
+
+    return client;
+  }
+
+  protected static OAuth2Client getClient_Code_Public() throws Exception {
+    final OAuth2Client client = new OAuth2Client(MockUtils.getDummyEncrypter());
+    MockUtils.setClientCommons(client);
+    client.setClientAuthenticationType(OAuth2Message.STANDARD_AUTH_TYPE);
+    client.setClientId(MockUtils.CLIENT_ID2);
+    client.setClientSecret(MockUtils.CLIENT_SECRET2.getBytes("UTF-8"));
+    client.setGadgetUri(MockUtils.GADGET_URI2);
+    client.setType(OAuth2Accessor.Type.PUBLIC);
+    client.setAllowModuleOverride(false);
+    client.setAuthorizationHeader(false);
+    client.setUrlParameter(true);
+
+    return client;
+  }
+
+  protected static OAuth2Arguments getDummyArguments() throws Exception {
+    final Map<String, String> map = Maps.newHashMap();
+    map.put("OAUTH_SCOPE", MockUtils.SCOPE);
+    map.put("OAUTH_SERVICE_NAME", MockUtils.SERVICE_NAME);
+    return new OAuth2Arguments(AuthType.OAUTH2, map);
+  }
+
+  protected static List<ClientAuthenticationHandler> getDummyClientAuthHandlers() throws Exception {
+    final List<ClientAuthenticationHandler> ret = new ArrayList<ClientAuthenticationHandler>(2);
+    ret.add(new BasicAuthenticationHandler());
+    ret.add(new StandardAuthenticationHandler());
+    return ret;
+  }
+
+  protected static OAuth2Encrypter getDummyEncrypter() {
+    return MockUtils.encrypter;
+  }
+
+  protected static HttpFetcher getDummyFecther() throws Exception {
+    return new DummyHttpFetcher();
+  }
+
+  protected static Authority getDummyAuthority() {
+    return new DummyAuthority();
+  }
+
+  protected static Provider<OAuth2Message> getDummyMessageProvider() {
+    return new DummyMessageProvider();
+  }
+
+  protected static JSONOAuth2Persister getDummyPersister() throws Exception {
+    final JSONObject configFile = new JSONObject(MockUtils.getJSONString());
+    return new JSONOAuth2Persister(MockUtils.getDummyEncrypter(), MockUtils.getDummyAuthority(),
+        MockUtils.REDIRECT_URI, "xxx", configFile);
+  }
+
+  protected static GadgetSpecFactory getDummySpecFactory() {
+    return new DummyGadgetSpecFactory();
+  }
+
+  protected static SecurityToken getDummySecurityToken(final String ownerId, final String viewerId,
+      final String appUrl) {
+    return new DummySecurityToken(ownerId, viewerId, appUrl);
+  }
+
+  protected static OAuth2Store getDummyStore() throws Exception {
+    if (MockUtils.dummyStore == null) {
+      final OAuth2Cache cache = new InMemoryCache();
+      final OAuth2Persister persister = MockUtils.getDummyPersister();
+      MockUtils.dummyStore = MockUtils.getDummyStore(cache, persister, MockUtils.REDIRECT_URI);
+    }
+
+    MockUtils.dummyStore.clearCache();
+    MockUtils.dummyStore.init();
+
+    return MockUtils.dummyStore;
+  }
+
+  protected static OAuth2Store getDummyStore(final OAuth2Cache cache,
+      final OAuth2Persister persister, final String globalRedirectUri) {
+    final OAuth2Store store = new BasicOAuth2Store(cache, persister, globalRedirectUri);
+
+    return store;
+  }
+
+  protected static List<TokenEndpointResponseHandler> getDummyTokenEndpointResponseHandlers()
+      throws Exception {
+    final List<TokenEndpointResponseHandler> ret = new ArrayList<TokenEndpointResponseHandler>(1);
+    ret.add(new TokenAuthorizationResponseHandler(MockUtils.getDummyMessageProvider(), MockUtils
+        .getDummyStore()));
+    return ret;
+  }
+
+  protected static String getJSONString() throws IOException {
+    return MockUtils.loadFile("org/apache/shindig/gadgets/oauth2/oauth2_test.json");
+  }
+
+  protected static OAuth2TokenPersistence getMacToken() throws Exception {
+    final OAuth2TokenPersistence accessToken = new OAuth2TokenPersistence(
+        MockUtils.getDummyEncrypter());
+
+    MockUtils.setTokenCommons(accessToken);
+    accessToken.setMacAlgorithm(OAuth2Message.HMAC_SHA_1);
+    accessToken.setMacExt("1 2 3");
+    accessToken.setMacSecret(MockUtils.MAC_SECRET.getBytes("UTF-8"));
+    accessToken.setTokenType(OAuth2Message.MAC_TOKEN_TYPE);
+    accessToken.setType(OAuth2Token.Type.ACCESS);
+
+    return accessToken;
+  }
+
+  private static BasicOAuth2Accessor getOAuth2AccessorCommon() throws Exception {
+    final OAuth2Cache cache = new InMemoryCache();
+    final OAuth2Persister persister = MockUtils.getDummyPersister();
+    final OAuth2Store store = MockUtils.getDummyStore(cache, persister, MockUtils.REDIRECT_URI);
+    final BasicOAuth2Accessor accessor = new BasicOAuth2Accessor(MockUtils.GADGET_URI1,
+        MockUtils.SERVICE_NAME, MockUtils.USER, MockUtils.SCOPE, true, store,
+        MockUtils.REDIRECT_URI);
+
+    accessor.setAccessToken(MockUtils.getAccessToken());
+    accessor.setAuthorizationUrl(MockUtils.AUTHORIZE_URL);
+    accessor.setClientAuthenticationType(OAuth2Message.BASIC_AUTH_TYPE);
+    accessor.setClientId(MockUtils.CLIENT_ID1);
+    accessor.setClientSecret(MockUtils.CLIENT_SECRET1.getBytes("UTF-8"));
+    accessor.setErrorUri(null);
+    accessor.setGrantType(OAuth2Message.AUTHORIZATION);
+    accessor.setRedirectUri(MockUtils.REDIRECT_URI);
+    accessor.setRefreshToken(MockUtils.getRefreshToken());
+    accessor.setTokenUrl(MockUtils.TOKEN_URL);
+    accessor.setType(OAuth2Accessor.Type.CONFIDENTIAL);
+    accessor.setAuthorizationHeader(Boolean.TRUE);
+    accessor.setRedirecting(Boolean.FALSE);
+    accessor.setUrlParameter(Boolean.FALSE);
+
+    return accessor;
+  }
+
+  protected static OAuth2Accessor getOAuth2Accessor_Code() throws Exception {
+    final BasicOAuth2Accessor accessor = MockUtils.getOAuth2AccessorCommon();
+
+    return accessor;
+  }
+
+  protected static OAuth2Accessor getOAuth2Accessor_Error() {
+    final OAuth2Accessor accessor = new BasicOAuth2Accessor(null,
+        OAuth2Error.GET_OAUTH2_ACCESSOR_PROBLEM, "test contextMessage", null);
+
+    return accessor;
+  }
+
+  protected static OAuth2Accessor getOAuth2Accessor_MacToken() throws Exception {
+    final BasicOAuth2Accessor accessor = MockUtils.getOAuth2AccessorCommon();
+
+    accessor.setAccessToken(MockUtils.getMacToken());
+    accessor.setRefreshToken(null);
+
+    return accessor;
+  }
+
+  protected static OAuth2Accessor getOAuth2Accessor_BadMacToken() throws Exception {
+    final BasicOAuth2Accessor accessor = MockUtils.getOAuth2AccessorCommon();
+
+    accessor.setAccessToken(MockUtils.getBadMacToken());
+    accessor.setRefreshToken(null);
+
+    return accessor;
+  }
+
+  protected static OAuth2Accessor getOAuth2Accessor_StandardAuth() throws Exception {
+    final BasicOAuth2Accessor accessor = MockUtils.getOAuth2AccessorCommon();
+
+    accessor.setClientAuthenticationType(OAuth2Message.STANDARD_AUTH_TYPE);
+
+    return accessor;
+  }
+
+  protected static OAuth2Accessor getOAuth2Accessor_ClientCredentials() throws Exception {
+    final BasicOAuth2Accessor accessor = MockUtils.getOAuth2AccessorCommon();
+
+    accessor.setGrantType(OAuth2Message.CLIENT_CREDENTIALS);
+
+    return accessor;
+  }
+
+  protected static OAuth2Accessor getOAuth2Accessor_Redirecting() throws Exception {
+    final BasicOAuth2Accessor accessor = MockUtils.getOAuth2AccessorCommon();
+
+    accessor.setRedirecting(Boolean.TRUE);
+
+    return accessor;
+  }
+
+  protected static OAuth2Accessor getOAuth2Accessor_ClientCredentialsRedirecting() throws Exception {
+    final OAuth2Cache cache = new InMemoryCache();
+    final OAuth2Persister persister = MockUtils.getDummyPersister();
+    final OAuth2Store store = MockUtils.getDummyStore(cache, persister, MockUtils.REDIRECT_URI);
+    final BasicOAuth2Accessor accessor = new BasicOAuth2Accessor(MockUtils.GADGET_URI1,
+        MockUtils.SERVICE_NAME, MockUtils.USER, MockUtils.SCOPE, true, store,
+        MockUtils.REDIRECT_URI);
+
+    accessor.setGrantType(OAuth2Message.CLIENT_CREDENTIALS);
+    accessor.setRedirecting(Boolean.TRUE);
+
+    return accessor;
+  }
+
+  protected static OAuth2TokenPersistence getRefreshToken() throws Exception {
+    final OAuth2TokenPersistence refreshToken = new OAuth2TokenPersistence(
+        MockUtils.getDummyEncrypter());
+    refreshToken.setExpiresAt(1L);
+    refreshToken.setGadgetUri(MockUtils.GADGET_URI1);
+    refreshToken.setIssuedAt(0L);
+    refreshToken.setMacAlgorithm("");
+    refreshToken.setMacExt("");
+    refreshToken.setMacSecret(new byte[] {});
+    refreshToken.setProperties(MockUtils.EMPTY_MAP);
+    refreshToken.setScope(MockUtils.SCOPE);
+    refreshToken.setSecret(MockUtils.ACCESS_SECRET.getBytes("UTF-8"));
+    refreshToken.setServiceName(MockUtils.SERVICE_NAME);
+    refreshToken.setTokenType(OAuth2Message.MAC_TOKEN_TYPE);
+    refreshToken.setType(OAuth2Token.Type.REFRESH);
+    refreshToken.setUser(MockUtils.USER);
+    return refreshToken;
+  }
+  
+  protected static String loadFile(String path) throws IOException {
+    InputStream is = MockUtils.class.getClassLoader().getResourceAsStream(path);
+    return IOUtils.toString(is,"UTF-8");
+  }
+}

Added: shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/OAuth2ArgumentsTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/OAuth2ArgumentsTest.java?rev=1182565&view=auto
==============================================================================
--- shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/OAuth2ArgumentsTest.java (added)
+++ shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/OAuth2ArgumentsTest.java Wed Oct 12 20:10:39 2011
@@ -0,0 +1,205 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shindig.gadgets.oauth2;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.shindig.gadgets.AuthType;
+import org.apache.shindig.gadgets.spec.RequestAuthenticationInfo;
+import org.easymock.EasyMock;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.collect.Maps;
+
+public class OAuth2ArgumentsTest extends MockUtils {
+  private static HttpServletRequest requestMock;
+  private static Map<String, String> attrs;
+
+  @Before
+  public void setUp() throws Exception {
+    OAuth2ArgumentsTest.attrs = Maps.newHashMap();
+    OAuth2ArgumentsTest.attrs.put("OAUTH_SCOPE", MockUtils.SCOPE);
+    OAuth2ArgumentsTest.attrs.put("OAUTH_SERVICE_NAME", MockUtils.SERVICE_NAME);
+    OAuth2ArgumentsTest.attrs.put("bypassSpecCache", "1");
+    OAuth2ArgumentsTest.attrs.put("extraParam", "extraValue");
+    OAuth2ArgumentsTest.requestMock = EasyMock.createNiceMock(HttpServletRequest.class);
+    EasyMock.expect(OAuth2ArgumentsTest.requestMock.getParameterNames()).andReturn(
+        Collections.enumeration(OAuth2ArgumentsTest.attrs.keySet()));
+    EasyMock.expect(OAuth2ArgumentsTest.requestMock.getParameterMap()).andReturn(
+        OAuth2ArgumentsTest.attrs);
+    for (final Entry<String, String> entry : OAuth2ArgumentsTest.attrs.entrySet()) {
+      EasyMock.expect(OAuth2ArgumentsTest.requestMock.getParameter(entry.getKey())).andReturn(
+          entry.getValue());
+    }
+    EasyMock.replay(OAuth2ArgumentsTest.requestMock);
+  }
+
+  @Test
+  public void testOAuth2Arguments_1() throws Exception {
+    final OAuth2Arguments result = new OAuth2Arguments(OAuth2ArgumentsTest.requestMock);
+
+    Assert.assertNotNull(result);
+    Assert.assertTrue(result.getBypassSpecCache());
+    Assert.assertEquals(MockUtils.SCOPE, result.getScope());
+    Assert.assertEquals(MockUtils.SERVICE_NAME, result.getServiceName());
+  }
+
+  @Test
+  public void testOAuth2Arguments_2() throws Exception {
+    final Map<String, String> attrs1 = Maps.newHashMap();
+    attrs1.put("OAUTH_SCOPE", "xxx");
+    attrs1.put("OAUTH_SERVICE_NAME", "yyy");
+    attrs1.put("bypassSpecCache", "0");
+    final HttpServletRequest request = EasyMock.createNiceMock(HttpServletRequest.class);
+    EasyMock.expect(request.getParameterNames())
+        .andReturn(Collections.enumeration(attrs1.keySet()));
+    EasyMock.expect(request.getParameterMap()).andReturn(attrs1);
+    for (final Entry<String, String> entry : attrs1.entrySet()) {
+      EasyMock.expect(request.getParameter(entry.getKey())).andReturn(entry.getValue());
+    }
+    EasyMock.replay(request);
+
+    final OAuth2Arguments orig = new OAuth2Arguments(request);
+
+    final OAuth2Arguments result = new OAuth2Arguments(orig);
+
+    Assert.assertNotNull(result);
+    Assert.assertFalse(result.getBypassSpecCache());
+    Assert.assertEquals("xxx", result.getScope());
+    Assert.assertEquals("yyy", result.getServiceName());
+  }
+
+  @Test
+  public void testOAuth2Arguments_3() throws Exception {
+    final RequestAuthenticationInfo info = EasyMock.createNiceMock(RequestAuthenticationInfo.class);
+    EasyMock.expect(info.getAuthType()).andReturn(AuthType.OAUTH2);
+    EasyMock.expect(info.getAttributes()).andReturn(OAuth2ArgumentsTest.attrs);
+    EasyMock.replay(info);
+
+    final OAuth2Arguments result = new OAuth2Arguments(info);
+
+    Assert.assertNotNull(result);
+    Assert.assertTrue(result.getBypassSpecCache());
+    Assert.assertEquals(MockUtils.SCOPE, result.getScope());
+    Assert.assertEquals(MockUtils.SERVICE_NAME, result.getServiceName());
+  }
+
+  @Test
+  public void testOAuth2Arguments_4() throws Exception {
+    final OAuth2Arguments result = new OAuth2Arguments(AuthType.OAUTH2, OAuth2ArgumentsTest.attrs);
+
+    Assert.assertNotNull(result);
+    Assert.assertTrue(result.getBypassSpecCache());
+    Assert.assertEquals(MockUtils.SCOPE, result.getScope());
+    Assert.assertEquals(MockUtils.SERVICE_NAME, result.getServiceName());
+  }
+
+  @Test
+  public void testEquals_1() throws Exception {
+    final OAuth2Arguments fixture = new OAuth2Arguments(AuthType.OAUTH2, OAuth2ArgumentsTest.attrs);
+
+    final Object obj = new OAuth2Arguments(OAuth2ArgumentsTest.requestMock);
+
+    final boolean result = fixture.equals(obj);
+
+    Assert.assertTrue(result);
+  }
+
+  @Test
+  public void testEquals_2() throws Exception {
+    final Object obj = new Object();
+
+    final boolean result = OAuth2ArgumentsTest.requestMock.equals(obj);
+
+    Assert.assertFalse(result);
+  }
+
+  @Test
+  public void testEquals_3() throws Exception {
+    final boolean result = OAuth2ArgumentsTest.requestMock.equals(null);
+
+    Assert.assertFalse(result);
+  }
+
+  @Test
+  public void testEquals_4() throws Exception {
+    final Map<String, String> attrs1 = Maps.newHashMap();
+    attrs1.put("OAUTH_SCOPE", "xxx");
+    attrs1.put("OAUTH_SERVICE_NAME", "yyy");
+    attrs1.put("bypassSpecCache", "0");
+    final HttpServletRequest request = EasyMock.createNiceMock(HttpServletRequest.class);
+    EasyMock.expect(request.getParameterNames())
+        .andReturn(Collections.enumeration(attrs1.keySet()));
+    EasyMock.expect(request.getParameterMap()).andReturn(attrs1);
+    for (final Entry<String, String> entry : attrs1.entrySet()) {
+      EasyMock.expect(request.getParameter(entry.getKey())).andReturn(entry.getValue());
+    }
+    EasyMock.replay(request);
+
+    final OAuth2Arguments obj = new OAuth2Arguments(request);
+
+    final boolean result = OAuth2ArgumentsTest.requestMock.equals(obj);
+
+    Assert.assertFalse(result);
+  }
+
+  @Test
+  public void testGetBypassSpecCache_1() throws Exception {
+    final OAuth2Arguments fixture = new OAuth2Arguments(OAuth2ArgumentsTest.requestMock);
+
+    final boolean result = fixture.getBypassSpecCache();
+
+    Assert.assertTrue(result);
+  }
+
+  @Test
+  public void testGetScope_1() throws Exception {
+    final OAuth2Arguments fixture = new OAuth2Arguments(OAuth2ArgumentsTest.requestMock);
+
+    final String result = fixture.getScope();
+
+    Assert.assertNotNull(result);
+    Assert.assertEquals(MockUtils.SCOPE, result);
+  }
+
+  @Test
+  public void testGetServiceName_1() throws Exception {
+    final OAuth2Arguments fixture = new OAuth2Arguments(OAuth2ArgumentsTest.requestMock);
+
+    final String result = fixture.getServiceName();
+
+    Assert.assertNotNull(result);
+    Assert.assertEquals(MockUtils.SERVICE_NAME, result);
+  }
+
+  @Test
+  public void testHashCode_1() throws Exception {
+    final OAuth2Arguments fixture = new OAuth2Arguments(OAuth2ArgumentsTest.requestMock);
+
+    final int result = fixture.hashCode();
+
+    Assert.assertEquals(-1928533070, result);
+  }
+}
\ No newline at end of file

Added: shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/OAuth2ErrorTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/OAuth2ErrorTest.java?rev=1182565&view=auto
==============================================================================
--- shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/OAuth2ErrorTest.java (added)
+++ shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/OAuth2ErrorTest.java Wed Oct 12 20:10:39 2011
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shindig.gadgets.oauth2;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class OAuth2ErrorTest {
+  @Test
+  public void testGetErrorCode_1() throws Exception {
+    final OAuth2Error fixture = OAuth2Error.AUTHENTICATION_PROBLEM;
+
+    final String result = fixture.getErrorCode();
+
+    Assert.assertEquals("authentication_problem", result);
+  }
+
+  @Test
+  public void testGetErrorDescription_1() throws Exception {
+    final OAuth2Error fixture = OAuth2Error.AUTHENTICATION_PROBLEM;
+
+    final String result = fixture.getErrorDescription();
+
+    Assert
+        .assertEquals(
+            "org.apache.shindig.gadgets.oauth2.OAuth2Request encountered a problem :  adding client authentication : {0}",
+            result);
+  }
+
+  @Test
+  public void testGetErrorExplanation_1() throws Exception {
+    final OAuth2Error fixture = OAuth2Error.AUTHENTICATION_PROBLEM;
+
+    final String result = fixture.getErrorExplanation();
+
+    Assert.assertEquals("Could not add authentication headers to the request.", result);
+  }
+}
\ No newline at end of file

Added: shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/OAuth2FetcherConfigTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/OAuth2FetcherConfigTest.java?rev=1182565&view=auto
==============================================================================
--- shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/OAuth2FetcherConfigTest.java (added)
+++ shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/OAuth2FetcherConfigTest.java Wed Oct 12 20:10:39 2011
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shindig.gadgets.oauth2;
+
+import org.apache.shindig.gadgets.GadgetSpecFactory;
+import org.easymock.EasyMock;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class OAuth2FetcherConfigTest {
+  @Test
+  public void testOAuth2FetcherConfig_1() throws Exception {
+    final GadgetOAuth2TokenStore tokenStore = new GadgetOAuth2TokenStore(
+        EasyMock.createNiceMock(OAuth2Store.class),
+        EasyMock.createNiceMock(GadgetSpecFactory.class));
+    final boolean viewerAccessTokensEnabled = true;
+
+    final OAuth2FetcherConfig result = new OAuth2FetcherConfig(tokenStore,
+        viewerAccessTokensEnabled);
+
+    Assert.assertNotNull(result);
+    Assert.assertEquals(true, result.isViewerAccessTokensEnabled());
+  }
+
+  @Test
+  public void testGetOAuth2Store_1() throws Exception {
+    final OAuth2FetcherConfig fixture = new OAuth2FetcherConfig(new GadgetOAuth2TokenStore(
+        EasyMock.createNiceMock(OAuth2Store.class),
+        EasyMock.createNiceMock(GadgetSpecFactory.class)), true);
+
+    final OAuth2Store result = fixture.getOAuth2Store();
+
+    Assert.assertNotNull(result);
+    Assert.assertEquals(false, result.clearCache());
+  }
+
+  @Test
+  public void testGetTokenStore_1() throws Exception {
+    final OAuth2FetcherConfig fixture = new OAuth2FetcherConfig(new GadgetOAuth2TokenStore(
+        EasyMock.createNiceMock(OAuth2Store.class),
+        EasyMock.createNiceMock(GadgetSpecFactory.class)), true);
+
+    final GadgetOAuth2TokenStore result = fixture.getTokenStore();
+
+    Assert.assertNotNull(result);
+  }
+
+  @Test
+  public void testIsViewerAccessTokensEnabled_1() throws Exception {
+    final OAuth2FetcherConfig fixture = new OAuth2FetcherConfig(new GadgetOAuth2TokenStore(
+        EasyMock.createNiceMock(OAuth2Store.class),
+        EasyMock.createNiceMock(GadgetSpecFactory.class)), true);
+
+    final boolean result = fixture.isViewerAccessTokensEnabled();
+
+    Assert.assertEquals(true, result);
+  }
+
+  @Test
+  public void testIsViewerAccessTokensEnabled_2() throws Exception {
+    final OAuth2FetcherConfig fixture = new OAuth2FetcherConfig(new GadgetOAuth2TokenStore(
+        EasyMock.createNiceMock(OAuth2Store.class),
+        EasyMock.createNiceMock(GadgetSpecFactory.class)), false);
+
+    final boolean result = fixture.isViewerAccessTokensEnabled();
+
+    Assert.assertEquals(false, result);
+  }
+}
\ No newline at end of file

Added: shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/OAuth2GadgetContextTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/OAuth2GadgetContextTest.java?rev=1182565&view=auto
==============================================================================
--- shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/OAuth2GadgetContextTest.java (added)
+++ shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/OAuth2GadgetContextTest.java Wed Oct 12 20:10:39 2011
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shindig.gadgets.oauth2;
+
+import org.apache.shindig.auth.SecurityToken;
+import org.apache.shindig.common.uri.Uri;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class OAuth2GadgetContextTest extends MockUtils {
+  private static SecurityToken securityToken;
+  private static OAuth2Arguments arguments;
+  private static Uri gadgetUri;
+
+  @Before
+  public void setUp() throws Exception {
+    OAuth2GadgetContextTest.securityToken = MockUtils.getDummySecurityToken(MockUtils.USER,
+        MockUtils.USER, MockUtils.GADGET_URI1);
+    OAuth2GadgetContextTest.arguments = MockUtils.getDummyArguments();
+    OAuth2GadgetContextTest.gadgetUri = Uri.parse(MockUtils.GADGET_URI1);
+  }
+
+  @Test
+  public void testOAuth2GadgetContext_1() throws Exception {
+    final OAuth2GadgetContext result = new OAuth2GadgetContext(
+        OAuth2GadgetContextTest.securityToken, OAuth2GadgetContextTest.arguments,
+        OAuth2GadgetContextTest.gadgetUri);
+
+    Assert.assertNotNull(result);
+    Assert.assertEquals(false, result.getCajoled());
+    Assert.assertEquals("", result.getContainer());
+    Assert.assertEquals(false, result.getDebug());
+    Assert.assertEquals(null, result.getHost());
+    Assert.assertEquals(false, result.getIgnoreCache());
+    Assert.assertNotNull(result.getLocale());
+    Assert.assertEquals(0, result.getModuleId());
+    Assert.assertNotNull(result.getRenderingContext());
+    Assert.assertEquals(null, result.getRepository());
+    Assert.assertEquals(false, result.getSanitize());
+    Assert.assertEquals(MockUtils.SCOPE, result.getScope());
+    Assert.assertEquals(OAuth2GadgetContextTest.securityToken, result.getToken());
+    Assert.assertEquals(MockUtils.GADGET_URI1, result.getUrl().toString());
+    Assert.assertEquals(null, result.getUserAgent());
+    Assert.assertEquals(null, result.getUserIp());
+    Assert.assertNotNull(result.getUserPrefs());
+  }
+}
\ No newline at end of file

Added: shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/OAuth2MessageModuleTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/OAuth2MessageModuleTest.java?rev=1182565&view=auto
==============================================================================
--- shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/OAuth2MessageModuleTest.java (added)
+++ shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/OAuth2MessageModuleTest.java Wed Oct 12 20:10:39 2011
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shindig.gadgets.oauth2;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.google.inject.AbstractModule;
+
+public class OAuth2MessageModuleTest {
+  @Test
+  public void testConfigure_1() throws Exception {
+    final OAuth2MessageModule fixture = new OAuth2MessageModule();
+
+    Assert.assertNotNull(fixture);
+    Assert.assertTrue(AbstractModule.class.isInstance(fixture));
+  }
+}
\ No newline at end of file

Added: shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/OAuth2ModuleTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/OAuth2ModuleTest.java?rev=1182565&view=auto
==============================================================================
--- shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/OAuth2ModuleTest.java (added)
+++ shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/OAuth2ModuleTest.java Wed Oct 12 20:10:39 2011
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shindig.gadgets.oauth2;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.google.inject.AbstractModule;
+
+public class OAuth2ModuleTest {
+  @Test
+  public void testOAuth2Module_1() throws Exception {
+    final OAuth2Module result = new OAuth2Module();
+    Assert.assertNotNull(result);
+    Assert.assertTrue(AbstractModule.class.isInstance(result));
+  }
+}
\ No newline at end of file

Added: shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/OAuth2RequestExceptionTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/OAuth2RequestExceptionTest.java?rev=1182565&view=auto
==============================================================================
--- shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/OAuth2RequestExceptionTest.java (added)
+++ shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/OAuth2RequestExceptionTest.java Wed Oct 12 20:10:39 2011
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shindig.gadgets.oauth2;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class OAuth2RequestExceptionTest {
+  @Test
+  public void testOAuth2RequestException_1() throws Exception {
+    final OAuth2Error error = OAuth2Error.AUTHENTICATION_PROBLEM;
+    final String errorText = "";
+    final Throwable cause = new Throwable();
+
+    final OAuth2RequestException result = new OAuth2RequestException(error, errorText, cause);
+
+    Assert.assertNotNull(result);
+    Assert
+        .assertEquals(
+            "org.apache.shindig.gadgets.oauth2.OAuth2Request encountered a problem :  adding client authentication : ",
+            result.getErrorText());
+    Assert
+        .assertEquals(
+            "org.apache.shindig.gadgets.oauth2.OAuth2Request encountered a problem :  adding client authentication : ",
+            result.getMessage());
+    Assert
+        .assertEquals(
+            "[AUTHENTICATION_PROBLEM,org.apache.shindig.gadgets.oauth2.OAuth2Request encountered a problem :  adding client authentication : ]",
+            result.toString());
+    Assert
+        .assertEquals(
+            "org.apache.shindig.gadgets.oauth2.OAuth2Request encountered a problem :  adding client authentication : ",
+            result.getLocalizedMessage());
+  }
+
+  @Test
+  public void testGetError_1() throws Exception {
+    final OAuth2RequestException fixture = new OAuth2RequestException(
+        OAuth2Error.AUTHENTICATION_PROBLEM, "", new Throwable());
+
+    final OAuth2Error result = fixture.getError();
+
+    Assert.assertNotNull(result);
+    Assert.assertEquals("authentication_problem", result.getErrorCode());
+    Assert.assertEquals("Could not add authentication headers to the request.",
+        result.getErrorExplanation());
+    Assert.assertEquals("AUTHENTICATION_PROBLEM", result.name());
+    Assert.assertEquals(2, result.ordinal());
+    Assert.assertEquals("AUTHENTICATION_PROBLEM", result.toString());
+  }
+
+  @Test
+  public void testGetErrorText_1() throws Exception {
+    final OAuth2RequestException fixture = new OAuth2RequestException(
+        OAuth2Error.AUTHENTICATION_PROBLEM, "", new Throwable());
+
+    final String result = fixture.getErrorText();
+
+    Assert
+        .assertEquals(
+            "org.apache.shindig.gadgets.oauth2.OAuth2Request encountered a problem :  adding client authentication : ",
+            result);
+  }
+
+  @Test
+  public void testGetMessage_1() throws Exception {
+    final OAuth2RequestException fixture = new OAuth2RequestException(
+        OAuth2Error.AUTHENTICATION_PROBLEM, "", new Throwable());
+
+    final String result = fixture.getMessage();
+
+    Assert
+        .assertEquals(
+            "org.apache.shindig.gadgets.oauth2.OAuth2Request encountered a problem :  adding client authentication : ",
+            result);
+  }
+
+  @Test
+  public void testToString_1() throws Exception {
+    final OAuth2RequestException fixture = new OAuth2RequestException(
+        OAuth2Error.AUTHENTICATION_PROBLEM, "", new Throwable());
+
+    final String result = fixture.toString();
+
+    Assert
+        .assertEquals(
+            "[AUTHENTICATION_PROBLEM,org.apache.shindig.gadgets.oauth2.OAuth2Request encountered a problem :  adding client authentication : ]",
+            result);
+  }
+}
\ No newline at end of file

Added: shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/OAuth2ResponseParamsTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/OAuth2ResponseParamsTest.java?rev=1182565&view=auto
==============================================================================
--- shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/OAuth2ResponseParamsTest.java (added)
+++ shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/OAuth2ResponseParamsTest.java Wed Oct 12 20:10:39 2011
@@ -0,0 +1,305 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shindig.gadgets.oauth2;
+
+import java.net.URI;
+
+import org.apache.shindig.common.uri.Uri;
+import org.apache.shindig.gadgets.http.HttpRequest;
+import org.apache.shindig.gadgets.http.HttpResponse;
+import org.apache.shindig.gadgets.http.HttpResponseBuilder;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class OAuth2ResponseParamsTest {
+  @Test
+  public void testOAuth2ResponseParams_1() throws Exception {
+
+    final OAuth2ResponseParams result = new OAuth2ResponseParams();
+    Assert.assertNotNull(result);
+    Assert.assertEquals(null, result.getAuthorizationUrl());
+  }
+
+  @Test
+  public void testAddDebug_1() throws Exception {
+    final OAuth2ResponseParams fixture = new OAuth2ResponseParams();
+    fixture.addDebug("");
+    fixture.setAuthorizationUrl("");
+    final String message = "";
+
+    fixture.addDebug(message);
+  }
+
+  @Test
+  public void testAddRequestTrace_1() throws Exception {
+    final OAuth2ResponseParams fixture = new OAuth2ResponseParams();
+    fixture.addDebug("");
+    fixture.setAuthorizationUrl("");
+    final HttpResponseBuilder responseBuilder = new HttpResponseBuilder().setStrictNoCache();
+    final HttpRequest request = new HttpRequest(Uri.fromJavaUri(new URI("")));
+    final HttpResponse response = responseBuilder.create();
+
+    fixture.addRequestTrace(request, response);
+  }
+
+  @Test
+  public void testAddToResponse_1() throws Exception {
+    final OAuth2ResponseParams fixture = new OAuth2ResponseParams();
+    fixture.addDebug("");
+    fixture.setAuthorizationUrl("");
+    final HttpResponseBuilder responseBuilder = new HttpResponseBuilder();
+    final String errorCode = "";
+    final String errorDescription = null;
+    final String errorUri = null;
+    final String errorExplanation = null;
+
+    fixture.addToResponse(responseBuilder, errorCode, errorDescription, errorUri, errorExplanation);
+  }
+
+  @Test
+  public void testAddToResponse_2() throws Exception {
+    final OAuth2ResponseParams fixture = new OAuth2ResponseParams();
+    fixture.addDebug("");
+    fixture.setAuthorizationUrl("");
+    final HttpResponseBuilder responseBuilder = new HttpResponseBuilder();
+    final String errorCode = "";
+    final String errorDescription = "";
+    final String errorUri = "";
+    final String errorExplanation = null;
+
+    fixture.addToResponse(responseBuilder, errorCode, errorDescription, errorUri, errorExplanation);
+  }
+
+  @Test
+  public void testAddToResponse_3() throws Exception {
+    final OAuth2ResponseParams fixture = new OAuth2ResponseParams();
+    fixture.addDebug("");
+    fixture.setAuthorizationUrl("");
+    final HttpResponseBuilder responseBuilder = new HttpResponseBuilder();
+    final String errorCode = "";
+    final String errorDescription = null;
+    final String errorUri = "";
+    final String errorExplanation = "";
+
+    fixture.addToResponse(responseBuilder, errorCode, errorDescription, errorUri, errorExplanation);
+  }
+
+  @Test
+  public void testAddToResponse_4() throws Exception {
+    final OAuth2ResponseParams fixture = new OAuth2ResponseParams();
+    fixture.addDebug("");
+    fixture.setAuthorizationUrl("");
+    final HttpResponseBuilder responseBuilder = new HttpResponseBuilder();
+    final String errorCode = "";
+    final String errorDescription = "";
+    final String errorUri = null;
+    final String errorExplanation = "";
+
+    fixture.addToResponse(responseBuilder, errorCode, errorDescription, errorUri, errorExplanation);
+  }
+
+  @Test
+  public void testAddToResponse_5() throws Exception {
+    final OAuth2ResponseParams fixture = new OAuth2ResponseParams();
+    fixture.addDebug("");
+    fixture.setAuthorizationUrl("");
+    final HttpResponseBuilder responseBuilder = new HttpResponseBuilder();
+    final String errorCode = null;
+    final String errorDescription = "";
+    final String errorUri = "";
+    final String errorExplanation = "";
+
+    fixture.addToResponse(responseBuilder, errorCode, errorDescription, errorUri, errorExplanation);
+  }
+
+  @Test
+  public void testAddToResponse_6() throws Exception {
+    final OAuth2ResponseParams fixture = new OAuth2ResponseParams();
+    fixture.addDebug("");
+    fixture.setAuthorizationUrl("");
+    final HttpResponseBuilder responseBuilder = new HttpResponseBuilder();
+    final String errorCode = "";
+    final String errorDescription = "";
+    final String errorUri = "";
+    final String errorExplanation = "";
+
+    fixture.addToResponse(responseBuilder, errorCode, errorDescription, errorUri, errorExplanation);
+  }
+
+  @Test
+  public void testAddToResponse_7() throws Exception {
+    final OAuth2ResponseParams fixture = new OAuth2ResponseParams();
+    fixture.addDebug((String) null);
+    fixture.setAuthorizationUrl("");
+    final HttpResponseBuilder responseBuilder = new HttpResponseBuilder();
+    final String errorCode = null;
+    final String errorDescription = null;
+    final String errorUri = null;
+    final String errorExplanation = null;
+
+    fixture.addToResponse(responseBuilder, errorCode, errorDescription, errorUri, errorExplanation);
+  }
+
+  @Test
+  public void testAddToResponse_8() throws Exception {
+    final OAuth2ResponseParams fixture = new OAuth2ResponseParams();
+    fixture.addDebug((String) null);
+    fixture.setAuthorizationUrl("");
+    final HttpResponseBuilder responseBuilder = new HttpResponseBuilder();
+    final String errorCode = "";
+    final String errorDescription = "";
+    final String errorUri = "";
+    final String errorExplanation = "";
+
+    fixture.addToResponse(responseBuilder, errorCode, errorDescription, errorUri, errorExplanation);
+  }
+
+  @Test
+  public void testAddToResponse_9() throws Exception {
+    final OAuth2ResponseParams fixture = new OAuth2ResponseParams();
+    fixture.addDebug("");
+    fixture.setAuthorizationUrl("");
+    final HttpResponseBuilder responseBuilder = new HttpResponseBuilder();
+    final String errorCode = null;
+    final String errorDescription = null;
+    final String errorUri = null;
+    final String errorExplanation = null;
+
+    fixture.addToResponse(responseBuilder, errorCode, errorDescription, errorUri, errorExplanation);
+  }
+
+  @Test
+  public void testAddToResponse_10() throws Exception {
+    final OAuth2ResponseParams fixture = new OAuth2ResponseParams();
+    fixture.addDebug("");
+    fixture.setAuthorizationUrl("");
+    final HttpResponseBuilder responseBuilder = new HttpResponseBuilder();
+    final String errorCode = "";
+    final String errorDescription = "";
+    final String errorUri = "";
+    final String errorExplanation = "";
+
+    fixture.addToResponse(responseBuilder, errorCode, errorDescription, errorUri, errorExplanation);
+  }
+
+  @Test
+  public void testAddToResponse_11() throws Exception {
+    final OAuth2ResponseParams fixture = new OAuth2ResponseParams();
+    fixture.addDebug((String) null);
+    fixture.setAuthorizationUrl("");
+    final HttpResponseBuilder responseBuilder = new HttpResponseBuilder();
+    final String errorCode = null;
+    final String errorDescription = null;
+    final String errorUri = null;
+    final String errorExplanation = null;
+
+    fixture.addToResponse(responseBuilder, errorCode, errorDescription, errorUri, errorExplanation);
+  }
+
+  @Test
+  public void testAddToResponse_12() throws Exception {
+    final OAuth2ResponseParams fixture = new OAuth2ResponseParams();
+    fixture.addDebug((String) null);
+    fixture.setAuthorizationUrl("");
+    final HttpResponseBuilder responseBuilder = new HttpResponseBuilder();
+    final String errorCode = "";
+    final String errorDescription = null;
+    final String errorUri = null;
+    final String errorExplanation = null;
+
+    fixture.addToResponse(responseBuilder, errorCode, errorDescription, errorUri, errorExplanation);
+  }
+
+  @Test
+  public void testAddToResponse_13() throws Exception {
+    final OAuth2ResponseParams fixture = new OAuth2ResponseParams();
+    fixture.addDebug((String) null);
+    fixture.setAuthorizationUrl("");
+    final HttpResponseBuilder responseBuilder = new HttpResponseBuilder();
+    final String errorCode = null;
+    final String errorDescription = null;
+    final String errorUri = "";
+    final String errorExplanation = null;
+
+    fixture.addToResponse(responseBuilder, errorCode, errorDescription, errorUri, errorExplanation);
+  }
+
+  @Test
+  public void testAddToResponse_14() throws Exception {
+    final OAuth2ResponseParams fixture = new OAuth2ResponseParams();
+    fixture.addDebug((String) null);
+    fixture.setAuthorizationUrl("");
+    final HttpResponseBuilder responseBuilder = new HttpResponseBuilder();
+    final String errorCode = null;
+    final String errorDescription = "";
+    final String errorUri = null;
+    final String errorExplanation = null;
+
+    fixture.addToResponse(responseBuilder, errorCode, errorDescription, errorUri, errorExplanation);
+  }
+
+  @Test
+  public void testAddToResponse_15() throws Exception {
+    final OAuth2ResponseParams fixture = new OAuth2ResponseParams();
+    fixture.addDebug((String) null);
+    fixture.setAuthorizationUrl("");
+    final HttpResponseBuilder responseBuilder = new HttpResponseBuilder();
+    final String errorCode = null;
+    final String errorDescription = null;
+    final String errorUri = null;
+    final String errorExplanation = "";
+
+    fixture.addToResponse(responseBuilder, errorCode, errorDescription, errorUri, errorExplanation);
+  }
+
+  @Test
+  public void testAddToResponse_16() throws Exception {
+    final OAuth2ResponseParams fixture = new OAuth2ResponseParams();
+    fixture.addDebug((String) null);
+    fixture.setAuthorizationUrl("");
+    final HttpResponseBuilder responseBuilder = new HttpResponseBuilder();
+    final String errorCode = null;
+    final String errorDescription = "";
+    final String errorUri = "";
+    final String errorExplanation = "";
+
+    fixture.addToResponse(responseBuilder, errorCode, errorDescription, errorUri, errorExplanation);
+  }
+
+  @Test
+  public void testGetAuthorizationUrl_1() throws Exception {
+    final OAuth2ResponseParams fixture = new OAuth2ResponseParams();
+    fixture.addDebug("");
+    fixture.setAuthorizationUrl("");
+
+    final String result = fixture.getAuthorizationUrl();
+
+    Assert.assertEquals("", result);
+  }
+
+  @Test
+  public void testSetAuthorizationUrl_1() throws Exception {
+    final OAuth2ResponseParams fixture = new OAuth2ResponseParams();
+    fixture.addDebug("");
+    fixture.setAuthorizationUrl("");
+    final String authorizationUrl = "";
+
+    fixture.setAuthorizationUrl(authorizationUrl);
+  }
+}
\ No newline at end of file

Added: shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/handler/BasicAuthenticationHandlerTest.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/handler/BasicAuthenticationHandlerTest.java?rev=1182565&view=auto
==============================================================================
--- shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/handler/BasicAuthenticationHandlerTest.java (added)
+++ shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth2/handler/BasicAuthenticationHandlerTest.java Wed Oct 12 20:10:39 2011
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shindig.gadgets.oauth2.handler;
+
+import java.net.URI;
+
+import org.apache.shindig.common.uri.Uri;
+import org.apache.shindig.gadgets.http.HttpRequest;
+import org.apache.shindig.gadgets.oauth2.MockUtils;
+import org.apache.shindig.gadgets.oauth2.OAuth2Accessor;
+import org.apache.shindig.gadgets.oauth2.OAuth2Error;
+import org.apache.shindig.gadgets.oauth2.OAuth2Message;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class BasicAuthenticationHandlerTest extends MockUtils {
+  @Test
+  public void testBasicAuthenticationHandler_1() throws Exception {
+    final BasicAuthenticationHandler result = new BasicAuthenticationHandler();
+
+    Assert.assertNotNull(result);
+    Assert.assertTrue(ClientAuthenticationHandler.class.isInstance(result));
+    Assert.assertEquals(OAuth2Message.BASIC_AUTH_TYPE, result.geClientAuthenticationType());
+  }
+
+  @Test
+  public void testAddOAuth2Authentication_1() throws Exception {
+    final BasicAuthenticationHandler fixture = new BasicAuthenticationHandler();
+    final HttpRequest request = null;
+    final OAuth2Accessor accessor = MockUtils.getOAuth2Accessor_Code();
+
+    final OAuth2HandlerError result = fixture.addOAuth2Authentication(request, accessor);
+
+    Assert.assertNotNull(result);
+    Assert.assertEquals(null, result.getCause());
+    Assert.assertEquals("request is null", result.getContextMessage());
+    Assert
+        .assertEquals(
+            "org.apache.shindig.gadgets.oauth2.handler.OAuth2HandlerError : AUTHENTICATION_PROBLEM : request is null : null",
+            result.toString());
+  }
+
+  @Test
+  public void testAddOAuth2Authentication_2() throws Exception {
+    final BasicAuthenticationHandler fixture = new BasicAuthenticationHandler();
+    final HttpRequest request = new HttpRequest(Uri.fromJavaUri(new URI("")));
+    final OAuth2Accessor accessor = null;
+
+    final OAuth2HandlerError result = fixture.addOAuth2Authentication(request, accessor);
+
+    Assert.assertNotNull(result);
+    Assert.assertEquals(null, result.getCause());
+    Assert.assertEquals("accessor is invalid null", result.getContextMessage());
+    Assert
+        .assertEquals(
+            "org.apache.shindig.gadgets.oauth2.handler.OAuth2HandlerError : AUTHENTICATION_PROBLEM : accessor is invalid null : null",
+            result.toString());
+  }
+
+  @Test
+  public void testAddOAuth2Authentication_3() throws Exception {
+    final BasicAuthenticationHandler fixture = new BasicAuthenticationHandler();
+    final HttpRequest request = new HttpRequest(Uri.fromJavaUri(new URI("")));
+    final OAuth2Accessor accessor = MockUtils.getOAuth2Accessor_Error();
+
+    final OAuth2HandlerError result = fixture.addOAuth2Authentication(request, accessor);
+
+    Assert.assertNotNull(result);
+    Assert.assertEquals(null, result.getCause());
+    Assert.assertEquals(OAuth2Error.AUTHENTICATION_PROBLEM, result.getError());
+    Assert.assertTrue(result.getContextMessage().startsWith("accessor is invalid"));
+  }
+
+  @Test
+  public void testAddOAuth2Authentication_4() throws Exception {
+    final BasicAuthenticationHandler fixture = new BasicAuthenticationHandler();
+    final HttpRequest request = new HttpRequest(Uri.fromJavaUri(new URI("")));
+    final OAuth2Accessor accessor = MockUtils.getOAuth2Accessor_Code();
+
+    final OAuth2HandlerError result = fixture.addOAuth2Authentication(request, accessor);
+
+    Assert.assertNull(result);
+
+    final String authHeader = request.getHeader("Authorization");
+
+    Assert.assertNotNull(authHeader);
+
+    Assert.assertEquals("Basic: Y2xpZW50SWQxOmNsaWVudFNlY3JldDE=", authHeader);
+  }
+
+  @Test
+  public void testGeClientAuthenticationType_1() throws Exception {
+    final BasicAuthenticationHandler fixture = new BasicAuthenticationHandler();
+
+    final String result = fixture.geClientAuthenticationType();
+    Assert.assertEquals(OAuth2Message.BASIC_AUTH_TYPE, result);
+  }
+}
\ No newline at end of file