use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.
the class DefaultServerRequestTests method checkNotModifiedETagAndTimestamp.
@ParameterizedHttpMethodTest
void checkNotModifiedETagAndTimestamp(String method) {
String eTag = "\"Foo\"";
Instant now = Instant.now().truncatedTo(ChronoUnit.SECONDS);
HttpHeaders headers = new HttpHeaders();
headers.setIfNoneMatch(eTag);
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, eTag);
StepVerifier.create(result).assertNext(serverResponse -> {
assertThat(serverResponse.statusCode()).isEqualTo(HttpStatus.NOT_MODIFIED);
assertThat(serverResponse.headers().getETag()).isEqualTo(eTag);
assertThat(serverResponse.headers().getLastModified()).isEqualTo(now.toEpochMilli());
}).verifyComplete();
}
use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.
the class DefaultServerRequestTests method checkModifiedETag.
@ParameterizedHttpMethodTest
void checkModifiedETag(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 bodyUnacceptable.
@Test
public void bodyUnacceptable() {
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), Collections.emptyList());
Flux<String> resultFlux = request.bodyToFlux(String.class);
StepVerifier.create(resultFlux).expectError(UnsupportedMediaTypeStatusException.class).verify();
}
use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.
the class RequestPredicatesTests method pathWithContext.
@Test
public void pathWithContext() {
RequestPredicate predicate = RequestPredicates.path("/p*");
MockServerHttpRequest mockRequest = MockServerHttpRequest.get("https://localhost/context/path").contextPath("/context").build();
ServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), Collections.emptyList());
assertThat(predicate.test(request)).isTrue();
}
use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.
the class RequestPredicatesTests method methods.
@Test
public void methods() {
RequestPredicate predicate = RequestPredicates.methods(HttpMethod.GET, HttpMethod.HEAD);
MockServerHttpRequest mockRequest = MockServerHttpRequest.get("https://example.com").build();
ServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), Collections.emptyList());
assertThat(predicate.test(request)).isTrue();
mockRequest = MockServerHttpRequest.head("https://example.com").build();
request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), Collections.emptyList());
assertThat(predicate.test(request)).isTrue();
mockRequest = MockServerHttpRequest.post("https://example.com").build();
request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), Collections.emptyList());
assertThat(predicate.test(request)).isFalse();
}
Aggregations