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 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();
}
Aggregations