.expectAccessGrant(ACCESS_GRANT)
.expectRedirectUri(REDIRECT_URI)
.build();
replay(request);
OAuthTokenRequest req = null;
try {
req = new OAuthTokenRequest(request);
} catch (OAuthProblemException e) {
fail("Exception not expected");
}
assertEquals(GrantType.AUTHORIZATION_CODE.toString(), req.getGrantType());
assertEquals(CLIENT_ID, req.getClientId());
assertEquals(REDIRECT_URI, req.getRedirectURI());
assertEquals(ACCESS_GRANT, req.getCode());
verify(request);
request = new OauthMockRequestBuilder()
.expectGrantType(GrantType.PASSWORD.toString())
.expectHttpMethod(OAuth.HttpMethod.POST)
.expectContentType(OAuth.ContentType.URL_ENCODED)
.expectClientId(CLIENT_ID)
.expectClientSecret(SECRET)
.expectBasicAuthHeader(null)
.expectOauthUsername(USERNAME)
.expectOauthPassword(PASSWORD)
.build();
replay(request);
try {
req = new OAuthTokenRequest(request);
} catch (OAuthProblemException e) {
fail("Exception not expected");
}
assertEquals(CLIENT_ID, req.getClientId());
assertEquals(USERNAME, req.getUsername());
assertEquals(PASSWORD, req.getPassword());
verify(request);
request = new OauthMockRequestBuilder()
.expectGrantType(GrantType.CLIENT_CREDENTIALS.toString())
.expectHttpMethod(OAuth.HttpMethod.POST)
.expectContentType(OAuth.ContentType.URL_ENCODED)
.expectBasicAuthHeader(createBasicAuthHeader(CLIENT_ID, SECRET))
.build();
replay(request);
try {
req = new OAuthTokenRequest(request);
} catch (OAuthProblemException e) {
fail("Exception not expected");
}
verify(request);
request = new OauthMockRequestBuilder()
.expectGrantType(GrantType.REFRESH_TOKEN.toString())
.expectHttpMethod(OAuth.HttpMethod.POST)
.expectContentType(OAuth.ContentType.URL_ENCODED)
.expectClientId(CLIENT_ID)
.expectClientSecret(SECRET)
.expectBasicAuthHeader(null)
.expectOauthRefreshToken(REFRESH_TOKEN)
.build();
replay(request);
try {
req = new OAuthTokenRequest(request);
} catch (OAuthProblemException e) {
fail("Exception not expected");
}
assertEquals(CLIENT_ID, req.getClientId());
assertEquals(REFRESH_TOKEN, req.getRefreshToken());
assertEquals(SECRET, req.getClientSecret());
verify(request);
request = new OauthMockRequestBuilder()
.expectGrantType(GrantType.REFRESH_TOKEN.toString())
.expectHttpMethod(OAuth.HttpMethod.POST)
.expectContentType(OAuth.ContentType.URL_ENCODED)
.expectClientId("")
.expectClientSecret("")
.expectBasicAuthHeader(createBasicAuthHeader(CLIENT_ID, SECRET))
.expectOauthRefreshToken(REFRESH_TOKEN)
.build();
replay(request);
try {
req = new OAuthTokenRequest(request);
} catch (OAuthProblemException e) {
fail("Exception not expected");
}
assertEquals(CLIENT_ID, req.getClientId());
assertEquals(REFRESH_TOKEN, req.getRefreshToken());
assertEquals(SECRET, req.getClientSecret());
verify(request);
}