expect(request.getParameter(OAuth.OAUTH_REDIRECT_URI)).andStubReturn("http://example.com/callback");
expect(request.getParameter(OAuth.OAUTH_CODE)).andStubReturn("test_code");
expect(request.getParameter(OAuth.OAUTH_CLIENT_SECRET)).andStubReturn("test_secret");
replay(request);
OAuthTokenRequest req = null;
try {
req = new OAuthTokenRequest(request);
} catch (OAuthProblemException e) {
fail("Exception not expected");
}
Assert.assertEquals(GrantType.AUTHORIZATION_CODE.toString(), req.getGrantType());
Assert.assertEquals("test_client", req.getClientId());
Assert.assertEquals("http://example.com/callback", req.getRedirectURI());
Assert.assertEquals("test_code", req.getCode());
verify(request);
reset(request);
expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
.andStubReturn(GrantType.PASSWORD.toString());
expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST);
expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);
expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("client_id");
expect(request.getParameter(OAuth.OAUTH_USERNAME)).andStubReturn("username_test");
expect(request.getParameter(OAuth.OAUTH_PASSWORD)).andStubReturn("test_password");
replay(request);
try {
req = new OAuthTokenRequest(request);
} catch (OAuthProblemException e) {
fail("Exception not expected");
}
Assert.assertEquals("client_id", req.getClientId());
Assert.assertEquals("username_test", req.getUsername());
Assert.assertEquals("test_password", req.getPassword());
verify(request);
reset(request);
expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST);
expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);
expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE)).andStubReturn(GrantType.CLIENT_CREDENTIALS.toString());
replay(request);
try {
req = new OAuthTokenRequest(request);
} catch (OAuthProblemException e) {
fail("Exception not expected");
}
// Assert.assertEquals("test_assertion", req.getAssertion());
// Assert.assertEquals("test_type", req.getAssertionType());
verify(request);
reset(request);
expect(request.getParameter(OAuth.OAUTH_GRANT_TYPE))
.andStubReturn(GrantType.REFRESH_TOKEN.toString());
expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST);
expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);
expect(request.getParameter(OAuth.OAUTH_CLIENT_ID)).andStubReturn("client_id");
expect(request.getParameter(OAuth.OAUTH_REFRESH_TOKEN)).andStubReturn("refresh_token");
expect(request.getParameter(OAuth.OAUTH_CLIENT_SECRET)).andStubReturn("secret");
replay(request);
try {
req = new OAuthTokenRequest(request);
} catch (OAuthProblemException e) {
fail("Exception not expected");
}
Assert.assertEquals("client_id", req.getClientId());
Assert.assertEquals("refresh_token", req.getRefreshToken());
Assert.assertEquals("secret", req.getClientSecret());
verify(request);
}