use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.
the class ServerSentEventHttpMessageReaderTests method readError.
@Test
public void readError() {
Flux<DataBuffer> body = Flux.just(stringBuffer("data:foo\ndata:bar\n\ndata:baz\n\n")).concatWith(Flux.error(new RuntimeException()));
MockServerHttpRequest request = MockServerHttpRequest.post("/").body(body);
Flux<String> data = reader.read(ResolvableType.forClass(String.class), request, Collections.emptyMap()).cast(String.class);
StepVerifier.create(data).expectNextMatches(elem -> elem.equals("foo\nbar")).expectNextMatches(elem -> elem.equals("baz")).expectError().verify();
}
use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.
the class FormHttpMessageReaderTests method readFormError.
@Test
public void readFormError() {
DataBuffer fooBuffer = stringBuffer("name=value");
Flux<DataBuffer> body = Flux.just(fooBuffer).concatWith(Flux.error(new RuntimeException()));
MockServerHttpRequest request = request(body);
Flux<MultiValueMap<String, String>> result = this.reader.read(null, request, null);
StepVerifier.create(result).expectError().verify();
}
use of org.springframework.web.testfixture.http.server.reactive.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();
assertThat(result.size()).as("Invalid result").isEqualTo(3);
assertThat(result.getFirst("name 1")).as("Invalid result").isEqualTo("value 1");
List<String> values = result.get("name 2");
assertThat(values.size()).as("Invalid result").isEqualTo(2);
assertThat(values.get(0)).as("Invalid result").isEqualTo("value 2+1");
assertThat(values.get(1)).as("Invalid result").isEqualTo("value 2+2");
assertThat(result.getFirst("name 3")).as("Invalid result").isNull();
}
use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.
the class ServerSentEventHttpMessageReaderTests method readServerSentEvents.
@Test
@SuppressWarnings("rawtypes")
public void readServerSentEvents() {
MockServerHttpRequest request = MockServerHttpRequest.post("/").body(Mono.just(stringBuffer("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\ndata:\n\ndata: \n\n")));
Flux<ServerSentEvent> events = this.reader.read(ResolvableType.forClassWithGenerics(ServerSentEvent.class, String.class), request, Collections.emptyMap()).cast(ServerSentEvent.class);
StepVerifier.create(events).consumeNextWith(event -> {
assertThat(event.id()).isEqualTo("c42");
assertThat(event.event()).isEqualTo("foo");
assertThat(event.retry()).isEqualTo(Duration.ofMillis(123));
assertThat(event.comment()).isEqualTo("bla\nbla bla\nbla bla bla");
assertThat(event.data()).isEqualTo("bar");
}).consumeNextWith(event -> {
assertThat(event.id()).isEqualTo("c43");
assertThat(event.event()).isEqualTo("bar");
assertThat(event.retry()).isEqualTo(Duration.ofMillis(456));
assertThat(event.comment()).isNull();
assertThat(event.data()).isEqualTo("baz");
}).consumeNextWith(event -> assertThat(event.data()).isNull()).consumeNextWith(event -> assertThat(event.data()).isNull()).expectComplete().verify();
}
use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest in project spring-framework by spring-projects.
the class RequestHeaderMethodArgumentResolverTests method resolveNameFromSystemPropertyThroughPlaceholder.
@Test
public void resolveNameFromSystemPropertyThroughPlaceholder() {
String expected = "foo";
MockServerHttpRequest request = MockServerHttpRequest.get("/").header("bar", expected).build();
ServerWebExchange exchange = MockServerWebExchange.from(request);
System.setProperty("systemProperty", "bar");
try {
Mono<Object> mono = this.resolver.resolveArgument(this.paramResolvedNameWithPlaceholder, this.bindingContext, exchange);
Object result = mono.block();
boolean condition = result instanceof String;
assertThat(condition).isTrue();
assertThat(result).isEqualTo(expected);
} finally {
System.clearProperty("systemProperty");
}
}
Aggregations