use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest 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);
MockServerHttpRequest mockRequest = MockServerHttpRequest.get("https://localhost/resources/response.txt").build();
ServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), Collections.emptyList());
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.web.testfixture.http.server.reactive.MockServerHttpRequest 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);
MockServerHttpRequest mockRequest = MockServerHttpRequest.get("https://example.com").build();
ServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), Collections.emptyList());
Mono<Resource> result = function.apply(request);
StepVerifier.create(result).expectComplete().verify();
}
use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.
the class RequestPredicateTests method negate.
@Test
public void negate() {
RequestPredicate predicate = request -> false;
RequestPredicate negated = predicate.negate();
MockServerHttpRequest mockRequest = MockServerHttpRequest.get("https://example.com").build();
ServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), Collections.emptyList());
assertThat(negated.test(request)).isTrue();
predicate = r -> true;
negated = predicate.negate();
assertThat(negated.test(request)).isFalse();
}
use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.
the class RequestPredicateTests method or.
@Test
public void or() {
RequestPredicate predicate1 = request -> true;
RequestPredicate predicate2 = request -> false;
RequestPredicate predicate3 = request -> false;
MockServerHttpRequest mockRequest = MockServerHttpRequest.get("https://example.com").build();
ServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), Collections.emptyList());
assertThat(predicate1.or(predicate2).test(request)).isTrue();
assertThat(predicate2.or(predicate1).test(request)).isTrue();
assertThat(predicate2.or(predicate3).test(request)).isFalse();
}
use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.
the class DefaultServerResponseBuilderTests method buildVoidPublisher.
@Test
public void buildVoidPublisher() {
Mono<Void> mono = Mono.empty();
Mono<ServerResponse> result = ServerResponse.ok().build(mono);
MockServerHttpRequest request = MockServerHttpRequest.get("https://example.com").build();
MockServerWebExchange exchange = MockServerWebExchange.from(request);
result.flatMap(res -> res.writeTo(exchange, EMPTY_CONTEXT)).block();
MockServerHttpResponse response = exchange.getResponse();
StepVerifier.create(response.getBody()).expectComplete().verify();
}
Aggregations