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);
}
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());
}
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);
}
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);
}
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));
}
Aggregations