use of org.springframework.mock.http.server.reactive.test.MockServerHttpRequest in project spring-framework by spring-projects.
the class FormHttpMessageReaderTests method readFormAsFlux.
@Test
public void readFormAsFlux() {
String body = "name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3";
MockServerHttpRequest request = request(body);
MultiValueMap<String, String> result = this.reader.read(null, request, null).single().block();
assertEquals("Invalid result", 3, result.size());
assertEquals("Invalid result", "value 1", result.getFirst("name 1"));
List<String> values = result.get("name 2");
assertEquals("Invalid result", 2, values.size());
assertEquals("Invalid result", "value 2+1", values.get(0));
assertEquals("Invalid result", "value 2+2", values.get(1));
assertNull("Invalid result", result.getFirst("name 3"));
}
use of org.springframework.mock.http.server.reactive.test.MockServerHttpRequest in project spring-framework by spring-projects.
the class ResourceHttpMessageWriterTests method shouldSetRangeNotSatisfiableStatus.
@Test
public void shouldSetRangeNotSatisfiableStatus() throws Exception {
MockServerHttpRequest request = get("/").header(HttpHeaders.RANGE, "invalid").build();
testWrite(request);
assertThat(this.response.getHeaders().getFirst(HttpHeaders.ACCEPT_RANGES), is("bytes"));
assertThat(this.response.getStatusCode(), is(HttpStatus.REQUESTED_RANGE_NOT_SATISFIABLE));
}
use of org.springframework.mock.http.server.reactive.test.MockServerHttpRequest in project spring-framework by spring-projects.
the class ServerSentEventHttpMessageReaderTests method readServerSentEvents.
@Test
public void readServerSentEvents() {
MockServerHttpRequest request = MockServerHttpRequest.post("/").body("id:c42\nevent:foo\nretry:123\n:bla\n:bla bla\n:bla bla bla\ndata:bar\n\n" + "id:c43\nevent:bar\nretry:456\ndata:baz\n\n");
Flux<ServerSentEvent> events = this.messageReader.read(ResolvableType.forClassWithGenerics(ServerSentEvent.class, String.class), request, Collections.emptyMap()).cast(ServerSentEvent.class);
StepVerifier.create(events).consumeNextWith(event -> {
assertEquals("c42", event.id().get());
assertEquals("foo", event.event().get());
assertEquals(Duration.ofMillis(123), event.retry().get());
assertEquals("bla\nbla bla\nbla bla bla", event.comment().get());
assertEquals("bar", event.data().get());
}).consumeNextWith(event -> {
assertEquals("c43", event.id().get());
assertEquals("bar", event.event().get());
assertEquals(Duration.ofMillis(456), event.retry().get());
assertFalse(event.comment().isPresent());
assertEquals("baz", event.data().get());
}).expectComplete().verify();
}
use of org.springframework.mock.http.server.reactive.test.MockServerHttpRequest in project spring-framework by spring-projects.
the class CorsUtilsTests method isNotPreFlightRequest.
@Test
public void isNotPreFlightRequest() {
MockServerHttpRequest request = get("/").build();
assertFalse(CorsUtils.isPreFlightRequest(request));
request = options("/").header(HttpHeaders.ORIGIN, "http://domain.com").build();
assertFalse(CorsUtils.isPreFlightRequest(request));
request = options("/").header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET").build();
assertFalse(CorsUtils.isPreFlightRequest(request));
}
use of org.springframework.mock.http.server.reactive.test.MockServerHttpRequest in project spring-framework by spring-projects.
the class WebHttpHandlerBuilderTests method orderedWebFilterBeans.
// SPR-15074
@Test
public void orderedWebFilterBeans() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(OrderedWebFilterBeanConfig.class);
context.refresh();
HttpHandler httpHandler = WebHttpHandlerBuilder.applicationContext(context).build();
MockServerHttpRequest request = MockServerHttpRequest.get("/").build();
MockServerHttpResponse response = new MockServerHttpResponse();
httpHandler.handle(request, response).blockMillis(5000);
assertEquals("FilterB::FilterA", response.getBodyAsString().blockMillis(5000));
}
Aggregations