private void testWrite(MockServerHttpRequest request) { Mono<Void> mono = this.writer.write(this.input, null, null, TEXT_PLAIN, request, this.response, HINTS); StepVerifier.create(mono).expectComplete().verify(); }
private void assertHandlerResultValue(Mono<HandlerResult> mono, String expected) { StepVerifier.create(mono) .consumeNextWith(result -> assertEquals(expected, result.getReturnValue())) .expectComplete() .verify(); }
@Test public void nullIfNotRequired() throws Exception { BindingContext bindingContext = new BindingContext(); Mono<Object> mono = this.resolver.resolveArgument(this.paramNotRequired, bindingContext, this.exchange); StepVerifier.create(mono) .expectNextCount(0) .expectComplete() .verify(); }
@Test public void handleMissingValue() throws Exception { BindingContext bindingContext = new BindingContext(); Mono<Object> mono = this.resolver.resolveArgument(this.paramNamedString, bindingContext, this.exchange); StepVerifier.create(mono) .expectNextCount(0) .expectError(ServerErrorException.class) .verify(); }
@Test public void noContent() { Mono<ServerResponse> result = ServerResponse.noContent().build(); StepVerifier.create(result) .expectNextMatches(response -> HttpStatus.NO_CONTENT.equals(response.statusCode())) .expectComplete() .verify(); }
@Override public void decode() { Flux<DataBuffer> input = Flux.just(this.pojo1, this.pojo2) .map(this::writeObject) .flatMap(this::dataBuffer); testDecodeAll(input, Pojo.class, step -> step .expectNext(pojo1) .expectNext(pojo2) .verifyComplete()); }
@Override @Test public void decodeToMono() { Flux<DataBuffer> input = Flux.just( stringBuffer("foo"), stringBuffer("bar"), stringBuffer("baz")); testDecodeToMonoAll(input, String.class, step -> step .expectNext("foobarbaz") .expectComplete() .verify()); }
@Override public void encode() { Flux<byte[]> input = Flux.just(this.fooBytes, this.barBytes); testEncodeAll(input, byte[].class, step -> step .consumeNextWith(expectBytes(this.fooBytes)) .consumeNextWith(expectBytes(this.barBytes)) .verifyComplete()); } }
@Override @Test public void decodeToMono() { Mono<DataBuffer> input = dataBuffer(this.testMsg1); testDecodeToMonoAll(input, Msg.class, step -> step .expectNext(this.testMsg1) .verifyComplete()); }
private <T> void testWrite( Publisher<T> source, MediaType mediaType, MockServerHttpResponse response, Class<T> clazz) { Mono<Void> result = this.messageWriter.write(source, forClass(clazz), mediaType, response, HINTS); StepVerifier.create(result) .verifyComplete(); }
@Test public void emptyBodyWithMono() throws Exception { ResolvableType type = httpEntityType(Mono.class, String.class); HttpEntity<Mono<String>> entity = resolveValueWithEmptyBody(type); StepVerifier.create(entity.getBody()).expectNextCount(0).expectComplete().verify(); }
private void verifyReadData(Flux<DataBuffer> buffers) { StepVerifier.create(buffers) .consumeNextWith(stringConsumer("foo")) .consumeNextWith(stringConsumer("bar")) .consumeNextWith(stringConsumer("baz")) .consumeNextWith(stringConsumer("qux")) .expectComplete() .verify(Duration.ofSeconds(3)); }
@Test @SuppressWarnings("unchecked") public void validateMonoTestBean() throws Exception { String body = "{\"bar\":\"b1\"}"; ResolvableType type = forClassWithGenerics(Mono.class, TestBean.class); MethodParameter param = this.testMethod.arg(type); Mono<TestBean> mono = resolveValue(param, body); StepVerifier.create(mono).expectNextCount(0).expectError(ServerWebInputException.class).verify(); }
@Test public void notFound() { Mono<ServerResponse> result = ServerResponse.notFound().build(); StepVerifier.create(result) .expectNextMatches(response -> HttpStatus.NOT_FOUND.equals(response.statusCode())) .expectComplete() .verify(); }
@Override public void encode() { Flux<CharSequence> input = Flux.just(this.foo, this.bar); testEncodeAll(input, CharSequence.class, step -> step .consumeNextWith(expectString(this.foo)) .consumeNextWith(expectString(this.bar)) .verifyComplete()); }
@Test public void emptyBodyWithFlux() throws Exception { ResolvableType type = httpEntityType(Flux.class, String.class); HttpEntity<Flux<String>> entity = resolveValueWithEmptyBody(type); StepVerifier.create(entity.getBody()).expectNextCount(0).expectComplete().verify(); }
@Test public void readResourcePosition() throws Exception { Flux<DataBuffer> flux = DataBufferUtils.read(this.resource, 9, this.bufferFactory, 3); StepVerifier.create(flux) .consumeNextWith(stringConsumer("qux")) .expectComplete() .verify(Duration.ofSeconds(5)); }
@Test public void emptyBodyWithFlowable() throws Exception { ResolvableType type = httpEntityType(Flowable.class, String.class); HttpEntity<Flowable<String>> entity = resolveValueWithEmptyBody(type); StepVerifier.create(entity.getBody()) .expectNextCount(0) .expectComplete() .verify(); }
private void assertResponseBody(String responseBody) { StepVerifier.create(this.exchange.getResponse().getBody()) .consumeNextWith(buf -> assertEquals(responseBody, dumpString(buf, StandardCharsets.UTF_8))) .expectComplete() .verify(); }
@Test public void emptyBodyWithRxJava2Observable() throws Exception { ResolvableType type = httpEntityType(io.reactivex.Observable.class, String.class); HttpEntity<io.reactivex.Observable<String>> entity = resolveValueWithEmptyBody(type); StepVerifier.create(entity.getBody().toFlowable(BackpressureStrategy.BUFFER)) .expectNextCount(0) .expectComplete() .verify(); }