use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.
the class DefaultServerResponseBuilderTests method notModifiedLastModified.
@Test
public void notModifiedLastModified() {
ZonedDateTime now = ZonedDateTime.now();
ZonedDateTime oneMinuteBeforeNow = now.minus(1, ChronoUnit.MINUTES);
ServerResponse responseMono = ServerResponse.ok().lastModified(oneMinuteBeforeNow).bodyValue("bar").block();
MockServerHttpRequest request = MockServerHttpRequest.get("https://example.com").header(HttpHeaders.IF_MODIFIED_SINCE, DateTimeFormatter.RFC_1123_DATE_TIME.format(now)).build();
MockServerWebExchange exchange = MockServerWebExchange.from(request);
responseMono.writeTo(exchange, EMPTY_CONTEXT);
MockServerHttpResponse response = exchange.getResponse();
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_MODIFIED);
StepVerifier.create(response.getBody()).expectError(IllegalStateException.class).verify();
}
use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.
the class DefaultServerRequestTests method checkModifiedTimestamp.
@ParameterizedHttpMethodTest
void checkModifiedTimestamp(String method) {
Instant now = Instant.now().truncatedTo(ChronoUnit.SECONDS);
Instant oneMinuteAgo = now.minus(1, ChronoUnit.MINUTES);
HttpHeaders headers = new HttpHeaders();
headers.setIfModifiedSince(oneMinuteAgo);
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.valueOf(method), "/").headers(headers).build();
DefaultServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), Collections.emptyList());
Mono<ServerResponse> result = request.checkNotModified(now);
StepVerifier.create(result).verifyComplete();
}
use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.
the class DefaultServerRequestTests method body.
@Test
public void body() {
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
Flux<DataBuffer> body = Flux.just(dataBuffer);
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.TEXT_PLAIN);
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.GET, "https://example.com?foo=bar").headers(httpHeaders).body(body);
DefaultServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), messageReaders);
Mono<String> resultMono = request.body(toMono(String.class));
assertThat(resultMono.block()).isEqualTo("foo");
}
use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.
the class DefaultServerRequestTests method checkModifiedUnpaddedETag.
@ParameterizedHttpMethodTest
void checkModifiedUnpaddedETag(String method) {
String currentETag = "Foo";
String oldEtag = "Bar";
HttpHeaders headers = new HttpHeaders();
headers.setIfNoneMatch(oldEtag);
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.valueOf(method), "/").headers(headers).build();
DefaultServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), Collections.emptyList());
Mono<ServerResponse> result = request.checkNotModified(currentETag);
StepVerifier.create(result).verifyComplete();
}
use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.
the class DefaultServerRequestTests method checkNotModifiedTimestamp.
@ParameterizedHttpMethodTest
void checkNotModifiedTimestamp(String method) throws Exception {
Instant now = Instant.now().truncatedTo(ChronoUnit.SECONDS);
HttpHeaders headers = new HttpHeaders();
headers.setIfModifiedSince(now);
MockServerHttpRequest mockRequest = MockServerHttpRequest.method(HttpMethod.valueOf(method), "/").headers(headers).build();
DefaultServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), Collections.emptyList());
Mono<ServerResponse> result = request.checkNotModified(now);
StepVerifier.create(result).assertNext(serverResponse -> {
assertThat(serverResponse.statusCode()).isEqualTo(HttpStatus.NOT_MODIFIED);
assertThat(serverResponse.headers().getLastModified()).isEqualTo(now.toEpochMilli());
}).verifyComplete();
}
Aggregations