use of org.springframework.web.client.HttpStatusCodeException in project spring-security-oauth by spring-projects.
the class ClientCredentialsProviderTests method testHardCodedAuthenticationWrongClient.
@Test
public void testHardCodedAuthenticationWrongClient() {
RestTemplate restTemplate = new RestTemplate();
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
params.add("grant_type", "client_credentials");
params.add("client_id", "my-trusted-client");
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
RequestEntity<MultiValueMap<String, String>> req = new RequestEntity<MultiValueMap<String, String>>(params, headers, HttpMethod.POST, tokenUri);
try {
restTemplate.exchange(req, Map.class);
fail("Expected HTTP 401");
} catch (HttpStatusCodeException e) {
assertEquals(HttpStatus.UNAUTHORIZED, e.getStatusCode());
}
}
Aggregations