private Flux<DataBuffer> encodePartValues(byte[] boundary, String name, List<?> values) { return Flux.concat(values.stream().map(v -> encodePart(boundary, name, v)).collect(Collectors.toList())); }
@Override @Test public void decodeToMono() { Flux<DataBuffer> input = Flux.concat( dataBuffer(this.fooBytes), dataBuffer(this.barBytes)); ByteBuffer expected = ByteBuffer.allocate(this.fooBytes.length + this.barBytes.length); expected.put(this.fooBytes).put(this.barBytes).flip(); testDecodeToMonoAll(input, ByteBuffer.class, step -> step .consumeNextWith(expectByteBuffer(expected)) .verifyComplete()); }
@Override public void decodeToMono() throws Exception { Flux<DataBuffer> input = Flux.concat( dataBuffer(this.fooBytes), dataBuffer(this.barBytes)); byte[] expected = new byte[this.fooBytes.length + this.barBytes.length]; System.arraycopy(this.fooBytes, 0, expected, 0, this.fooBytes.length); System.arraycopy(this.barBytes, 0, expected, this.fooBytes.length, this.barBytes.length); testDecodeToMonoAll(input, DataBuffer.class, step -> step .consumeNextWith(expectDataBuffer(expected)) .verifyComplete()); }
@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(); }
@Override @Test public void decodeToMono() { Flux<DataBuffer> input = Flux.concat( dataBuffer(this.fooBytes), dataBuffer(this.barBytes)); byte[] expected = new byte[this.fooBytes.length + this.barBytes.length]; System.arraycopy(this.fooBytes, 0, expected, 0, this.fooBytes.length); System.arraycopy(this.barBytes, 0, expected, this.fooBytes.length, this.barBytes.length); testDecodeToMonoAll(input, byte[].class, step -> step .consumeNextWith(expectBytes(expected)) .verifyComplete()); }
@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(); }
@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<Resource> result = this.decoder.decode(input, outputType, mimeType, hints); StepVerifier.create(result) .expectError(InputException.class) .verify(); }
@Test public void takeUntilByteCountError() { Flux<DataBuffer> source = Flux.concat( Mono.defer(() -> Mono.just(stringBuffer("foo"))), Mono.error(new RuntimeException()) ); Flux<DataBuffer> result = DataBufferUtils.takeUntilByteCount(source, 5L); StepVerifier.create(result) .consumeNextWith(stringConsumer("foo")) .expectError(RuntimeException.class) .verify(Duration.ofSeconds(5)); }
@Test // gh-22042 public void decodeWithNullLiteral() { Flux<Object> result = this.decoder.decode(Flux.concat(stringBuffer("null")), ResolvableType.forType(Pojo.class), MediaType.APPLICATION_JSON, Collections.emptyMap()); StepVerifier.create(result).expectComplete().verify(); }
@Override @Test public void decode() { Flux<DataBuffer> input = Flux.concat( dataBuffer(this.fooBytes), dataBuffer(this.barBytes)); testDecodeAll(input, ByteBuffer.class, step -> step .consumeNextWith(expectByteBuffer(ByteBuffer.wrap(this.fooBytes))) .consumeNextWith(expectByteBuffer(ByteBuffer.wrap(this.barBytes))) .verifyComplete()); }
@Test public void skipUntilByteCountCancelled() { Flux<DataBuffer> source = Flux.concat( deferStringBuffer("foo"), deferStringBuffer("bar") ); Flux<DataBuffer> result = DataBufferUtils.skipUntilByteCount(source, 5L); StepVerifier.create(result) .consumeNextWith(stringConsumer("r")) .thenCancel() .verify(Duration.ofSeconds(5)); }
@Override public void decodeToMono() { Flux<DataBuffer> input = Flux.concat( stringBuffer("[{\"bar\":\"b1\",\"foo\":\"f1\"},"), stringBuffer("{\"bar\":\"b2\",\"foo\":\"f2\"}]")); ResolvableType elementType = ResolvableType.forClassWithGenerics(List.class, Pojo.class); testDecodeToMonoAll(input, elementType, step -> step .expectNext(asList(new Pojo("f1", "b1"), new Pojo("f2", "b2"))) .expectComplete() .verify(), null, null); }
@Test public void takeUntilByteCountCanceled() { Flux<DataBuffer> source = Flux.concat( deferStringBuffer("foo"), deferStringBuffer("bar") ); Flux<DataBuffer> result = DataBufferUtils.takeUntilByteCount( source, 5L); StepVerifier.create(result) .consumeNextWith(stringConsumer("foo")) .thenCancel() .verify(Duration.ofSeconds(5)); }
@Test public void decodeErrorAalto() { 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) .consumeNextWith(e -> assertTrue(e.isStartDocument())) .consumeNextWith(e -> assertStartElement(e, "pojo")) .expectError(RuntimeException.class) .verify(); }
@Override @Test public void decode() { Flux<DataBuffer> input = Flux.concat( stringBuffer("[{\"bar\":\"b1\",\"foo\":\"f1\"},"), stringBuffer("{\"bar\":\"b2\",\"foo\":\"f2\"}]")); testDecodeAll(input, Pojo.class, step -> step .expectNext(pojo1) .expectNext(pojo2) .verifyComplete()); }
@Test public void joinCanceled() { Flux<DataBuffer> source = Flux.concat( deferStringBuffer("foo"), deferStringBuffer("bar"), deferStringBuffer("baz") ); Mono<DataBuffer> result = DataBufferUtils.join(source); StepVerifier.create(result) .thenCancel() .verify(); }
@Test public void takeUntilByteCountExact() { Flux<DataBuffer> source = Flux.concat( deferStringBuffer("foo"), deferStringBuffer("bar"), deferStringBuffer("baz") ); Flux<DataBuffer> result = DataBufferUtils.takeUntilByteCount(source, 6L); StepVerifier.create(result) .consumeNextWith(stringConsumer("foo")) .consumeNextWith(stringConsumer("bar")) .expectComplete() .verify(Duration.ofSeconds(5)); }
@Override @Test public void decode() { Flux<DataBuffer> input = Flux.concat( dataBuffer(this.fooBytes), dataBuffer(this.barBytes)); testDecodeAll(input, byte[].class, step -> step .consumeNextWith(expectBytes(this.fooBytes)) .consumeNextWith(expectBytes(this.barBytes)) .verifyComplete()); }
@Test public void skipUntilByteCount() { Flux<DataBuffer> source = Flux.concat( deferStringBuffer("foo"), deferStringBuffer("bar"), deferStringBuffer("baz") ); Flux<DataBuffer> result = DataBufferUtils.skipUntilByteCount(source, 5L); StepVerifier.create(result) .consumeNextWith(stringConsumer("r")) .consumeNextWith(stringConsumer("baz")) .expectComplete() .verify(Duration.ofSeconds(5)); }