@Override protected void testEncodeError(Publisher<?> input, ResolvableType outputType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) { Flux<Resource> i = Flux.error(new InputException()); Flux<DataBuffer> result = ((Encoder<Resource>) this.encoder).encode(i, this.bufferFactory, outputType, mimeType, hints); StepVerifier.create(result) .expectError(InputException.class) .verify(); }
@Test public void decodeErrorNonAalto() { decoder.useAalto = false; Flux<DataBuffer> source = Flux.concat( stringBuffer("<pojo>"), Flux.error(new RuntimeException())); Flux<XMLEvent> events = this.decoder.decode(source, null, null, Collections.emptyMap()); StepVerifier.create(events) .expectError(RuntimeException.class) .verify(); }
@Test public void resolve() { MethodParameter param = initMethodParameter(0); Mono<Object> mono = this.resolver.resolveArgument(param, new BindingContext(), this.exchange); StepVerifier.create(mono).expectError(ServerWebInputException.class).verify(); Foo foo = new Foo(); when(this.session.getAttribute("foo")).thenReturn(foo); mono = this.resolver.resolveArgument(param, new BindingContext(), this.exchange); assertSame(foo, mono.block()); }
@Test public void encodeError() { Flux<Pojo> input = Flux.error(RuntimeException::new); testEncode(input, Pojo.class, step -> step .expectError(RuntimeException.class) .verify()); }
@Test public void personRequired() { MethodParameter param = this.testMethod.annot(requestPart()).arg(Person.class); ServerWebExchange exchange = createExchange(new MultipartBodyBuilder()); Mono<Object> result = this.resolver.resolveArgument(param, new BindingContext(), exchange); StepVerifier.create(result).expectError(ServerWebInputException.class).verify(); }
@Test public void encodeError() throws Exception { Mono<Pojo> input = Mono.error(new InputException()); testEncode(input, Pojo.class, step -> step .expectError(InputException.class) .verify()); }
@Test public void joinErrors() { DataBuffer foo = stringBuffer("foo"); DataBuffer bar = stringBuffer("bar"); Flux<DataBuffer> flux = Flux.just(foo, bar).concatWith(Flux.error(new RuntimeException())); Mono<DataBuffer> result = DataBufferUtils.join(flux); StepVerifier.create(result) .expectError(RuntimeException.class) .verify(); }
@Test public void skipUntilByteCountErrorInFlux() { DataBuffer foo = stringBuffer("foo"); Flux<DataBuffer> flux = Flux.just(foo).concatWith(Mono.error(new RuntimeException())); Flux<DataBuffer> result = DataBufferUtils.skipUntilByteCount(flux, 3L); StepVerifier.create(result) .expectError(RuntimeException.class) .verify(Duration.ofSeconds(5)); }
@Override protected void testDecodeError(Publisher<DataBuffer> input, ResolvableType outputType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) { input = Flux.concat( Flux.from(input).take(1), Flux.error(new InputException())); Flux<Resource> result = this.decoder.decode(input, outputType, mimeType, hints); StepVerifier.create(result) .expectError(InputException.class) .verify(); }
@Test // SPR-13135 public void unsupportedReturnType() throws Exception { ByteArrayOutputStream body = new ByteArrayOutputStream(); MethodParameter type = on(TestController.class).resolveReturnType(OutputStream.class); HttpMessageWriter<?> writer = new EncoderHttpMessageWriter<>(new ByteBufferEncoder()); Mono<Void> mono = initResultHandler(writer).writeBody(body, type, this.exchange); StepVerifier.create(mono).expectError(IllegalStateException.class).verify(); }
@Test // SPR-9603 public void getHandlerRequestMethodMatchFalsePositive() { ServerWebExchange exchange = MockServerWebExchange.from(get("/users").accept(MediaType.APPLICATION_XML)); this.handlerMapping.registerHandler(new UserController()); Mono<Object> mono = this.handlerMapping.getHandler(exchange); StepVerifier.create(mono) .expectError(NotAcceptableStatusException.class) .verify(); }
@Test @SuppressWarnings("unchecked") // SPR-9942 public void emptyBody() throws Exception { MockServerHttpRequest request = post("/path").contentType(MediaType.APPLICATION_JSON).build(); ServerWebExchange exchange = MockServerWebExchange.from(request); ResolvableType type = forClassWithGenerics(Mono.class, TestBean.class); MethodParameter param = this.testMethod.arg(type); Mono<TestBean> result = (Mono<TestBean>) this.resolver.readBody( param, true, this.bindingContext, exchange).block(); StepVerifier.create(result).expectError(ServerWebInputException.class).verify(); }
@Test // SPR-17482 public void bodyToMonoVoidWithoutContentType() { this.server.enqueue(new MockResponse() .setResponseCode(HttpStatus.ACCEPTED.value()) .setChunkedBody("{\"foo\" : \"123\", \"baz\" : \"456\", \"baz\" : \"456\"}", 5)); Mono<Map<String, String>> mono = this.webClient.get() .uri("/sample").accept(MediaType.APPLICATION_JSON) .retrieve() .bodyToMono(new ParameterizedTypeReference<Map<String, String>>() {}); StepVerifier.create(mono).expectError(UnsupportedMediaTypeException.class).verify(Duration.ofSeconds(3)); assertEquals(1, this.server.getRequestCount()); }
@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(); }
@Test public void errorInStream() { DataBuffer buffer = stringBuffer("{\"id\":1,\"name\":"); Flux<DataBuffer> source = Flux.just(buffer) .concatWith(Flux.error(new RuntimeException())); Flux<TokenBuffer> result = Jackson2Tokenizer.tokenize(source, this.jsonFactory, true); StepVerifier.create(result) .expectError(RuntimeException.class) .verify(); }
@Test // SPR-16521 public void jsonEOFExceptionIsWrappedAsDecodingError() { Flux<DataBuffer> source = Flux.just(stringBuffer("{\"status\": \"noClosingQuote}")); Flux<TokenBuffer> tokens = Jackson2Tokenizer.tokenize(source, this.jsonFactory, false); StepVerifier.create(tokens) .expectError(DecodingException.class) .verify(); }
@Test public void partRequired() { MethodParameter param = this.testMethod.annot(requestPart()).arg(Part.class); ServerWebExchange exchange = createExchange(new MultipartBodyBuilder()); Mono<Object> result = this.resolver.resolveArgument(param, new BindingContext(), exchange); StepVerifier.create(result).expectError(ServerWebInputException.class).verify(); }
@SuppressWarnings("unchecked") @Test public void missingContentType() throws Exception { MockServerHttpRequest request = post("/path").body("{\"bar\":\"BARBAR\",\"foo\":\"FOOFOO\"}"); ServerWebExchange exchange = MockServerWebExchange.from(request); ResolvableType type = forClassWithGenerics(Mono.class, TestBean.class); MethodParameter param = this.testMethod.arg(type); Mono<Object> result = this.resolver.readBody(param, true, this.bindingContext, exchange); Mono<TestBean> value = (Mono<TestBean>) result.block(Duration.ofSeconds(1)); StepVerifier.create(value).expectError(UnsupportedMediaTypeStatusException.class).verify(); }
@Test public void decodeError() throws Exception { Flux<DataBuffer> source = Flux.concat( stringBuffer("<pojo>"), Flux.error(new RuntimeException())); Mono<Object> output = this.decoder.decodeToMono(source, ResolvableType.forClass(Pojo.class), null, Collections.emptyMap()); StepVerifier.create(output) .expectError(RuntimeException.class) .verify(); }
@Override protected void testDecodeError(Publisher<DataBuffer> input, ResolvableType outputType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) { input = Flux.concat( Flux.from(input).take(1), Flux.error(new InputException())); Flux<String> result = this.decoder.decode(input, outputType, mimeType, hints); StepVerifier.create(result) .expectError(InputException.class) .verify(); }