Search in sources :

Example 1 with MockServerWebExchange

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

the class HeadersRequestConditionTests method headerNotPresent.

@Test
public void headerNotPresent() {
    MockServerWebExchange exchange = MockServerWebExchange.from(get("/"));
    HeadersRequestCondition condition = new HeadersRequestCondition("!accept");
    assertThat(condition.getMatchingCondition(exchange)).isNotNull();
}
Also used : MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) Test(org.junit.jupiter.api.Test)

Example 2 with MockServerWebExchange

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

the class HeadersRequestConditionTests method headerValueMatchNegated.

@Test
public void headerValueMatchNegated() {
    MockServerWebExchange exchange = MockServerWebExchange.from(get("/").header("foo", "baz"));
    HeadersRequestCondition condition = new HeadersRequestCondition("foo!=bar");
    assertThat(condition.getMatchingCondition(exchange)).isNotNull();
}
Also used : MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) Test(org.junit.jupiter.api.Test)

Example 3 with MockServerWebExchange

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

the class PatternsRequestConditionTests method matchPatternContainsExtension.

@Test
public void matchPatternContainsExtension() {
    PatternsRequestCondition condition = createPatternsCondition("/foo.jpg");
    MockServerWebExchange exchange = MockServerWebExchange.from(get("/foo.html"));
    PatternsRequestCondition match = condition.getMatchingCondition(exchange);
    assertThat(match).isNull();
}
Also used : MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) Test(org.junit.jupiter.api.Test)

Example 4 with MockServerWebExchange

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

the class PatternsRequestConditionTests method matchTrailingSlash.

@Test
public void matchTrailingSlash() {
    MockServerWebExchange exchange = MockServerWebExchange.from(get("/foo/"));
    PatternsRequestCondition condition = createPatternsCondition("/foo");
    PatternsRequestCondition match = condition.getMatchingCondition(exchange);
    assertThat(match).isNotNull();
    assertThat(match.getPatterns().iterator().next().getPatternString()).as("Should match by default").isEqualTo("/foo");
    condition = createPatternsCondition("/foo");
    match = condition.getMatchingCondition(exchange);
    assertThat(match).isNotNull();
    assertThat(match.getPatterns().iterator().next().getPatternString()).as("Trailing slash should be insensitive to useSuffixPatternMatch settings (SPR-6164, SPR-5636)").isEqualTo("/foo");
    PathPatternParser parser = new PathPatternParser();
    parser.setMatchOptionalTrailingSeparator(false);
    condition = new PatternsRequestCondition(parser.parse("/foo"));
    match = condition.getMatchingCondition(MockServerWebExchange.from(get("/foo/")));
    assertThat(match).isNull();
}
Also used : PathPatternParser(org.springframework.web.util.pattern.PathPatternParser) MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) Test(org.junit.jupiter.api.Test)

Example 5 with MockServerWebExchange

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

the class PatternsRequestConditionTests method matchSortPatterns.

@Test
public void matchSortPatterns() {
    PatternsRequestCondition condition = createPatternsCondition("/*/*", "/foo/bar", "/foo/*");
    MockServerWebExchange exchange = MockServerWebExchange.from(get("/foo/bar"));
    PatternsRequestCondition match = condition.getMatchingCondition(exchange);
    PatternsRequestCondition expected = createPatternsCondition("/foo/bar", "/foo/*", "/*/*");
    assertThat(match).isEqualTo(expected);
}
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