use of org.springframework.web.testfixture.servlet.MockHttpServletRequest in project spring-framework by spring-projects.
the class DefaultServerRequestTests method pathVariableNotFound.
@Test
void pathVariableNotFound() {
MockHttpServletRequest servletRequest = PathPatternsTestUtils.initRequest("GET", "/", true);
Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
servletRequest.setAttribute(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE, pathVariables);
DefaultServerRequest request = new DefaultServerRequest(servletRequest, this.messageConverters);
assertThatIllegalArgumentException().isThrownBy(() -> request.pathVariable("baz"));
}
use of org.springframework.web.testfixture.servlet.MockHttpServletRequest in project spring-framework by spring-projects.
the class DefaultServerRequestTests method checkNotModifiedWildcardIsIgnored.
@ParameterizedHttpMethodTest
void checkNotModifiedWildcardIsIgnored(String method) {
MockHttpServletRequest servletRequest = PathPatternsTestUtils.initRequest(method, "/", true);
String eTag = "\"Foo\"";
servletRequest.addHeader(HttpHeaders.IF_NONE_MATCH, "*");
DefaultServerRequest request = new DefaultServerRequest(servletRequest, this.messageConverters);
Optional<ServerResponse> result = request.checkNotModified(eTag);
assertThat(result).isEmpty();
}
use of org.springframework.web.testfixture.servlet.MockHttpServletRequest in project spring-framework by spring-projects.
the class DefaultServerRequestTests method checkNotModifiedETagWithSeparatorChars.
@ParameterizedHttpMethodTest
void checkNotModifiedETagWithSeparatorChars(String method) {
MockHttpServletRequest servletRequest = PathPatternsTestUtils.initRequest(method, "/", true);
String eTag = "\"Foo, Bar\"";
servletRequest.addHeader(HttpHeaders.IF_NONE_MATCH, eTag);
DefaultServerRequest request = new DefaultServerRequest(servletRequest, this.messageConverters);
Optional<ServerResponse> result = request.checkNotModified(eTag);
assertThat(result).hasValueSatisfying(serverResponse -> {
assertThat(serverResponse.statusCode()).isEqualTo(HttpStatus.NOT_MODIFIED);
assertThat(serverResponse.headers().getETag()).isEqualTo(eTag);
});
}
use of org.springframework.web.testfixture.servlet.MockHttpServletRequest in project spring-framework by spring-projects.
the class DefaultServerRequestTests method cookies.
@Test
void cookies() {
Cookie cookie = new Cookie("foo", "bar");
MockHttpServletRequest servletRequest = PathPatternsTestUtils.initRequest("GET", "/", true);
servletRequest.setCookies(cookie);
DefaultServerRequest request = new DefaultServerRequest(servletRequest, this.messageConverters);
MultiValueMap<String, Cookie> expected = new LinkedMultiValueMap<>();
expected.add("foo", cookie);
assertThat(request.cookies()).isEqualTo(expected);
}
use of org.springframework.web.testfixture.servlet.MockHttpServletRequest in project spring-framework by spring-projects.
the class DefaultServerRequestTests method method.
@Test
void method() {
MockHttpServletRequest servletRequest = PathPatternsTestUtils.initRequest("HEAD", "/", true);
DefaultServerRequest request = new DefaultServerRequest(servletRequest, this.messageConverters);
assertThat(request.method()).isEqualTo(HttpMethod.HEAD);
}
Aggregations