MockRestServiceServer mockServer = MockRestServiceServer.createServer(oauthTemplate.getRestTemplate());
ResponseActions responseActions = mockServer.expect(requestTo(ACCESS_TOKEN_URL))
.andExpect(method(POST))
.andExpect(content().string(expectedClientParams + "username=habuma&password=letmein01&grant_type=password&scope=read%2Cwrite"));
if (expectedAuthorizationHeader != null) {
responseActions.andExpect(header("Authorization", expectedAuthorizationHeader));
}
responseActions.andRespond(withSuccess(new ClassPathResource(responseFile, getClass()), MediaType.APPLICATION_JSON));
OAuth2Parameters parameters = new OAuth2Parameters();
parameters.setScope("read,write");
return oauthTemplate.exchangeCredentialsForAccess("habuma", "letmein01", parameters);