use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.
the class ProducesRequestConditionTests method compareToMediaTypeAll.
// SPR-8536
@Test
public void compareToMediaTypeAll() {
MockServerWebExchange exchange = MockServerWebExchange.from(get("/"));
ProducesRequestCondition condition1 = new ProducesRequestCondition();
ProducesRequestCondition condition2 = new ProducesRequestCondition("application/json");
assertThat(condition1.compareTo(condition2, exchange) < 0).as("Should have picked '*/*' condition as an exact match").isTrue();
assertThat(condition2.compareTo(condition1, exchange) > 0).as("Should have picked '*/*' condition as an exact match").isTrue();
condition1 = new ProducesRequestCondition("*/*");
condition2 = new ProducesRequestCondition("application/json");
assertThat(condition1.compareTo(condition2, exchange) < 0).isTrue();
assertThat(condition2.compareTo(condition1, exchange) > 0).isTrue();
exchange = MockServerWebExchange.from(get("/").header("Accept", "*/*"));
condition1 = new ProducesRequestCondition();
condition2 = new ProducesRequestCondition("application/json");
assertThat(condition1.compareTo(condition2, exchange) < 0).isTrue();
assertThat(condition2.compareTo(condition1, exchange) > 0).isTrue();
condition1 = new ProducesRequestCondition("*/*");
condition2 = new ProducesRequestCondition("application/json");
assertThat(condition1.compareTo(condition2, exchange) < 0).isTrue();
assertThat(condition2.compareTo(condition1, exchange) > 0).isTrue();
}
use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.
the class ProducesRequestConditionTests method compareTo.
@Test
public void compareTo() {
ProducesRequestCondition html = new ProducesRequestCondition("text/html");
ProducesRequestCondition xml = new ProducesRequestCondition("application/xml");
ProducesRequestCondition none = new ProducesRequestCondition();
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", "application/xml, text/html"));
assertThat(html.compareTo(xml, exchange) > 0).isTrue();
assertThat(xml.compareTo(html, exchange) < 0).isTrue();
assertThat(xml.compareTo(none, exchange) < 0).isTrue();
assertThat(none.compareTo(xml, exchange) > 0).isTrue();
assertThat(html.compareTo(none, exchange) < 0).isTrue();
assertThat(none.compareTo(html, exchange) > 0).isTrue();
exchange = MockServerWebExchange.from(get("/").header("Accept", "application/xml, text/*"));
assertThat(html.compareTo(xml, exchange) > 0).isTrue();
assertThat(xml.compareTo(html, exchange) < 0).isTrue();
exchange = MockServerWebExchange.from(get("/").header("Accept", "application/pdf"));
assertThat(html.compareTo(xml, exchange)).isEqualTo(0);
assertThat(xml.compareTo(html, exchange)).isEqualTo(0);
// See SPR-7000
exchange = MockServerWebExchange.from(get("/").header("Accept", "text/html;q=0.9,application/xml"));
assertThat(html.compareTo(xml, exchange) > 0).isTrue();
assertThat(xml.compareTo(html, exchange) < 0).isTrue();
}
use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.
the class ProducesRequestConditionTests method match.
@Test
public void match() {
MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", "text/plain"));
ProducesRequestCondition condition = new ProducesRequestCondition("text/plain");
assertThat(condition.getMatchingCondition(exchange)).isNotNull();
}
use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.
the class HandlerResultHandlerTests method producibleMediaTypesRequestAttribute.
@Test
void producibleMediaTypesRequestAttribute() {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path"));
exchange.getAttributes().put(HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, Collections.singleton(IMAGE_GIF));
List<MediaType> mediaTypes = Arrays.asList(IMAGE_JPEG, IMAGE_GIF, IMAGE_PNG);
MediaType actual = resultHandler.selectMediaType(exchange, () -> mediaTypes);
assertThat(actual).isEqualTo(IMAGE_GIF);
}
use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.
the class HandlerResultHandlerTests method removeQualityParameter.
@Test
void removeQualityParameter() {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path").header("Accept", "text/plain; q=0.5"));
List<MediaType> mediaTypes = Arrays.asList(APPLICATION_JSON, TEXT_PLAIN);
MediaType actual = this.resultHandler.selectMediaType(exchange, () -> mediaTypes);
assertThat(actual).isEqualTo(TEXT_PLAIN);
}
Aggregations