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();
}
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();
}
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();
}
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);
}
use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.
the class ResponseEntityResultHandlerTests method handleWithProducibleContentTypeShouldFailWithServerError.
// gh-23287
@Test
public void handleWithProducibleContentTypeShouldFailWithServerError() {
ResponseEntity<String> value = ResponseEntity.ok().body("<foo/>");
MethodParameter returnType = on(TestController.class).resolveReturnType(entity(String.class));
HandlerResult result = handlerResult(value, returnType);
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path"));
Set<MediaType> mediaTypes = Collections.singleton(MediaType.APPLICATION_XML);
exchange.getAttributes().put(PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, mediaTypes);
ResponseEntityResultHandler resultHandler = new ResponseEntityResultHandler(Collections.singletonList(new EncoderHttpMessageWriter<>(CharSequenceEncoder.textPlainOnly())), new RequestedContentTypeResolverBuilder().build());
StepVerifier.create(resultHandler.handleResult(exchange, result)).consumeErrorWith(ex -> assertThat(ex).isInstanceOf(HttpMessageNotWritableException.class).hasMessageContaining("with preset Content-Type")).verify();
}
Aggregations