Package org.apache.shindig.gadgets.oauth2.persistence.sample

Examples of org.apache.shindig.gadgets.oauth2.persistence.sample.JSONOAuth2PersisterTest


        .isInstance(TokenAuthorizationResponseHandlerTest.tarh));
  }

  @Test
  public void testHandlesResponse_1() throws Exception {
    final OAuth2Accessor accessor = MockUtils.getOAuth2Accessor_Error();
    final HttpResponse response = new HttpResponse();

    final boolean result = TokenAuthorizationResponseHandlerTest.tarh.handlesResponse(accessor,
        response);
    Assert.assertFalse(result);
View Full Code Here


    Assert.assertFalse(result);
  }

  @Test
  public void testHandlesResponse_2() throws Exception {
    final OAuth2Accessor accessor = MockUtils.getOAuth2Accessor_Code();
    final HttpResponse response = null;

    final boolean result = TokenAuthorizationResponseHandlerTest.tarh.handlesResponse(accessor,
        response);
    Assert.assertFalse(result);
View Full Code Here

    Assert.assertFalse(result);
  }

  @Test
  public void testHandlesResponse_3() throws Exception {
    final OAuth2Accessor accessor = MockUtils.getOAuth2Accessor_Code();
    final HttpResponse response = new HttpResponse();

    final boolean result = TokenAuthorizationResponseHandlerTest.tarh.handlesResponse(accessor,
        response);
    Assert.assertTrue(result);
View Full Code Here

    Assert.assertTrue(result);
  }

  @Test
  public void testHandleResponse_1() throws Exception {
    final OAuth2Accessor accessor = MockUtils.getOAuth2Accessor_Error();
    final HttpResponse response = new HttpResponse();

    final OAuth2HandlerError result = TokenAuthorizationResponseHandlerTest.tarh.handleResponse(
        accessor, response);
    Assert.assertNotNull(result);
View Full Code Here

    Assert.assertTrue(result.getContextMessage().startsWith("accessor is invalid"));
  }

  @Test
  public void testHandleResponse_2() throws Exception {
    final OAuth2Accessor accessor = MockUtils.getOAuth2Accessor_Code();
    final HttpResponse response = null;

    final OAuth2HandlerError result = TokenAuthorizationResponseHandlerTest.tarh.handleResponse(
        accessor, response);
    Assert.assertNotNull(result);
View Full Code Here

    Assert.assertEquals("response is null", result.getContextMessage());
  }

  @Test
  public void testHandleResponse_3() throws Exception {
    final OAuth2Accessor accessor = MockUtils.getOAuth2Accessor_Code();
    final HttpResponseBuilder builder = new HttpResponseBuilder().setStrictNoCache();
    builder.setHttpStatusCode(HttpResponse.SC_FORBIDDEN);
    final HttpResponse response = builder.create();

    final OAuth2HandlerError result = TokenAuthorizationResponseHandlerTest.tarh.handleResponse(
View Full Code Here

    Assert.assertTrue(result.getContextMessage().startsWith("can't handle error response"));
  }

  @Test
  public void testHandleResponse_4() throws Exception {
    final OAuth2Accessor accessor = MockUtils.getOAuth2Accessor_Code();
    final HttpResponseBuilder builder = new HttpResponseBuilder().setStrictNoCache();
    builder.setHttpStatusCode(HttpResponse.SC_OK);
    builder.setHeader("Content-Type", "text/plain");
    builder
        .setContent("access_token=xxx&token_type=Bearer&expires=1&refresh_token=yyy&example_parameter=example_value");
    final HttpResponse response = builder.create();

    final OAuth2HandlerError result = TokenAuthorizationResponseHandlerTest.tarh.handleResponse(
        accessor, response);

    Assert.assertNull(result);

    final OAuth2Token accessToken = TokenAuthorizationResponseHandlerTest.store.getToken(
        accessor.getGadgetUri(), accessor.getServiceName(), accessor.getUser(),
        accessor.getScope(), OAuth2Token.Type.ACCESS);
    Assert.assertNotNull(accessToken);
    Assert.assertEquals("xxx", new String(accessToken.getSecret(), "UTF-8"));
    Assert.assertEquals(OAuth2Message.BEARER_TOKEN_TYPE, accessToken.getTokenType());
    Assert.assertTrue(accessToken.getExpiresAt() > 1000);

    final OAuth2Token refreshToken = TokenAuthorizationResponseHandlerTest.store.getToken(
        accessor.getGadgetUri(), accessor.getServiceName(), accessor.getUser(),
        accessor.getScope(), OAuth2Token.Type.REFRESH);
    Assert.assertNotNull(refreshToken);
    Assert.assertEquals("yyy", new String(refreshToken.getSecret(), "UTF-8"));
  }
View Full Code Here

    Assert.assertEquals("yyy", new String(refreshToken.getSecret(), "UTF-8"));
  }

  @Test
  public void testHandleResponse_5() throws Exception {
    final OAuth2Accessor accessor = MockUtils.getOAuth2Accessor_Code();
    final HttpResponseBuilder builder = new HttpResponseBuilder().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\"}");
    final HttpResponse response = builder.create();

    final OAuth2HandlerError result = TokenAuthorizationResponseHandlerTest.tarh.handleResponse(
        accessor, response);

    Assert.assertNull(result);

    final OAuth2Token accessToken = TokenAuthorizationResponseHandlerTest.store.getToken(
        accessor.getGadgetUri(), accessor.getServiceName(), accessor.getUser(),
        accessor.getScope(), OAuth2Token.Type.ACCESS);
    Assert.assertNotNull(accessToken);
    Assert.assertEquals("xxx", new String(accessToken.getSecret(), "UTF-8"));
    Assert.assertEquals(OAuth2Message.BEARER_TOKEN_TYPE, accessToken.getTokenType());
    Assert.assertTrue(accessToken.getExpiresAt() > 1000);

    final OAuth2Token refreshToken = TokenAuthorizationResponseHandlerTest.store.getToken(
        accessor.getGadgetUri(), accessor.getServiceName(), accessor.getUser(),
        accessor.getScope(), OAuth2Token.Type.REFRESH);
    Assert.assertNotNull(refreshToken);
    Assert.assertEquals("yyy", new String(refreshToken.getSecret(), "UTF-8"));
  }
View Full Code Here

    Assert.assertEquals("yyy", new String(refreshToken.getSecret(), "UTF-8"));
  }

  @Test
  public void testHandleResponse_6() throws Exception {
    final OAuth2Accessor accessor = MockUtils.getOAuth2Accessor_Code();
    final HttpResponseBuilder builder = new HttpResponseBuilder().setStrictNoCache();
    builder.setHttpStatusCode(HttpResponse.SC_OK);
    builder.setHeader("Content-Type", "BAD");
    final HttpResponse response = builder.create();
View Full Code Here

  }

  @Test(expected = OAuth2RequestException.class)
  public void testGetAuthorizationRequest_1() throws Exception {
    final CodeGrantTypeHandler fixture = CodeGrantTypeHandlerTest.cgth;
    final OAuth2Accessor accessor = MockUtils.getOAuth2Accessor_Code();
    final String completeAuthorizationUrl = "xxx";

    fixture.getAuthorizationRequest(accessor, completeAuthorizationUrl);
  }
View Full Code Here

TOP

Related Classes of org.apache.shindig.gadgets.oauth2.persistence.sample.JSONOAuth2PersisterTest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.