use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.
the class DefaultServerResponseBuilderTests method overwriteHeaders.
@Test
public void overwriteHeaders() {
ServerResponse serverResponse = ServerResponse.ok().headers(headers -> headers.set("Foo", "Bar")).build().block();
assertThat(serverResponse).isNotNull();
MockServerWebExchange mockExchange = MockServerWebExchange.builder(MockServerHttpRequest.get("https://example.org")).build();
MockServerHttpResponse response = mockExchange.getResponse();
response.getHeaders().set("Foo", "Baz");
serverResponse.writeTo(mockExchange, EMPTY_CONTEXT).block();
assertThat(response.getHeaders().getFirst("Foo")).isEqualTo("Bar");
}
use of org.springframework.web.testfixture.server.MockServerWebExchange 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();
}
use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.
the class DefaultServerResponseBuilderTests method notModifiedEtag.
@Test
public void notModifiedEtag() {
String etag = "\"foo\"";
ServerResponse responseMono = ServerResponse.ok().eTag(etag).bodyValue("bar").block();
MockServerHttpRequest request = MockServerHttpRequest.get("https://example.com").header(HttpHeaders.IF_NONE_MATCH, etag).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.server.MockServerWebExchange in project spring-framework by spring-projects.
the class RequestPredicatesTests method all.
@Test
public void all() {
MockServerHttpRequest mockRequest = MockServerHttpRequest.get("https://example.com").build();
MockServerWebExchange mockExchange = MockServerWebExchange.from(mockRequest);
RequestPredicate predicate = RequestPredicates.all();
ServerRequest request = new DefaultServerRequest(mockExchange, Collections.emptyList());
assertThat(predicate.test(request)).isTrue();
}
use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.
the class CachingResourceResolverTests method resolveResourceNoAcceptEncoding.
@Test
public void resolveResourceNoAcceptEncoding() {
String file = "bar.css";
MockServerWebExchange exchange = MockServerWebExchange.from(get(file));
Resource expected = this.chain.resolveResource(exchange, file, this.locations).block(TIMEOUT);
String cacheKey = resourceKey(file);
Object actual = this.cache.get(cacheKey).get();
assertThat(actual).isEqualTo(expected);
}
Aggregations