Search in sources :

Example 46 with MockServerWebExchange

use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.

the class ConsumesRequestConditionTests method negatedConsumesMatch.

@Test
public void negatedConsumesMatch() throws Exception {
    MockServerWebExchange exchange = postExchange("text/plain");
    ConsumesRequestCondition condition = new ConsumesRequestCondition("!text/plain");
    assertThat(condition.getMatchingCondition(exchange)).isNull();
}
Also used : MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) Test(org.junit.jupiter.api.Test)

Example 47 with MockServerWebExchange

use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.

the class ConsumesRequestConditionTests method consumesMatch.

@Test
public void consumesMatch() throws Exception {
    MockServerWebExchange exchange = postExchange("text/plain");
    ConsumesRequestCondition condition = new ConsumesRequestCondition("text/plain");
    assertThat(condition.getMatchingCondition(exchange)).isNotNull();
}
Also used : MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) Test(org.junit.jupiter.api.Test)

Example 48 with MockServerWebExchange

use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.

the class ParamsRequestConditionTests method paramNotPresent.

@Test
public void paramNotPresent() throws Exception {
    MockServerWebExchange exchange = MockServerWebExchange.from(get("/"));
    assertThat(new ParamsRequestCondition("!foo").getMatchingCondition(exchange)).isNotNull();
}
Also used : MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) Test(org.junit.jupiter.api.Test)

Example 49 with MockServerWebExchange

use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.

the class ProducesRequestConditionTests method matchAndCompare.

// gh-22853
@Test
public void matchAndCompare() {
    RequestedContentTypeResolverBuilder builder = new RequestedContentTypeResolverBuilder();
    builder.headerResolver();
    builder.fixedResolver(MediaType.TEXT_HTML);
    RequestedContentTypeResolver resolver = builder.build();
    ProducesRequestCondition none = new ProducesRequestCondition(new String[0], null, resolver);
    ProducesRequestCondition html = new ProducesRequestCondition(new String[] { "text/html" }, null, resolver);
    MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", "*/*"));
    ProducesRequestCondition noneMatch = none.getMatchingCondition(exchange);
    ProducesRequestCondition htmlMatch = html.getMatchingCondition(exchange);
    assertThat(noneMatch.compareTo(htmlMatch, exchange)).isEqualTo(1);
}
Also used : MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) RequestedContentTypeResolver(org.springframework.web.reactive.accept.RequestedContentTypeResolver) RequestedContentTypeResolverBuilder(org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder) Test(org.junit.jupiter.api.Test)

Example 50 with MockServerWebExchange

use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.

the class ProducesRequestConditionTests method matchWithNegationAndMediaTypeAllWithQualityParameter.

// SPR-17550
@Test
public void matchWithNegationAndMediaTypeAllWithQualityParameter() {
    ProducesRequestCondition condition = new ProducesRequestCondition("!application/json");
    MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"));
    assertThat(condition.getMatchingCondition(exchange)).isNotNull();
}
Also used : MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) Test(org.junit.jupiter.api.Test)

Aggregations

MockServerWebExchange (org.springframework.web.testfixture.server.MockServerWebExchange)224 Test (org.junit.jupiter.api.Test)216 MockServerHttpRequest (org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest)61 ClassPathResource (org.springframework.core.io.ClassPathResource)26 HttpHeaders (org.springframework.http.HttpHeaders)25 Resource (org.springframework.core.io.Resource)24 HandlerResult (org.springframework.web.reactive.HandlerResult)23 MethodParameter (org.springframework.core.MethodParameter)22 MockServerHttpResponse (org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse)22 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)19 MediaType (org.springframework.http.MediaType)19 Mono (reactor.core.publisher.Mono)18 BeforeEach (org.junit.jupiter.api.BeforeEach)17 HttpMethod (org.springframework.http.HttpMethod)15 StepVerifier (reactor.test.StepVerifier)13 Arrays (java.util.Arrays)12 Collections (java.util.Collections)12 List (java.util.List)12 HttpStatus (org.springframework.http.HttpStatus)12 IOException (java.io.IOException)10