コード例 #1
0
  /** Test successful authorization. */
  @Test
  public void testSuccessfulAuthorizationWithUnsignedCallback() {
    final OAuthDomainEntry dto = new OAuthDomainEntry();
    dto.setCallbackUrlSigned(false);

    context.checking(
        new Expectations() {
          {
            oneOf(actionContext).getPrincipal();
            will(returnValue(principal));

            oneOf(principal).getAccountId();
            will(returnValue("testacctid"));

            oneOf(actionContext).getParams();
            will(returnValue("token"));

            oneOf(entryMapper).execute("token");
            will(returnValue(dto));

            oneOf(entryMapper).execute("token");
            will(returnValue(dto));
          }
        });

    String callbackurl = sut.execute(actionContext);
    assertNotNull(callbackurl);
    assertEquals(dto.isAuthorized(), true);
    assertTrue(dto.getCallbackToken() == null);

    context.assertIsSatisfied();
  }
コード例 #2
0
  /** Test failure authorization. */
  @Test(expected = ExecutionException.class)
  public void testAuthorizationFailedTokenNotFound() {
    final OAuthDomainEntry dto = new OAuthDomainEntry();
    dto.setCallbackUrlSigned(true);

    context.checking(
        new Expectations() {
          {
            oneOf(actionContext).getPrincipal();
            will(returnValue(principal));

            oneOf(principal).getAccountId();
            will(returnValue("testacctid"));

            oneOf(actionContext).getParams();
            will(returnValue("token"));

            oneOf(entryMapper).execute("token");
            will(throwException(new Exception()));
          }
        });

    sut.execute(actionContext);

    context.assertIsSatisfied();
  }