use of org.springframework.web.testfixture.servlet.MockHttpServletRequest in project spring-framework by spring-projects.
the class DefaultServerRequestTests method checkNotModifiedUnpaddedETag.
@ParameterizedHttpMethodTest
void checkNotModifiedUnpaddedETag(String method) {
MockHttpServletRequest servletRequest = PathPatternsTestUtils.initRequest(method, "/", true);
String eTag = "Foo";
String paddedEtag = String.format("\"%s\"", eTag);
servletRequest.addHeader(HttpHeaders.IF_NONE_MATCH, paddedEtag);
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(paddedEtag);
});
}
use of org.springframework.web.testfixture.servlet.MockHttpServletRequest in project spring-framework by spring-projects.
the class DefaultServerRequestTests method checkNotModifiedETagAndModifiedTimestamp.
@ParameterizedHttpMethodTest
void checkNotModifiedETagAndModifiedTimestamp(String method) {
MockHttpServletRequest servletRequest = PathPatternsTestUtils.initRequest(method, "/", true);
String eTag = "\"Foo\"";
Instant now = Instant.now().truncatedTo(ChronoUnit.SECONDS);
Instant oneMinuteAgo = now.minus(1, ChronoUnit.MINUTES);
servletRequest.addHeader(HttpHeaders.IF_NONE_MATCH, eTag);
servletRequest.addHeader(HttpHeaders.IF_MODIFIED_SINCE, oneMinuteAgo.toEpochMilli());
DefaultServerRequest request = new DefaultServerRequest(servletRequest, this.messageConverters);
Optional<ServerResponse> result = request.checkNotModified(now, eTag);
assertThat(result).hasValueSatisfying(serverResponse -> {
assertThat(serverResponse.statusCode()).isEqualTo(HttpStatus.NOT_MODIFIED);
assertThat(serverResponse.headers().getETag()).isEqualTo(eTag);
assertThat(serverResponse.headers().getLastModified()).isEqualTo(now.toEpochMilli());
});
}
use of org.springframework.web.testfixture.servlet.MockHttpServletRequest in project spring-framework by spring-projects.
the class DefaultServerRequestTests method absentQueryParam.
@Test
void absentQueryParam() {
MockHttpServletRequest servletRequest = PathPatternsTestUtils.initRequest("GET", "/", true);
servletRequest.setParameter("foo", "");
DefaultServerRequest request = new DefaultServerRequest(servletRequest, this.messageConverters);
assertThat(request.param("bar")).isEqualTo(Optional.empty());
}
use of org.springframework.web.testfixture.servlet.MockHttpServletRequest in project spring-framework by spring-projects.
the class DefaultServerRequestTests method principal.
@Test
void principal() {
MockHttpServletRequest servletRequest = PathPatternsTestUtils.initRequest("GET", "/", true);
Principal principal = () -> "foo";
servletRequest.setUserPrincipal(principal);
DefaultServerRequest request = new DefaultServerRequest(servletRequest, this.messageConverters);
assertThat(request.principal().get()).isEqualTo(principal);
}
use of org.springframework.web.testfixture.servlet.MockHttpServletRequest in project spring-framework by spring-projects.
the class DefaultServerRequestTests method checkNotModifiedETag.
@ParameterizedHttpMethodTest
void checkNotModifiedETag(String method) {
MockHttpServletRequest servletRequest = PathPatternsTestUtils.initRequest(method, "/", true);
String eTag = "\"Foo\"";
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);
});
}
Aggregations