use of org.springframework.mock.http.server.reactive.test.MockServerWebExchange in project spring-framework by spring-projects.
the class ResourceHandlerFunctionTests method head.
@Test
public void head() throws IOException {
MockServerWebExchange exchange = MockServerHttpRequest.head("http://localhost").toExchange();
MockServerHttpResponse mockResponse = exchange.getResponse();
ServerRequest request = new DefaultServerRequest(exchange, HandlerStrategies.withDefaults());
Mono<ServerResponse> response = this.handlerFunction.handle(request);
Mono<Void> result = response.then(res -> {
assertEquals(HttpStatus.OK, res.statusCode());
return res.writeTo(exchange, HandlerStrategies.withDefaults());
});
StepVerifier.create(result).expectComplete().verify();
StepVerifier.create(result).expectComplete().verify();
StepVerifier.create(mockResponse.getBody()).expectComplete().verify();
assertEquals(MediaType.TEXT_PLAIN, mockResponse.getHeaders().getContentType());
assertEquals(this.resource.contentLength(), mockResponse.getHeaders().getContentLength());
}
use of org.springframework.mock.http.server.reactive.test.MockServerWebExchange in project spring-framework by spring-projects.
the class ResourceHandlerFunctionTests method options.
@Test
public void options() {
MockServerWebExchange exchange = MockServerHttpRequest.options("http://localhost").toExchange();
MockServerHttpResponse mockResponse = exchange.getResponse();
ServerRequest request = new DefaultServerRequest(exchange, HandlerStrategies.withDefaults());
Mono<ServerResponse> responseMono = this.handlerFunction.handle(request);
Mono<Void> result = responseMono.then(response -> {
assertEquals(HttpStatus.OK, response.statusCode());
assertEquals(EnumSet.of(HttpMethod.GET, HttpMethod.HEAD, HttpMethod.OPTIONS), response.headers().getAllow());
return response.writeTo(exchange, HandlerStrategies.withDefaults());
});
StepVerifier.create(result).expectComplete().verify();
assertEquals(HttpStatus.OK, mockResponse.getStatusCode());
assertEquals(EnumSet.of(HttpMethod.GET, HttpMethod.HEAD, HttpMethod.OPTIONS), mockResponse.getHeaders().getAllow());
StepVerifier.create(mockResponse.getBody()).expectComplete().verify();
}
use of org.springframework.mock.http.server.reactive.test.MockServerWebExchange in project spring-framework by spring-projects.
the class CssLinkResourceTransformerTests method transformWithNonCssResource.
@Test
public void transformWithNonCssResource() throws Exception {
MockServerWebExchange exchange = MockServerHttpRequest.get("/static/images/image.png").toExchange();
Resource expected = new ClassPathResource("test/images/image.png", getClass());
StepVerifier.create(this.transformerChain.transform(exchange, expected)).expectNext(expected).expectComplete().verify();
}
use of org.springframework.mock.http.server.reactive.test.MockServerWebExchange in project spring-framework by spring-projects.
the class CssLinkResourceTransformerTests method transformWithGzippedResource.
@Test
public void transformWithGzippedResource() throws Exception {
MockServerWebExchange exchange = MockServerHttpRequest.get("/static/main.css").toExchange();
Resource original = new ClassPathResource("test/main.css", getClass());
createTempCopy("main.css", "main.css.gz");
GzipResourceResolver.GzippedResource expected = new GzipResourceResolver.GzippedResource(original);
StepVerifier.create(this.transformerChain.transform(exchange, expected)).expectNext(expected).expectComplete().verify();
}
use of org.springframework.mock.http.server.reactive.test.MockServerWebExchange in project spring-framework by spring-projects.
the class GzipResourceResolverTests method resolveFromCacheWithEncodingVariants.
@Test
public void resolveFromCacheWithEncodingVariants() throws IOException {
MockServerWebExchange exchange = MockServerHttpRequest.get("").header("Accept-Encoding", "gzip").toExchange();
String file = "js/foo.js";
Resource resolved = this.resolver.resolveResource(exchange, file, this.locations).block(TIMEOUT);
String gzFile = file + ".gz";
Resource gzResource = new ClassPathResource("test/" + gzFile, getClass());
assertEquals(gzResource.getDescription(), resolved.getDescription());
assertEquals(new ClassPathResource("test/" + file).getFilename(), resolved.getFilename());
assertTrue("Expected " + resolved + " to be of type " + HttpResource.class, resolved instanceof HttpResource);
// resolved resource is now cached in CachingResourceResolver
exchange = MockServerHttpRequest.get("/js/foo.js").toExchange();
resolved = this.resolver.resolveResource(exchange, file, this.locations).block(TIMEOUT);
Resource resource = new ClassPathResource("test/" + file, getClass());
assertEquals(resource.getDescription(), resolved.getDescription());
assertEquals(new ClassPathResource("test/" + file).getFilename(), resolved.getFilename());
assertFalse("Expected " + resolved + " to *not* be of type " + HttpResource.class, resolved instanceof HttpResource);
}
Aggregations