use of org.springframework.test.web.client.RequestMatcher in project spring-boot by spring-projects.
the class RootUriRequestExpectationManagerTests method expectRequestShouldDelegateToExpectationManager.
@Test
public void expectRequestShouldDelegateToExpectationManager() throws Exception {
ExpectedCount count = mock(ExpectedCount.class);
RequestMatcher requestMatcher = mock(RequestMatcher.class);
this.manager.expectRequest(count, requestMatcher);
verify(this.delegate).expectRequest(count, requestMatcher);
}
use of org.springframework.test.web.client.RequestMatcher in project spring-framework by spring-projects.
the class ContentRequestMatchers method string.
/**
* Get the body of the request as a UTF-8 string and compare it to the given String.
*/
public RequestMatcher string(final String expectedContent) {
return new RequestMatcher() {
@Override
public void match(ClientHttpRequest request) throws IOException, AssertionError {
MockClientHttpRequest mockRequest = (MockClientHttpRequest) request;
assertEquals("Request content", expectedContent, mockRequest.getBodyAsString());
}
};
}
use of org.springframework.test.web.client.RequestMatcher in project spring-framework by spring-projects.
the class ContentRequestMatchers method string.
/**
* Get the body of the request as a UTF-8 string and appply the given {@link Matcher}.
*/
public RequestMatcher string(final Matcher<? super String> matcher) {
return new RequestMatcher() {
@Override
public void match(ClientHttpRequest request) throws IOException, AssertionError {
MockClientHttpRequest mockRequest = (MockClientHttpRequest) request;
assertThat("Request content", mockRequest.getBodyAsString(), matcher);
}
};
}
use of org.springframework.test.web.client.RequestMatcher in project spring-framework by spring-projects.
the class ContentRequestMatchers method contentTypeCompatibleWith.
/**
* Assert the request content type is compatible with the given
* content type as defined by {@link MediaType#isCompatibleWith(MediaType)}.
*/
public RequestMatcher contentTypeCompatibleWith(final MediaType contentType) {
return new RequestMatcher() {
@Override
public void match(ClientHttpRequest request) throws IOException, AssertionError {
MediaType actualContentType = request.getHeaders().getContentType();
assertTrue("Content type not set", actualContentType != null);
assertTrue("Content type [" + actualContentType + "] is not compatible with [" + contentType + "]", actualContentType.isCompatibleWith(contentType));
}
};
}
use of org.springframework.test.web.client.RequestMatcher in project spring-framework by spring-projects.
the class ContentRequestMatchers method formData.
/**
* Parse the body as form data and compare to the given {@code MultiValueMap}.
* @since 4.3
*/
public RequestMatcher formData(final MultiValueMap<String, String> expectedContent) {
return new RequestMatcher() {
@Override
public void match(final ClientHttpRequest request) throws IOException, AssertionError {
HttpInputMessage inputMessage = new HttpInputMessage() {
@Override
public InputStream getBody() throws IOException {
MockClientHttpRequest mockRequest = (MockClientHttpRequest) request;
return new ByteArrayInputStream(mockRequest.getBodyAsBytes());
}
@Override
public HttpHeaders getHeaders() {
return request.getHeaders();
}
};
FormHttpMessageConverter converter = new FormHttpMessageConverter();
assertEquals("Request content", expectedContent, converter.read(null, inputMessage));
}
};
}
Aggregations