@Test(expected = ServerWebInputException.class) public void emptyBodyWithString() throws Exception { MethodParameter param = this.testMethod.annot(requestBody()).arg(String.class); resolveValueWithEmptyBody(param); }
@Test public void stringBody() throws Exception { String body = "line1"; MethodParameter param = this.testMethod.annot(requestBody()).arg(String.class); String value = resolveValue(param, body); assertEquals(body, value); }
@Test public void emptyBodyWithCompletableFuture() throws Exception { MethodParameter param = this.testMethod.annot(requestBody()).arg(CompletableFuture.class, String.class); CompletableFuture<String> future = resolveValueWithEmptyBody(param); future.whenComplete((text, ex) -> { assertNull(text); assertNotNull(ex); }); param = this.testMethod.annot(requestBody().notRequired()).arg(CompletableFuture.class, String.class); future = resolveValueWithEmptyBody(param); future.whenComplete((text, ex) -> { assertNotNull(text); assertNull(ex); }); }
@Test // SPR-15758 public void emptyBodyWithoutContentType() throws Exception { MethodParameter param = this.testMethod.annot(requestBody().notRequired()).arg(Map.class); String body = resolveValueWithEmptyBody(param); assertNull(body); }
@Test public void emptyBodyWithStringNotRequired() throws Exception { MethodParameter param = this.testMethod.annot(requestBody().notRequired()).arg(String.class); String body = resolveValueWithEmptyBody(param); assertNull(body); }
@Test @SuppressWarnings("unchecked") public void emptyBodyWithMono() throws Exception { MethodParameter param = this.testMethod.annot(requestBody()).arg(Mono.class, String.class); StepVerifier.create((Mono<Void>) resolveValueWithEmptyBody(param)) .expectNextCount(0) .expectError(ServerWebInputException.class) .verify(); param = this.testMethod.annot(requestBody().notRequired()).arg(Mono.class, String.class); StepVerifier.create((Mono<Void>) resolveValueWithEmptyBody(param)) .expectNextCount(0) .expectComplete() .verify(); }
@Test @SuppressWarnings("unchecked") public void emptyBodyWithFlux() throws Exception { MethodParameter param = this.testMethod.annot(requestBody()).arg(Flux.class, String.class); StepVerifier.create((Flux<Void>) resolveValueWithEmptyBody(param)) .expectNextCount(0) .expectError(ServerWebInputException.class) .verify(); param = this.testMethod.annot(requestBody().notRequired()).arg(Flux.class, String.class); StepVerifier.create((Flux<Void>) resolveValueWithEmptyBody(param)) .expectNextCount(0) .expectComplete() .verify(); }
@Test public void supports() throws Exception { MethodParameter param; param = this.testMethod.annot(requestBody()).arg(Mono.class, String.class); assertTrue(this.resolver.supportsParameter(param)); param = this.testMethod.annotNotPresent(RequestBody.class).arg(String.class); assertFalse(this.resolver.supportsParameter(param)); }
@Test public void emptyBodyWithSingle() throws Exception { MethodParameter param = this.testMethod.annot(requestBody()).arg(Single.class, String.class); Single<String> single = resolveValueWithEmptyBody(param); StepVerifier.create(RxReactiveStreams.toPublisher(single)) .expectNextCount(0) .expectError(ServerWebInputException.class) .verify(); param = this.testMethod.annot(requestBody().notRequired()).arg(Single.class, String.class); single = resolveValueWithEmptyBody(param); StepVerifier.create(RxReactiveStreams.toPublisher(single)) .expectNextCount(0) .expectError(ServerWebInputException.class) .verify(); }
@Test public void emptyBodyWithMaybe() throws Exception { MethodParameter param = this.testMethod.annot(requestBody()).arg(Maybe.class, String.class); Maybe<String> maybe = resolveValueWithEmptyBody(param); StepVerifier.create(maybe.toFlowable()) .expectNextCount(0) .expectError(ServerWebInputException.class) .verify(); param = this.testMethod.annot(requestBody().notRequired()).arg(Maybe.class, String.class); maybe = resolveValueWithEmptyBody(param); StepVerifier.create(maybe.toFlowable()) .expectNextCount(0) .expectComplete() .verify(); }
@Test public void emptyBodyWithObservable() throws Exception { MethodParameter param = this.testMethod.annot(requestBody()).arg(Observable.class, String.class); Observable<String> observable = resolveValueWithEmptyBody(param); StepVerifier.create(RxReactiveStreams.toPublisher(observable)) .expectNextCount(0) .expectError(ServerWebInputException.class) .verify(); param = this.testMethod.annot(requestBody().notRequired()).arg(Observable.class, String.class); observable = resolveValueWithEmptyBody(param); StepVerifier.create(RxReactiveStreams.toPublisher(observable)) .expectNextCount(0) .expectComplete() .verify(); }