Search in sources :

Example 6 with RequestMatcher

use of org.springframework.test.web.client.RequestMatcher in project spring-framework by spring-projects.

the class ContentRequestMatchers method contentType.

/**
	 * Assert the request content type as a {@link MediaType}.
	 */
public RequestMatcher contentType(final MediaType expectedContentType) {
    return new RequestMatcher() {

        @Override
        public void match(ClientHttpRequest request) throws IOException, AssertionError {
            MediaType actualContentType = request.getHeaders().getContentType();
            assertTrue("Content type not set", actualContentType != null);
            assertEquals("Content type", expectedContentType, actualContentType);
        }
    };
}
Also used : RequestMatcher(org.springframework.test.web.client.RequestMatcher) MediaType(org.springframework.http.MediaType) MockClientHttpRequest(org.springframework.mock.http.client.MockClientHttpRequest) ClientHttpRequest(org.springframework.http.client.ClientHttpRequest)

Example 7 with RequestMatcher

use of org.springframework.test.web.client.RequestMatcher in project spring-framework by spring-projects.

the class ContentRequestMatchers method bytes.

/**
	 * Compare the body of the request to the given byte array.
	 */
public RequestMatcher bytes(final byte[] expectedContent) {
    return new RequestMatcher() {

        @Override
        public void match(ClientHttpRequest request) throws IOException, AssertionError {
            MockClientHttpRequest mockRequest = (MockClientHttpRequest) request;
            assertEquals("Request content", expectedContent, mockRequest.getBodyAsBytes());
        }
    };
}
Also used : RequestMatcher(org.springframework.test.web.client.RequestMatcher) MockClientHttpRequest(org.springframework.mock.http.client.MockClientHttpRequest) MockClientHttpRequest(org.springframework.mock.http.client.MockClientHttpRequest) ClientHttpRequest(org.springframework.http.client.ClientHttpRequest)

Aggregations

RequestMatcher (org.springframework.test.web.client.RequestMatcher)7 ClientHttpRequest (org.springframework.http.client.ClientHttpRequest)6 MockClientHttpRequest (org.springframework.mock.http.client.MockClientHttpRequest)6 MediaType (org.springframework.http.MediaType)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Test (org.junit.Test)1 HttpInputMessage (org.springframework.http.HttpInputMessage)1 FormHttpMessageConverter (org.springframework.http.converter.FormHttpMessageConverter)1 ExpectedCount (org.springframework.test.web.client.ExpectedCount)1