use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.
the class DefaultServerWebExchangeCheckNotModifiedTests method checkModifiedETagAndNotModifiedTimestamp.
@Test
void checkModifiedETagAndNotModifiedTimestamp() throws Exception {
String currentETag = "\"Foo\"";
String oldEtag = "\"Bar\"";
long time = currentDate.toEpochMilli();
MockServerHttpRequest request = get("/").ifNoneMatch(oldEtag).ifModifiedSince(time).build();
MockServerWebExchange exchange = MockServerWebExchange.from(request);
assertThat(exchange.checkNotModified(currentETag, currentDate)).isFalse();
assertThat(exchange.getResponse().getStatusCode()).isNull();
assertThat(exchange.getResponse().getHeaders().getETag()).isEqualTo(currentETag);
assertThat(exchange.getResponse().getHeaders().getLastModified()).isEqualTo(time);
}
use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.
the class DefaultServerWebExchangeCheckNotModifiedTests method checkNotModifiedTimestampConditionalPutConflict.
@Test
void checkNotModifiedTimestampConditionalPutConflict() throws Exception {
Instant oneMinuteAgo = currentDate.minusSeconds(60);
long millis = oneMinuteAgo.toEpochMilli();
MockServerHttpRequest request = MockServerHttpRequest.put("/").ifUnmodifiedSince(millis).build();
MockServerWebExchange exchange = MockServerWebExchange.from(request);
assertThat(exchange.checkNotModified(currentDate)).isTrue();
assertThat(exchange.getResponse().getStatusCode().value()).isEqualTo(412);
assertThat(exchange.getResponse().getHeaders().getLastModified()).isEqualTo(-1);
}
use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.
the class DefaultServerWebExchangeCheckNotModifiedTests method checkModifiedTimestampWithLengthPart.
@Test
void checkModifiedTimestampWithLengthPart() throws Exception {
long epochTime = dateFormat.parse(CURRENT_TIME).getTime();
String header = "Tue, 08 Apr 2014 09:57:42 GMT; length=13774";
MockServerHttpRequest request = get("/").header("If-Modified-Since", header).build();
MockServerWebExchange exchange = MockServerWebExchange.from(request);
assertThat(exchange.checkNotModified(Instant.ofEpochMilli(epochTime))).isFalse();
assertThat(exchange.getResponse().getStatusCode()).isNull();
assertThat(exchange.getResponse().getHeaders().getLastModified()).isEqualTo(epochTime);
}
use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.
the class DefaultServerWebExchangeCheckNotModifiedTests method checkNotModifiedTimestamp.
@Test
void checkNotModifiedTimestamp() throws Exception {
MockServerHttpRequest request = get("/").ifModifiedSince(currentDate.toEpochMilli()).build();
MockServerWebExchange exchange = MockServerWebExchange.from(request);
assertThat(exchange.checkNotModified(currentDate)).isTrue();
assertThat(exchange.getResponse().getStatusCode().value()).isEqualTo(304);
assertThat(exchange.getResponse().getHeaders().getLastModified()).isEqualTo(currentDate.toEpochMilli());
}
use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.
the class DefaultServerWebExchangeCheckNotModifiedTests method checkNotModifiedTimestampWithLengthPart.
@Test
void checkNotModifiedTimestampWithLengthPart() throws Exception {
long epochTime = dateFormat.parse(CURRENT_TIME).getTime();
String header = "Wed, 09 Apr 2014 09:57:42 GMT; length=13774";
MockServerHttpRequest request = get("/").header("If-Modified-Since", header).build();
MockServerWebExchange exchange = MockServerWebExchange.from(request);
assertThat(exchange.checkNotModified(Instant.ofEpochMilli(epochTime))).isTrue();
assertThat(exchange.getResponse().getStatusCode().value()).isEqualTo(304);
assertThat(exchange.getResponse().getHeaders().getLastModified()).isEqualTo(epochTime);
}
Aggregations