Search in sources :

Example 1 with TEXT_XML_VALUE

use of org.springframework.http.MediaType.TEXT_XML_VALUE in project spring-framework by spring-projects.

the class RequestPredicatesTests method accept.

@Test
void accept() {
    MediaType json = MediaType.APPLICATION_JSON;
    RequestPredicate predicate = RequestPredicates.accept(json);
    ServerRequest request = initRequest("GET", "/path", req -> req.addHeader("Accept", json.toString()));
    assertThat(predicate.test(request)).isTrue();
    request = initRequest("GET", "", req -> req.addHeader("Accept", TEXT_XML_VALUE));
    assertThat(predicate.test(request)).isFalse();
}
Also used : MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) HttpHeaders(org.springframework.http.HttpHeaders) MediaType(org.springframework.http.MediaType) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HttpMethod(org.springframework.http.HttpMethod) PathPatternParser(org.springframework.web.util.pattern.PathPatternParser) TEXT_XML_VALUE(org.springframework.http.MediaType.TEXT_XML_VALUE) Function(java.util.function.Function) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) Nullable(org.springframework.lang.Nullable) PathPatternsTestUtils(org.springframework.web.servlet.handler.PathPatternsTestUtils) Collections(java.util.Collections) MediaType(org.springframework.http.MediaType) Test(org.junit.jupiter.api.Test)

Aggregations

Collections (java.util.Collections)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Test (org.junit.jupiter.api.Test)1 HttpHeaders (org.springframework.http.HttpHeaders)1 HttpMethod (org.springframework.http.HttpMethod)1 MediaType (org.springframework.http.MediaType)1 TEXT_XML_VALUE (org.springframework.http.MediaType.TEXT_XML_VALUE)1 Nullable (org.springframework.lang.Nullable)1 PathPatternsTestUtils (org.springframework.web.servlet.handler.PathPatternsTestUtils)1 MockHttpServletRequest (org.springframework.web.testfixture.servlet.MockHttpServletRequest)1 PathPatternParser (org.springframework.web.util.pattern.PathPatternParser)1