use of org.springframework.core.io.Resource in project spring-framework by spring-projects.
the class BodyInsertersTests method ofResource.
@Test
public void ofResource() throws Exception {
Resource body = new ClassPathResource("response.txt", getClass());
BodyInserter<Resource, ReactiveHttpOutputMessage> inserter = BodyInserters.fromResource(body);
MockServerHttpResponse response = new MockServerHttpResponse();
Mono<Void> result = inserter.insert(response, this.context);
StepVerifier.create(result).expectComplete().verify();
byte[] expectedBytes = Files.readAllBytes(body.getFile().toPath());
StepVerifier.create(response.getBody()).consumeNextWith(dataBuffer -> {
byte[] resultBytes = new byte[dataBuffer.readableByteCount()];
dataBuffer.read(resultBytes);
assertArrayEquals(expectedBytes, resultBytes);
}).expectComplete().verify();
}
use of org.springframework.core.io.Resource in project spring-framework by spring-projects.
the class PathResourceLookupFunctionTests method normal.
@Test
public void normal() throws Exception {
ClassPathResource location = new ClassPathResource("org/springframework/web/reactive/function/server/");
PathResourceLookupFunction function = new PathResourceLookupFunction("/resources/**", location);
MockServerRequest request = MockServerRequest.builder().uri(new URI("http://localhost/resources/response.txt")).build();
Mono<Resource> result = function.apply(request);
File expected = new ClassPathResource("response.txt", getClass()).getFile();
StepVerifier.create(result).expectNextMatches(resource -> {
try {
return expected.equals(resource.getFile());
} catch (IOException ex) {
return false;
}
}).expectComplete().verify();
}
use of org.springframework.core.io.Resource in project spring-framework by spring-projects.
the class PathResourceLookupFunctionTests method notFound.
@Test
public void notFound() throws Exception {
ClassPathResource location = new ClassPathResource("org/springframework/web/reactive/function/server/");
PathResourceLookupFunction function = new PathResourceLookupFunction("/resources/**", location);
MockServerRequest request = MockServerRequest.builder().uri(new URI("http://localhost/resources/foo")).build();
Mono<Resource> result = function.apply(request);
StepVerifier.create(result).expectComplete().verify();
}
use of org.springframework.core.io.Resource 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.core.io.Resource 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();
}
Aggregations