Merge branch '5.3.x' into main
This commit is contained in:
commit
e7b97f5be7
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2021 the original author or authors.
|
* Copyright 2002-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -81,7 +81,7 @@ public abstract class AbstractEncoderTests<E extends Encoder<?>> extends Abstrac
|
||||||
* Helper methods that tests for a variety of encoding scenarios. This methods
|
* Helper methods that tests for a variety of encoding scenarios. This methods
|
||||||
* invokes:
|
* invokes:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>{@link #testEncode(Publisher, ResolvableType, Consumer, MimeType, Map)}</li>
|
* <li>{@link #testEncode(Publisher, ResolvableType, MimeType, Map, Consumer)}</li>
|
||||||
* <li>{@link #testEncodeError(Publisher, ResolvableType, MimeType, Map)}</li>
|
* <li>{@link #testEncodeError(Publisher, ResolvableType, MimeType, Map)}</li>
|
||||||
* <li>{@link #testEncodeCancel(Publisher, ResolvableType, MimeType, Map)}</li>
|
* <li>{@link #testEncodeCancel(Publisher, ResolvableType, MimeType, Map)}</li>
|
||||||
* <li>{@link #testEncodeEmpty(ResolvableType, MimeType, Map)}</li>
|
* <li>{@link #testEncodeEmpty(ResolvableType, MimeType, Map)}</li>
|
||||||
|
@ -94,30 +94,32 @@ public abstract class AbstractEncoderTests<E extends Encoder<?>> extends Abstrac
|
||||||
*/
|
*/
|
||||||
protected <T> void testEncodeAll(Publisher<? extends T> input, Class<? extends T> inputClass,
|
protected <T> void testEncodeAll(Publisher<? extends T> input, Class<? extends T> inputClass,
|
||||||
Consumer<StepVerifier.FirstStep<DataBuffer>> stepConsumer) {
|
Consumer<StepVerifier.FirstStep<DataBuffer>> stepConsumer) {
|
||||||
testEncodeAll(input, ResolvableType.forClass(inputClass), stepConsumer, null, null);
|
|
||||||
|
testEncodeAll(input, ResolvableType.forClass(inputClass), null, null, stepConsumer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper methods that tests for a variety of decoding scenarios. This methods
|
* Helper methods that tests for a variety of decoding scenarios. This methods
|
||||||
* invokes:
|
* invokes:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>{@link #testEncode(Publisher, ResolvableType, Consumer, MimeType, Map)}</li>
|
* <li>{@link #testEncode(Publisher, ResolvableType, MimeType, Map, Consumer)}</li>
|
||||||
* <li>{@link #testEncodeError(Publisher, ResolvableType, MimeType, Map)}</li>
|
* <li>{@link #testEncodeError(Publisher, ResolvableType, MimeType, Map)}</li>
|
||||||
* <li>{@link #testEncodeCancel(Publisher, ResolvableType, MimeType, Map)}</li>
|
* <li>{@link #testEncodeCancel(Publisher, ResolvableType, MimeType, Map)}</li>
|
||||||
* <li>{@link #testEncodeEmpty(ResolvableType, MimeType, Map)}</li>
|
* <li>{@link #testEncodeEmpty(ResolvableType, MimeType, Map)}</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
|
* @param <T> the output type
|
||||||
* @param input the input to be provided to the encoder
|
* @param input the input to be provided to the encoder
|
||||||
* @param inputType the input type
|
* @param inputType the input type
|
||||||
* @param stepConsumer a consumer to {@linkplain StepVerifier verify} the output
|
|
||||||
* @param mimeType the mime type to use for decoding. May be {@code null}.
|
* @param mimeType the mime type to use for decoding. May be {@code null}.
|
||||||
* @param hints the hints used for decoding. May be {@code null}.
|
* @param hints the hints used for decoding. May be {@code null}.
|
||||||
* @param <T> the output type
|
* @param stepConsumer a consumer to {@linkplain StepVerifier verify} the output
|
||||||
*/
|
*/
|
||||||
protected <T> void testEncodeAll(Publisher<? extends T> input, ResolvableType inputType,
|
protected <T> void testEncodeAll(Publisher<? extends T> input, ResolvableType inputType,
|
||||||
Consumer<StepVerifier.FirstStep<DataBuffer>> stepConsumer,
|
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints,
|
||||||
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
|
Consumer<StepVerifier.FirstStep<DataBuffer>> stepConsumer) {
|
||||||
testEncode(input, inputType, stepConsumer, mimeType, hints);
|
|
||||||
|
testEncode(input, inputType, mimeType, hints, stepConsumer);
|
||||||
testEncodeError(input, inputType, mimeType, hints);
|
testEncodeError(input, inputType, mimeType, hints);
|
||||||
testEncodeCancel(input, inputType, mimeType, hints);
|
testEncodeCancel(input, inputType, mimeType, hints);
|
||||||
testEncodeEmpty(inputType, mimeType, hints);
|
testEncodeEmpty(inputType, mimeType, hints);
|
||||||
|
@ -133,25 +135,25 @@ public abstract class AbstractEncoderTests<E extends Encoder<?>> extends Abstrac
|
||||||
*/
|
*/
|
||||||
protected <T> void testEncode(Publisher<? extends T> input, Class<? extends T> inputClass,
|
protected <T> void testEncode(Publisher<? extends T> input, Class<? extends T> inputClass,
|
||||||
Consumer<StepVerifier.FirstStep<DataBuffer>> stepConsumer) {
|
Consumer<StepVerifier.FirstStep<DataBuffer>> stepConsumer) {
|
||||||
testEncode(input, ResolvableType.forClass(inputClass), stepConsumer, null, null);
|
|
||||||
|
testEncode(input, ResolvableType.forClass(inputClass), null, null, stepConsumer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test a standard {@link Encoder#encode encode} scenario.
|
* Test a standard {@link Encoder#encode encode} scenario.
|
||||||
*
|
*
|
||||||
|
* @param <T> the output type
|
||||||
* @param input the input to be provided to the encoder
|
* @param input the input to be provided to the encoder
|
||||||
* @param inputType the input type
|
* @param inputType the input type
|
||||||
* @param stepConsumer a consumer to {@linkplain StepVerifier verify} the output
|
|
||||||
* @param mimeType the mime type to use for decoding. May be {@code null}.
|
* @param mimeType the mime type to use for decoding. May be {@code null}.
|
||||||
* @param hints the hints used for decoding. May be {@code null}.
|
* @param hints the hints used for decoding. May be {@code null}.
|
||||||
* @param <T> the output type
|
* @param stepConsumer a consumer to {@linkplain StepVerifier verify} the output
|
||||||
*/
|
*/
|
||||||
protected <T> void testEncode(Publisher<? extends T> input, ResolvableType inputType,
|
protected <T> void testEncode(Publisher<? extends T> input, ResolvableType inputType,
|
||||||
Consumer<StepVerifier.FirstStep<DataBuffer>> stepConsumer,
|
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints,
|
||||||
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
|
Consumer<StepVerifier.FirstStep<DataBuffer>> stepConsumer) {
|
||||||
|
|
||||||
Flux<DataBuffer> result = encoder().encode(input, this.bufferFactory, inputType,
|
Flux<DataBuffer> result = encoder().encode(input, this.bufferFactory, inputType, mimeType, hints);
|
||||||
mimeType, hints);
|
|
||||||
StepVerifier.FirstStep<DataBuffer> step = StepVerifier.create(result);
|
StepVerifier.FirstStep<DataBuffer> step = StepVerifier.create(result);
|
||||||
stepConsumer.accept(step);
|
stepConsumer.accept(step);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2017 the original author or authors.
|
* Copyright 2002-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -32,7 +32,7 @@ import org.springframework.util.Assert;
|
||||||
*/
|
*/
|
||||||
public class MockClientHttpResponse extends MockHttpInputMessage implements ClientHttpResponse {
|
public class MockClientHttpResponse extends MockHttpInputMessage implements ClientHttpResponse {
|
||||||
|
|
||||||
private final HttpStatus status;
|
private final int statusCode;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,7 +41,17 @@ public class MockClientHttpResponse extends MockHttpInputMessage implements Clie
|
||||||
public MockClientHttpResponse(byte[] body, HttpStatus statusCode) {
|
public MockClientHttpResponse(byte[] body, HttpStatus statusCode) {
|
||||||
super(body);
|
super(body);
|
||||||
Assert.notNull(statusCode, "HttpStatus is required");
|
Assert.notNull(statusCode, "HttpStatus is required");
|
||||||
this.status = statusCode;
|
this.statusCode = statusCode.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Variant of {@link #MockClientHttpResponse(byte[], HttpStatus)} with a
|
||||||
|
* custom HTTP status code.
|
||||||
|
* @since 5.3.17
|
||||||
|
*/
|
||||||
|
public MockClientHttpResponse(byte[] body, int statusCode) {
|
||||||
|
super(body);
|
||||||
|
this.statusCode = statusCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -50,23 +60,34 @@ public class MockClientHttpResponse extends MockHttpInputMessage implements Clie
|
||||||
public MockClientHttpResponse(InputStream body, HttpStatus statusCode) {
|
public MockClientHttpResponse(InputStream body, HttpStatus statusCode) {
|
||||||
super(body);
|
super(body);
|
||||||
Assert.notNull(statusCode, "HttpStatus is required");
|
Assert.notNull(statusCode, "HttpStatus is required");
|
||||||
this.status = statusCode;
|
this.statusCode = statusCode.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Variant of {@link #MockClientHttpResponse(InputStream, HttpStatus)} with a
|
||||||
|
* custom HTTP status code.
|
||||||
|
* @since 5.3.17
|
||||||
|
*/
|
||||||
|
public MockClientHttpResponse(InputStream body, int statusCode) {
|
||||||
|
super(body);
|
||||||
|
this.statusCode = statusCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HttpStatus getStatusCode() throws IOException {
|
public HttpStatus getStatusCode() {
|
||||||
return this.status;
|
return HttpStatus.valueOf(this.statusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getRawStatusCode() throws IOException {
|
public int getRawStatusCode() {
|
||||||
return this.status.value();
|
return this.statusCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getStatusText() throws IOException {
|
public String getStatusText() {
|
||||||
return this.status.getReasonPhrase();
|
HttpStatus status = HttpStatus.resolve(this.statusCode);
|
||||||
|
return (status != null ? status.getReasonPhrase() : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2021 the original author or authors.
|
* Copyright 2002-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -17,7 +17,6 @@
|
||||||
package org.springframework.test.web.client.response;
|
package org.springframework.test.web.client.response;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
@ -40,7 +39,7 @@ import org.springframework.util.Assert;
|
||||||
*/
|
*/
|
||||||
public class DefaultResponseCreator implements ResponseCreator {
|
public class DefaultResponseCreator implements ResponseCreator {
|
||||||
|
|
||||||
private final HttpStatus statusCode;
|
private final int statusCode;
|
||||||
|
|
||||||
private byte[] content = new byte[0];
|
private byte[] content = new byte[0];
|
||||||
|
|
||||||
|
@ -56,6 +55,15 @@ public class DefaultResponseCreator implements ResponseCreator {
|
||||||
*/
|
*/
|
||||||
protected DefaultResponseCreator(HttpStatus statusCode) {
|
protected DefaultResponseCreator(HttpStatus statusCode) {
|
||||||
Assert.notNull(statusCode, "HttpStatus must not be null");
|
Assert.notNull(statusCode, "HttpStatus must not be null");
|
||||||
|
this.statusCode = statusCode.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Protected constructor.
|
||||||
|
* Use static factory methods in {@link MockRestResponseCreators}.
|
||||||
|
* @since 5.3.17
|
||||||
|
*/
|
||||||
|
protected DefaultResponseCreator(int statusCode) {
|
||||||
this.statusCode = statusCode;
|
this.statusCode = statusCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,14 +119,9 @@ public class DefaultResponseCreator implements ResponseCreator {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ClientHttpResponse createResponse(@Nullable ClientHttpRequest request) throws IOException {
|
public ClientHttpResponse createResponse(@Nullable ClientHttpRequest request) throws IOException {
|
||||||
MockClientHttpResponse response;
|
MockClientHttpResponse response = (this.contentResource != null ?
|
||||||
if (this.contentResource != null) {
|
new MockClientHttpResponse(this.contentResource.getInputStream(), this.statusCode) :
|
||||||
InputStream stream = this.contentResource.getInputStream();
|
new MockClientHttpResponse(this.content, this.statusCode));
|
||||||
response = new MockClientHttpResponse(stream, this.statusCode);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
response = new MockClientHttpResponse(this.content, this.statusCode);
|
|
||||||
}
|
|
||||||
response.getHeaders().putAll(this.headers);
|
response.getHeaders().putAll(this.headers);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2019 the original author or authors.
|
* Copyright 2002-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -117,6 +117,15 @@ public abstract class MockRestResponseCreators {
|
||||||
return new DefaultResponseCreator(status);
|
return new DefaultResponseCreator(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Variant of {@link #withStatus(HttpStatus)} for a custom HTTP status code.
|
||||||
|
* @param status the response status
|
||||||
|
* @since 5.3.17
|
||||||
|
*/
|
||||||
|
public static DefaultResponseCreator withRawStatus(int status) {
|
||||||
|
return new DefaultResponseCreator(status);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@code ResponseCreator} with an internal application {@code IOException}.
|
* {@code ResponseCreator} with an internal application {@code IOException}.
|
||||||
* <p>For example, one could use this to simulate a {@code SocketTimeoutException}.
|
* <p>For example, one could use this to simulate a {@code SocketTimeoutException}.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2020 the original author or authors.
|
* Copyright 2002-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -128,6 +128,15 @@ class ResponseCreatorsTests {
|
||||||
assertThat(StreamUtils.copyToByteArray(response.getBody()).length).isEqualTo(0);
|
assertThat(StreamUtils.copyToByteArray(response.getBody()).length).isEqualTo(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void withCustomStatus() throws Exception {
|
||||||
|
DefaultResponseCreator responseCreator = MockRestResponseCreators.withRawStatus(454);
|
||||||
|
MockClientHttpResponse response = (MockClientHttpResponse) responseCreator.createResponse(null);
|
||||||
|
|
||||||
|
assertThat(response.getRawStatusCode()).isEqualTo(454);
|
||||||
|
assertThat(response.getStatusText()).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void withException() {
|
void withException() {
|
||||||
ResponseCreator responseCreator = MockRestResponseCreators.withException(new SocketTimeoutException());
|
ResponseCreator responseCreator = MockRestResponseCreators.withException(new SocketTimeoutException());
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2021 the original author or authors.
|
* Copyright 2002-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -196,21 +196,25 @@ public abstract class AbstractJackson2Encoder extends Jackson2CodecSupport imple
|
||||||
public DataBuffer encodeValue(Object value, DataBufferFactory bufferFactory,
|
public DataBuffer encodeValue(Object value, DataBufferFactory bufferFactory,
|
||||||
ResolvableType valueType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
|
ResolvableType valueType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
|
||||||
|
|
||||||
ObjectMapper mapper = selectObjectMapper(valueType, mimeType);
|
|
||||||
if (mapper == null) {
|
|
||||||
throw new IllegalStateException("No ObjectMapper for " + valueType);
|
|
||||||
}
|
|
||||||
Class<?> jsonView = null;
|
Class<?> jsonView = null;
|
||||||
FilterProvider filters = null;
|
FilterProvider filters = null;
|
||||||
if (value instanceof MappingJacksonValue mappingJacksonValue) {
|
if (value instanceof MappingJacksonValue mappingJacksonValue) {
|
||||||
value = mappingJacksonValue.getValue();
|
value = mappingJacksonValue.getValue();
|
||||||
|
valueType = ResolvableType.forInstance(value);
|
||||||
jsonView = mappingJacksonValue.getSerializationView();
|
jsonView = mappingJacksonValue.getSerializationView();
|
||||||
filters = mappingJacksonValue.getFilters();
|
filters = mappingJacksonValue.getFilters();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ObjectMapper mapper = selectObjectMapper(valueType, mimeType);
|
||||||
|
if (mapper == null) {
|
||||||
|
throw new IllegalStateException("No ObjectMapper for " + valueType);
|
||||||
|
}
|
||||||
|
|
||||||
ObjectWriter writer = createObjectWriter(mapper, valueType, mimeType, jsonView, hints);
|
ObjectWriter writer = createObjectWriter(mapper, valueType, mimeType, jsonView, hints);
|
||||||
if (filters != null) {
|
if (filters != null) {
|
||||||
writer = writer.with(filters);
|
writer = writer.with(filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteArrayBuilder byteBuilder = new ByteArrayBuilder(writer.getFactory()._getBufferRecycler());
|
ByteArrayBuilder byteBuilder = new ByteArrayBuilder(writer.getFactory()._getBufferRecycler());
|
||||||
try {
|
try {
|
||||||
JsonEncoding encoding = getJsonEncoding(mimeType);
|
JsonEncoding encoding = getJsonEncoding(mimeType);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2021 the original author or authors.
|
* Copyright 2002-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -95,12 +95,12 @@ public class Jackson2JsonEncoderTests extends AbstractEncoderTests<Jackson2JsonE
|
||||||
new Pojo("foofoo", "barbar"),
|
new Pojo("foofoo", "barbar"),
|
||||||
new Pojo("foofoofoo", "barbarbar"));
|
new Pojo("foofoofoo", "barbarbar"));
|
||||||
|
|
||||||
testEncodeAll(input, ResolvableType.forClass(Pojo.class), step -> step
|
testEncodeAll(input, ResolvableType.forClass(Pojo.class), APPLICATION_STREAM_JSON, null, step -> step
|
||||||
.consumeNextWith(expectString("{\"foo\":\"foo\",\"bar\":\"bar\"}\n"))
|
.consumeNextWith(expectString("{\"foo\":\"foo\",\"bar\":\"bar\"}\n"))
|
||||||
.consumeNextWith(expectString("{\"foo\":\"foofoo\",\"bar\":\"barbar\"}\n"))
|
.consumeNextWith(expectString("{\"foo\":\"foofoo\",\"bar\":\"barbar\"}\n"))
|
||||||
.consumeNextWith(expectString("{\"foo\":\"foofoofoo\",\"bar\":\"barbarbar\"}\n"))
|
.consumeNextWith(expectString("{\"foo\":\"foofoofoo\",\"bar\":\"barbarbar\"}\n"))
|
||||||
.verifyComplete(),
|
.verifyComplete()
|
||||||
APPLICATION_STREAM_JSON, null);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // SPR-15866
|
@Test // SPR-15866
|
||||||
|
@ -168,15 +168,15 @@ public class Jackson2JsonEncoderTests extends AbstractEncoderTests<Jackson2JsonE
|
||||||
new Pojo("foofoofoo", "barbarbar")
|
new Pojo("foofoofoo", "barbarbar")
|
||||||
);
|
);
|
||||||
|
|
||||||
testEncode(input, ResolvableType.forClass(Pojo.class), step -> step
|
testEncode(input, ResolvableType.forClass(Pojo.class), barMediaType, null, step -> step
|
||||||
.consumeNextWith(expectString("{\"foo\":\"foo\",\"bar\":\"bar\"}\n")
|
.consumeNextWith(expectString("{\"foo\":\"foo\",\"bar\":\"bar\"}\n")
|
||||||
.andThen(DataBufferUtils::release))
|
.andThen(DataBufferUtils::release))
|
||||||
.consumeNextWith(expectString("{\"foo\":\"foofoo\",\"bar\":\"barbar\"}\n")
|
.consumeNextWith(expectString("{\"foo\":\"foofoo\",\"bar\":\"barbar\"}\n")
|
||||||
.andThen(DataBufferUtils::release))
|
.andThen(DataBufferUtils::release))
|
||||||
.consumeNextWith(expectString("{\"foo\":\"foofoofoo\",\"bar\":\"barbarbar\"}\n")
|
.consumeNextWith(expectString("{\"foo\":\"foofoofoo\",\"bar\":\"barbarbar\"}\n")
|
||||||
.andThen(DataBufferUtils::release))
|
.andThen(DataBufferUtils::release))
|
||||||
.verifyComplete(),
|
.verifyComplete()
|
||||||
barMediaType, null);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -190,11 +190,10 @@ public class Jackson2JsonEncoderTests extends AbstractEncoderTests<Jackson2JsonE
|
||||||
ResolvableType type = ResolvableType.forClass(JacksonViewBean.class);
|
ResolvableType type = ResolvableType.forClass(JacksonViewBean.class);
|
||||||
Map<String, Object> hints = singletonMap(JSON_VIEW_HINT, MyJacksonView1.class);
|
Map<String, Object> hints = singletonMap(JSON_VIEW_HINT, MyJacksonView1.class);
|
||||||
|
|
||||||
testEncode(input, type, step -> step
|
testEncode(input, type, null, hints, step -> step
|
||||||
.consumeNextWith(expectString("{\"withView1\":\"with\"}")
|
.consumeNextWith(expectString("{\"withView1\":\"with\"}").andThen(DataBufferUtils::release))
|
||||||
.andThen(DataBufferUtils::release))
|
.verifyComplete()
|
||||||
.verifyComplete(),
|
);
|
||||||
null, hints);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -208,11 +207,10 @@ public class Jackson2JsonEncoderTests extends AbstractEncoderTests<Jackson2JsonE
|
||||||
ResolvableType type = ResolvableType.forClass(JacksonViewBean.class);
|
ResolvableType type = ResolvableType.forClass(JacksonViewBean.class);
|
||||||
Map<String, Object> hints = singletonMap(JSON_VIEW_HINT, MyJacksonView3.class);
|
Map<String, Object> hints = singletonMap(JSON_VIEW_HINT, MyJacksonView3.class);
|
||||||
|
|
||||||
testEncode(input, type, step -> step
|
testEncode(input, type, null, hints, step -> step
|
||||||
.consumeNextWith(expectString("{\"withoutView\":\"without\"}")
|
.consumeNextWith(expectString("{\"withoutView\":\"without\"}").andThen(DataBufferUtils::release))
|
||||||
.andThen(DataBufferUtils::release))
|
.verifyComplete()
|
||||||
.verifyComplete(),
|
);
|
||||||
null, hints);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -227,11 +225,33 @@ public class Jackson2JsonEncoderTests extends AbstractEncoderTests<Jackson2JsonE
|
||||||
|
|
||||||
ResolvableType type = ResolvableType.forClass(MappingJacksonValue.class);
|
ResolvableType type = ResolvableType.forClass(MappingJacksonValue.class);
|
||||||
|
|
||||||
testEncode(Mono.just(jacksonValue), type, step -> step
|
testEncode(Mono.just(jacksonValue), type, null, Collections.emptyMap(), step -> step
|
||||||
.consumeNextWith(expectString("{\"withView1\":\"with\"}")
|
.consumeNextWith(expectString("{\"withView1\":\"with\"}").andThen(DataBufferUtils::release))
|
||||||
.andThen(DataBufferUtils::release))
|
.verifyComplete()
|
||||||
.verifyComplete(),
|
);
|
||||||
null, Collections.emptyMap());
|
}
|
||||||
|
|
||||||
|
@Test // gh-28045
|
||||||
|
public void jacksonValueUnwrappedBeforeObjectMapperSelection() {
|
||||||
|
|
||||||
|
JacksonViewBean bean = new JacksonViewBean();
|
||||||
|
bean.setWithView1("with");
|
||||||
|
bean.setWithView2("with");
|
||||||
|
bean.setWithoutView("without");
|
||||||
|
|
||||||
|
MappingJacksonValue jacksonValue = new MappingJacksonValue(bean);
|
||||||
|
jacksonValue.setSerializationView(MyJacksonView1.class);
|
||||||
|
|
||||||
|
ResolvableType type = ResolvableType.forClass(MappingJacksonValue.class);
|
||||||
|
|
||||||
|
MediaType halMediaType = MediaType.parseMediaType("application/hal+json");
|
||||||
|
ObjectMapper mapper = new ObjectMapper().configure(SerializationFeature.INDENT_OUTPUT, true);
|
||||||
|
this.encoder.registerObjectMappersForType(JacksonViewBean.class, map -> map.put(halMediaType, mapper));
|
||||||
|
|
||||||
|
testEncode(Mono.just(jacksonValue), type, halMediaType, Collections.emptyMap(), step -> step
|
||||||
|
.consumeNextWith(expectString("{\n \"withView1\" : \"with\"\n}").andThen(DataBufferUtils::release))
|
||||||
|
.verifyComplete()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // gh-22771
|
@Test // gh-22771
|
||||||
|
@ -252,11 +272,12 @@ public class Jackson2JsonEncoderTests extends AbstractEncoderTests<Jackson2JsonE
|
||||||
@Test
|
@Test
|
||||||
public void encodeAscii() {
|
public void encodeAscii() {
|
||||||
Mono<Object> input = Mono.just(new Pojo("foo", "bar"));
|
Mono<Object> input = Mono.just(new Pojo("foo", "bar"));
|
||||||
|
MimeType mimeType = new MimeType("application", "json", StandardCharsets.US_ASCII);
|
||||||
|
|
||||||
testEncode(input, ResolvableType.forClass(Pojo.class), step -> step
|
testEncode(input, ResolvableType.forClass(Pojo.class), mimeType, null, step -> step
|
||||||
.consumeNextWith(expectString("{\"foo\":\"foo\",\"bar\":\"bar\"}"))
|
.consumeNextWith(expectString("{\"foo\":\"foo\",\"bar\":\"bar\"}"))
|
||||||
.verifyComplete(),
|
.verifyComplete()
|
||||||
new MimeType("application", "json", StandardCharsets.US_ASCII), null);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2020 the original author or authors.
|
* Copyright 2002-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -108,17 +108,13 @@ public class Jackson2SmileEncoderTests extends AbstractEncoderTests<Jackson2Smil
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void encodeError() throws Exception {
|
public void encodeError() {
|
||||||
Mono<Pojo> input = Mono.error(new InputException());
|
Mono<Pojo> input = Mono.error(new InputException());
|
||||||
|
testEncode(input, Pojo.class, step -> step.expectError(InputException.class).verify());
|
||||||
testEncode(input, Pojo.class, step -> step
|
|
||||||
.expectError(InputException.class)
|
|
||||||
.verify());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void encodeAsStream() throws Exception {
|
public void encodeAsStream() {
|
||||||
Pojo pojo1 = new Pojo("foo", "bar");
|
Pojo pojo1 = new Pojo("foo", "bar");
|
||||||
Pojo pojo2 = new Pojo("foofoo", "barbar");
|
Pojo pojo2 = new Pojo("foofoo", "barbar");
|
||||||
Pojo pojo3 = new Pojo("foofoofoo", "barbarbar");
|
Pojo pojo3 = new Pojo("foofoofoo", "barbarbar");
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2021 the original author or authors.
|
* Copyright 2002-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -70,8 +70,8 @@ public class Jaxb2XmlEncoderTests extends AbstractEncoderTests<Jaxb2XmlEncoder>
|
||||||
Mono<Pojo> input = Mono.just(new Pojo("foofoo", "barbar"));
|
Mono<Pojo> input = Mono.just(new Pojo("foofoo", "barbar"));
|
||||||
|
|
||||||
testEncode(input, Pojo.class, step -> step
|
testEncode(input, Pojo.class, step -> step
|
||||||
.consumeNextWith(
|
.consumeNextWith(expectXml(
|
||||||
expectXml("<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" +
|
"<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" +
|
||||||
"<pojo><bar>barbar</bar><foo>foofoo</foo></pojo>"))
|
"<pojo><bar>barbar</bar><foo>foofoo</foo></pojo>"))
|
||||||
.verifyComplete());
|
.verifyComplete());
|
||||||
}
|
}
|
||||||
|
@ -79,10 +79,7 @@ public class Jaxb2XmlEncoderTests extends AbstractEncoderTests<Jaxb2XmlEncoder>
|
||||||
@Test
|
@Test
|
||||||
public void encodeError() {
|
public void encodeError() {
|
||||||
Flux<Pojo> input = Flux.error(RuntimeException::new);
|
Flux<Pojo> input = Flux.error(RuntimeException::new);
|
||||||
|
testEncode(input, Pojo.class, step -> step.expectError(RuntimeException.class).verify());
|
||||||
testEncode(input, Pojo.class, step -> step
|
|
||||||
.expectError(RuntimeException.class)
|
|
||||||
.verify());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -90,9 +87,11 @@ public class Jaxb2XmlEncoderTests extends AbstractEncoderTests<Jaxb2XmlEncoder>
|
||||||
Mono<Container> input = Mono.just(new Container());
|
Mono<Container> input = Mono.just(new Container());
|
||||||
|
|
||||||
testEncode(input, Pojo.class, step -> step
|
testEncode(input, Pojo.class, step -> step
|
||||||
.consumeNextWith(
|
.consumeNextWith(expectXml(
|
||||||
expectXml("<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" +
|
"<?xml version='1.0' encoding='UTF-8' standalone='yes'?>" +
|
||||||
"<container><foo><name>name1</name></foo><bar><title>title1</title></bar></container>"))
|
"<container>" +
|
||||||
|
"<foo><name>name1</name></foo><bar><title>title1</title></bar>" +
|
||||||
|
"</container>"))
|
||||||
.verifyComplete());
|
.verifyComplete());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2021 the original author or authors.
|
* Copyright 2002-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -65,25 +65,23 @@ class KotlinSerializationJsonEncoderTests : AbstractEncoderTests<KotlinSerializa
|
||||||
Pojo("foofoo", "barbar"),
|
Pojo("foofoo", "barbar"),
|
||||||
Pojo("foofoofoo", "barbarbar")
|
Pojo("foofoofoo", "barbarbar")
|
||||||
)
|
)
|
||||||
testEncode(input, Pojo::class.java, { step: FirstStep<DataBuffer?> ->
|
testEncode(input, Pojo::class.java, { step: FirstStep<DataBuffer?> -> step
|
||||||
step
|
.consumeNextWith(expectString("[" +
|
||||||
.consumeNextWith(expectString("[" +
|
"{\"foo\":\"foo\",\"bar\":\"bar\"}," +
|
||||||
"{\"foo\":\"foo\",\"bar\":\"bar\"}," +
|
"{\"foo\":\"foofoo\",\"bar\":\"barbar\"}," +
|
||||||
"{\"foo\":\"foofoo\",\"bar\":\"barbar\"}," +
|
"{\"foo\":\"foofoofoo\",\"bar\":\"barbarbar\"}]")
|
||||||
"{\"foo\":\"foofoofoo\",\"bar\":\"barbarbar\"}]")
|
.andThen { dataBuffer: DataBuffer? -> DataBufferUtils.release(dataBuffer) })
|
||||||
.andThen { dataBuffer: DataBuffer? -> DataBufferUtils.release(dataBuffer) })
|
.verifyComplete()
|
||||||
.verifyComplete()
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun encodeMono() {
|
fun encodeMono() {
|
||||||
val input = Mono.just(Pojo("foo", "bar"))
|
val input = Mono.just(Pojo("foo", "bar"))
|
||||||
testEncode(input, Pojo::class.java, { step: FirstStep<DataBuffer?> ->
|
testEncode(input, Pojo::class.java, { step: FirstStep<DataBuffer?> -> step
|
||||||
step
|
.consumeNextWith(expectString("{\"foo\":\"foo\",\"bar\":\"bar\"}")
|
||||||
.consumeNextWith(expectString("{\"foo\":\"foo\",\"bar\":\"bar\"}")
|
.andThen { dataBuffer: DataBuffer? -> DataBufferUtils.release(dataBuffer) })
|
||||||
.andThen { dataBuffer: DataBuffer? -> DataBufferUtils.release(dataBuffer) })
|
.verifyComplete()
|
||||||
.verifyComplete()
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue