use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class ProducesRequestConditionTests method match.
@Test
public void match() throws Exception {
ServerWebExchange exchange = MockServerHttpRequest.get("/").header("Accept", "text/plain").toExchange();
ProducesRequestCondition condition = new ProducesRequestCondition("text/plain");
assertNotNull(condition.getMatchingCondition(exchange));
}
use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class ProducesRequestConditionTests method compareTo.
@Test
public void compareTo() throws Exception {
ProducesRequestCondition html = new ProducesRequestCondition("text/html");
ProducesRequestCondition xml = new ProducesRequestCondition("application/xml");
ProducesRequestCondition none = new ProducesRequestCondition();
ServerWebExchange exchange = MockServerHttpRequest.get("/").header("Accept", "application/xml, text/html").toExchange();
assertTrue(html.compareTo(xml, exchange) > 0);
assertTrue(xml.compareTo(html, exchange) < 0);
assertTrue(xml.compareTo(none, exchange) < 0);
assertTrue(none.compareTo(xml, exchange) > 0);
assertTrue(html.compareTo(none, exchange) < 0);
assertTrue(none.compareTo(html, exchange) > 0);
exchange = MockServerHttpRequest.get("/").header("Accept", "application/xml, text/*").toExchange();
assertTrue(html.compareTo(xml, exchange) > 0);
assertTrue(xml.compareTo(html, exchange) < 0);
exchange = MockServerHttpRequest.get("/").header("Accept", "application/pdf").toExchange();
assertTrue(html.compareTo(xml, exchange) == 0);
assertTrue(xml.compareTo(html, exchange) == 0);
// See SPR-7000
exchange = MockServerHttpRequest.get("/").header("Accept", "text/html;q=0.9,application/xml").toExchange();
assertTrue(html.compareTo(xml, exchange) > 0);
assertTrue(xml.compareTo(html, exchange) < 0);
}
use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class RequestMappingInfoTests method matchCustomCondition.
@Test
public void matchCustomCondition() {
ServerWebExchange exchange = MockServerHttpRequest.get("/foo?foo=bar").toExchange();
RequestMappingInfo info = paths("/foo").params("foo=bar").build();
RequestMappingInfo match = info.getMatchingCondition(exchange);
assertNotNull(match);
info = paths("/foo").params("foo!=bar").customCondition(new ParamsRequestCondition("foo!=bar")).build();
match = info.getMatchingCondition(exchange);
assertNull(match);
}
use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class RequestMappingInfoTests method compareTwoHttpMethodsOneParam.
@Test
public void compareTwoHttpMethodsOneParam() {
RequestMappingInfo none = paths().build();
RequestMappingInfo oneMethod = paths().methods(RequestMethod.GET).build();
RequestMappingInfo oneMethodOneParam = paths().methods(RequestMethod.GET).params("foo").build();
ServerWebExchange exchange = MockServerHttpRequest.get("/foo").toExchange();
Comparator<RequestMappingInfo> comparator = (info, otherInfo) -> info.compareTo(otherInfo, exchange);
List<RequestMappingInfo> list = asList(none, oneMethod, oneMethodOneParam);
Collections.shuffle(list);
list.sort(comparator);
assertEquals(oneMethodOneParam, list.get(0));
assertEquals(oneMethod, list.get(1));
assertEquals(none, list.get(2));
}
use of org.springframework.web.server.ServerWebExchange in project spring-framework by spring-projects.
the class RequestMappingInfoTests method matchProducesCondition.
@Test
public void matchProducesCondition() {
ServerWebExchange exchange = MockServerHttpRequest.get("/foo").accept(MediaType.TEXT_PLAIN).toExchange();
RequestMappingInfo info = paths("/foo").produces("text/plain").build();
RequestMappingInfo match = info.getMatchingCondition(exchange);
assertNotNull(match);
info = paths("/foo").produces("application/xml").build();
match = info.getMatchingCondition(exchange);
assertNull(match);
}
Aggregations