expect(request.getMethod()).andStubReturn(OAuth.HttpMethod.POST);
expect(request.getContentType()).andStubReturn(OAuth.ContentType.URL_ENCODED);
expect(request.getParameterValues(OAuth.OAUTH_BEARER_TOKEN)).andStubReturn(new String[] {"sometoken"});
replay(request);
OAuthAccessResourceRequest req = null;
try {
req = new OAuthAccessResourceRequest(request, ParameterStyle.BODY);
} catch (OAuthProblemException e) {
fail("Exception not expected");
}
Assert.assertEquals("sometoken", req.getAccessToken());
verify(request);
reset(request);
//test header
expect(request.getParameter(OAuth.OAUTH_BEARER_TOKEN)).andStubReturn("sometoken");
expect(request.getParameter(OAuth.OAUTH_VERSION_DIFFER)).andStubReturn(null);
expect(request.getHeader("Authorization")).andStubReturn(AUTHORIZATION_HEADER_OAUTH2);
expect(request.getParameterValues(OAuth.OAUTH_BEARER_TOKEN)).andStubReturn(new String[] {"sometoken"});
replay(request);
try {
req = new OAuthAccessResourceRequest(request);
} catch (OAuthProblemException e) {
fail("Exception not expected");
}
Assert.assertEquals("sometoken", req.getAccessToken());
verify(request);
reset(request);
//test uri query
expect(request.getQueryString()).andStubReturn(OAuth.OAUTH_BEARER_TOKEN + "=sometoken");
// expect(request.getParameter(OAuth.OAUTH_BEARER_TOKEN)).andStubReturn("sometoken");
// expect(request.getParameter(OAuth.OAUTH_VERSION_DIFFER)).andStubReturn(null);
// expect(request.getParameterValues(OAuth.OAUTH_BEARER_TOKEN)).andStubReturn(new String[] {"sometoken"});
replay(request);
req = new OAuthAccessResourceRequest(request, ParameterStyle.QUERY);
Assert.assertEquals("sometoken", req.getAccessToken());
verify(request);
}