use of org.springframework.web.testfixture.servlet.MockHttpServletRequest in project spring-framework by spring-projects.
the class RequestMappingInfoTests method matchProducesCondition.
@Test
void matchProducesCondition() {
MockHttpServletRequest request = PathPatternsTestUtils.initRequest("GET", "/foo", false);
request.addHeader("Accept", "text/plain");
RequestMappingInfo info = RequestMappingInfo.paths("/foo").produces("text/plain").build();
RequestMappingInfo match = info.getMatchingCondition(request);
assertThat(match).isNotNull();
info = RequestMappingInfo.paths("/foo").produces("application/xml").build();
match = info.getMatchingCondition(request);
assertThat(match).isNull();
}
use of org.springframework.web.testfixture.servlet.MockHttpServletRequest in project spring-framework by spring-projects.
the class RequestMappingInfoTests method preFlightRequest.
@Test
void preFlightRequest() {
MockHttpServletRequest request = PathPatternsTestUtils.initRequest("OPTIONS", "/foo", false);
request.addHeader(HttpHeaders.ORIGIN, "https://domain.com");
request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "POST");
RequestMappingInfo info = RequestMappingInfo.paths("/foo").methods(RequestMethod.POST).build();
RequestMappingInfo match = info.getMatchingCondition(request);
assertThat(match).isNotNull();
info = RequestMappingInfo.paths("/foo").methods(RequestMethod.OPTIONS).build();
match = info.getMatchingCondition(request);
assertThat(match).as("Pre-flight should match the ACCESS_CONTROL_REQUEST_METHOD").isNull();
}
use of org.springframework.web.testfixture.servlet.MockHttpServletRequest in project spring-framework by spring-projects.
the class PatternsRequestConditionTests method matchTrailingSlash.
@Test
void matchTrailingSlash() {
MockHttpServletRequest request = initRequest("/foo/");
PatternsRequestCondition condition = new PatternsRequestCondition("/foo");
PatternsRequestCondition match = condition.getMatchingCondition(request);
assertThat(match).isNotNull();
assertThat(match.getPatterns().iterator().next()).as("Should match by default").isEqualTo("/foo/");
condition = new PatternsRequestCondition(new String[] { "/foo" }, true, null);
match = condition.getMatchingCondition(request);
assertThat(match).isNotNull();
assertThat(match.getPatterns().iterator().next()).as("Trailing slash should be insensitive to useSuffixPatternMatch settings (SPR-6164, SPR-5636)").isEqualTo("/foo/");
condition = new PatternsRequestCondition(new String[] { "/foo" }, false, null);
match = condition.getMatchingCondition(request);
assertThat(match).isNull();
}
use of org.springframework.web.testfixture.servlet.MockHttpServletRequest in project spring-framework by spring-projects.
the class PatternsRequestConditionTests method matchSuffixPatternUsingFileExtensions2.
@Test
@SuppressWarnings("deprecation")
void matchSuffixPatternUsingFileExtensions2() {
PatternsRequestCondition condition1 = new PatternsRequestCondition(new String[] { "/prefix" }, null, null, true, false, Collections.singletonList("json"));
PatternsRequestCondition condition2 = new PatternsRequestCondition(new String[] { "/suffix" }, null, null, true, false, null);
PatternsRequestCondition combined = condition1.combine(condition2);
MockHttpServletRequest request = initRequest("/prefix/suffix.json");
PatternsRequestCondition match = combined.getMatchingCondition(request);
assertThat(match).isNotNull();
}
use of org.springframework.web.testfixture.servlet.MockHttpServletRequest in project spring-framework by spring-projects.
the class ProducesRequestConditionTests method matchNegatedWithoutAcceptHeader.
@Test
public void matchNegatedWithoutAcceptHeader() {
ProducesRequestCondition condition = new ProducesRequestCondition("!text/plain");
assertThat(condition.getMatchingCondition(new MockHttpServletRequest())).isNotNull();
assertThat(condition.getProducibleMediaTypes()).isEqualTo(Collections.emptySet());
}
Aggregations