Search in sources :

Example 36 with MockServerWebExchange

use of org.springframework.mock.http.server.reactive.test.MockServerWebExchange in project spring-framework by spring-projects.

the class PatternsRequestConditionTests method matchTrailingSlash.

@Test
public void matchTrailingSlash() throws Exception {
    MockServerWebExchange exchange = get("/foo/").toExchange();
    PatternsRequestCondition condition = new PatternsRequestCondition("/foo");
    PatternsRequestCondition match = condition.getMatchingCondition(exchange);
    assertNotNull(match);
    assertEquals("Should match by default", "/foo/", match.getPatterns().iterator().next());
    condition = new PatternsRequestCondition(new String[] { "/foo" }, null, null, false, true, null);
    match = condition.getMatchingCondition(exchange);
    assertNotNull(match);
    assertEquals("Trailing slash should be insensitive to useSuffixPatternMatch settings (SPR-6164, SPR-5636)", "/foo/", match.getPatterns().iterator().next());
    condition = new PatternsRequestCondition(new String[] { "/foo" }, null, null, false, false, null);
    match = condition.getMatchingCondition(exchange);
    assertNull(match);
}
Also used : MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) Test(org.junit.Test)

Example 37 with MockServerWebExchange

use of org.springframework.mock.http.server.reactive.test.MockServerWebExchange in project spring-framework by spring-projects.

the class PatternsRequestConditionTests method matchSuffixPatternUsingFileExtensions.

// SPR-8410
@Test
public void matchSuffixPatternUsingFileExtensions() throws Exception {
    String[] patterns = new String[] { "/jobs/{jobName}" };
    Set<String> extensions = Collections.singleton("json");
    PatternsRequestCondition condition = new PatternsRequestCondition(patterns, null, null, true, false, extensions);
    MockServerWebExchange exchange = get("/jobs/my.job").toExchange();
    PatternsRequestCondition match = condition.getMatchingCondition(exchange);
    assertNotNull(match);
    assertEquals("/jobs/{jobName}", match.getPatterns().iterator().next());
    exchange = get("/jobs/my.job.json").toExchange();
    match = condition.getMatchingCondition(exchange);
    assertNotNull(match);
    assertEquals("/jobs/{jobName}.json", match.getPatterns().iterator().next());
}
Also used : MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) Test(org.junit.Test)

Example 38 with MockServerWebExchange

use of org.springframework.mock.http.server.reactive.test.MockServerWebExchange in project spring-framework by spring-projects.

the class PatternsRequestConditionTests method matchSuffixPatternUsingFileExtensions2.

@Test
public void matchSuffixPatternUsingFileExtensions2() throws Exception {
    PatternsRequestCondition condition1 = new PatternsRequestCondition(new String[] { "/prefix" }, null, null, true, false, Collections.singleton("json"));
    PatternsRequestCondition condition2 = new PatternsRequestCondition(new String[] { "/suffix" }, null, null, true, false, null);
    PatternsRequestCondition combined = condition1.combine(condition2);
    MockServerWebExchange exchange = get("/prefix/suffix.json").toExchange();
    PatternsRequestCondition match = combined.getMatchingCondition(exchange);
    assertNotNull(match);
}
Also used : MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) Test(org.junit.Test)

Example 39 with MockServerWebExchange

use of org.springframework.mock.http.server.reactive.test.MockServerWebExchange in project spring-framework by spring-projects.

the class ProducesRequestConditionTests method compareToMediaTypeAll.

// SPR-8536
@Test
public void compareToMediaTypeAll() throws Exception {
    MockServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
    ProducesRequestCondition condition1 = new ProducesRequestCondition();
    ProducesRequestCondition condition2 = new ProducesRequestCondition("application/json");
    assertTrue("Should have picked '*/*' condition as an exact match", condition1.compareTo(condition2, exchange) < 0);
    assertTrue("Should have picked '*/*' condition as an exact match", condition2.compareTo(condition1, exchange) > 0);
    condition1 = new ProducesRequestCondition("*/*");
    condition2 = new ProducesRequestCondition("application/json");
    assertTrue(condition1.compareTo(condition2, exchange) < 0);
    assertTrue(condition2.compareTo(condition1, exchange) > 0);
    exchange = MockServerHttpRequest.get("/").header("Accept", "*/*").toExchange();
    condition1 = new ProducesRequestCondition();
    condition2 = new ProducesRequestCondition("application/json");
    assertTrue(condition1.compareTo(condition2, exchange) < 0);
    assertTrue(condition2.compareTo(condition1, exchange) > 0);
    condition1 = new ProducesRequestCondition("*/*");
    condition2 = new ProducesRequestCondition("application/json");
    assertTrue(condition1.compareTo(condition2, exchange) < 0);
    assertTrue(condition2.compareTo(condition1, exchange) > 0);
}
Also used : MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) Test(org.junit.Test)

Example 40 with MockServerWebExchange

use of org.springframework.mock.http.server.reactive.test.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");
    assertNull(condition.getMatchingCondition(exchange));
}
Also used : MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) Test(org.junit.Test)

Aggregations

MockServerWebExchange (org.springframework.mock.http.server.reactive.test.MockServerWebExchange)135 Test (org.junit.Test)127 ClassPathResource (org.springframework.core.io.ClassPathResource)19 Resource (org.springframework.core.io.Resource)19 HandlerResult (org.springframework.web.reactive.HandlerResult)17 MethodParameter (org.springframework.core.MethodParameter)15 MediaType (org.springframework.http.MediaType)8 Instant (java.time.Instant)7 HttpHeaders (org.springframework.http.HttpHeaders)5 MockServerHttpResponse (org.springframework.mock.http.server.reactive.test.MockServerHttpResponse)5 FileSystemResource (org.springframework.core.io.FileSystemResource)3 UrlResource (org.springframework.core.io.UrlResource)3 DataBuffer (org.springframework.core.io.buffer.DataBuffer)3 CompositeContentTypeResolver (org.springframework.web.reactive.accept.CompositeContentTypeResolver)3 RequestedContentTypeResolverBuilder (org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder)3 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2 Assert.assertSame (org.junit.Assert.assertSame)2 DefaultDataBufferFactory (org.springframework.core.io.buffer.DefaultDataBufferFactory)2