use of org.springframework.http.client.ClientHttpRequest in project spring-security-oauth by spring-projects.
the class AuthorizationCodeAccessTokenProviderWithConversionTests method testGetErrorFromForm.
@Test
public void testGetErrorFromForm() throws Exception {
final HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
requestFactory = new ClientHttpRequestFactory() {
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
return new StubClientHttpRequest(HttpStatus.BAD_REQUEST, responseHeaders, "error=invalid_client&error_description=FOO");
}
};
AccessTokenRequest request = new DefaultAccessTokenRequest();
request.setAuthorizationCode("foo");
request.setPreservedState(new Object());
resource.setAccessTokenUri("http://localhost/oauth/token");
expected.expect(OAuth2AccessDeniedException.class);
expected.expect(hasCause(instanceOf(InvalidClientException.class)));
setUpRestTemplate();
provider.obtainAccessToken(resource, request);
}
use of org.springframework.http.client.ClientHttpRequest in project spring-boot by spring-projects.
the class DelayedLiveReloadTrigger method isUp.
private boolean isUp() {
try {
ClientHttpRequest request = createRequest();
ClientHttpResponse response = request.execute();
return response.getStatusCode() == HttpStatus.OK;
} catch (Exception ex) {
return false;
}
}
use of org.springframework.http.client.ClientHttpRequest in project spring-boot by spring-projects.
the class MultipartAutoConfigurationTests method verify404.
private void verify404() throws Exception {
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
ClientHttpRequest request = requestFactory.createRequest(new URI("http://localhost:" + this.context.getWebServer().getPort() + "/"), HttpMethod.GET);
ClientHttpResponse response = request.execute();
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}
use of org.springframework.http.client.ClientHttpRequest in project spring-boot by spring-projects.
the class RootUriRequestExpectationManagerTests method validateRequestWhenRequestUriAssertionIsThrownShouldReplaceUriInMessage.
@Test
public void validateRequestWhenRequestUriAssertionIsThrownShouldReplaceUriInMessage() throws Exception {
ClientHttpRequest request = mock(ClientHttpRequest.class);
given(request.getURI()).willReturn(new URI(this.uri + "/hello"));
given(this.delegate.validateRequest((ClientHttpRequest) any())).willThrow(new AssertionError("Request URI expected:</hello> was:<http://example.com/bad>"));
this.thrown.expect(AssertionError.class);
this.thrown.expectMessage("Request URI expected:<http://example.com/hello>");
this.manager.validateRequest(request);
}
use of org.springframework.http.client.ClientHttpRequest in project spring-boot by spring-projects.
the class RootUriRequestExpectationManagerTests method validateRequestWhenUriStartsWithRootUriShouldReplaceUri.
@Test
public void validateRequestWhenUriStartsWithRootUriShouldReplaceUri() throws Exception {
ClientHttpRequest request = mock(ClientHttpRequest.class);
given(request.getURI()).willReturn(new URI(this.uri + "/hello"));
this.manager.validateRequest(request);
verify(this.delegate).validateRequest(this.requestCaptor.capture());
HttpRequestWrapper actual = (HttpRequestWrapper) this.requestCaptor.getValue();
assertThat(actual.getRequest()).isSameAs(request);
assertThat(actual.getURI()).isEqualTo(new URI("/hello"));
}
Aggregations