Remove Pojo from tests that shouldn't depend on it
The Pojo test class from the codec package will end up in spring-core. This commit ensures it is used only from classes that also belong to spring-core.
This commit is contained in:
parent
4e3c439593
commit
22a6ca1f41
|
|
@ -21,6 +21,8 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
|
@ -36,7 +38,6 @@ import org.springframework.core.ResolvableType;
|
|||
import org.springframework.core.codec.support.JacksonJsonEncoder;
|
||||
import org.springframework.core.codec.support.Jaxb2Decoder;
|
||||
import org.springframework.core.codec.support.Jaxb2Encoder;
|
||||
import org.springframework.core.codec.support.Pojo;
|
||||
import org.springframework.core.codec.support.StringDecoder;
|
||||
import org.springframework.core.codec.support.StringEncoder;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
|
|
@ -141,8 +142,8 @@ public class WebReactiveConfigurationTests {
|
|||
assertHasConverter(converters, ByteBuffer.class, MediaType.APPLICATION_OCTET_STREAM);
|
||||
assertHasConverter(converters, String.class, MediaType.TEXT_PLAIN);
|
||||
assertHasConverter(converters, Resource.class, MediaType.IMAGE_PNG);
|
||||
assertHasConverter(converters, Pojo.class, MediaType.APPLICATION_XML);
|
||||
assertHasConverter(converters, Pojo.class, MediaType.APPLICATION_JSON);
|
||||
assertHasConverter(converters, TestBean.class, MediaType.APPLICATION_XML);
|
||||
assertHasConverter(converters, TestBean.class, MediaType.APPLICATION_JSON);
|
||||
|
||||
name = "mvcConversionService";
|
||||
ConversionService service = context.getBean(name, ConversionService.class);
|
||||
|
|
@ -161,7 +162,7 @@ public class WebReactiveConfigurationTests {
|
|||
assertEquals(2, converters.size());
|
||||
|
||||
assertHasConverter(converters, String.class, MediaType.TEXT_PLAIN);
|
||||
assertHasConverter(converters, Pojo.class, MediaType.APPLICATION_XML);
|
||||
assertHasConverter(converters, TestBean.class, MediaType.APPLICATION_XML);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -193,8 +194,8 @@ public class WebReactiveConfigurationTests {
|
|||
assertHasConverter(converters, ByteBuffer.class, MediaType.APPLICATION_OCTET_STREAM);
|
||||
assertHasConverter(converters, String.class, MediaType.TEXT_PLAIN);
|
||||
assertHasConverter(converters, Resource.class, MediaType.IMAGE_PNG);
|
||||
assertHasConverter(converters, Pojo.class, MediaType.APPLICATION_XML);
|
||||
assertHasConverter(converters, Pojo.class, MediaType.APPLICATION_JSON);
|
||||
assertHasConverter(converters, TestBean.class, MediaType.APPLICATION_XML);
|
||||
assertHasConverter(converters, TestBean.class, MediaType.APPLICATION_JSON);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -274,4 +275,8 @@ public class WebReactiveConfigurationTests {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
@XmlRootElement
|
||||
static class TestBean {
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
|
@ -44,7 +46,6 @@ import org.springframework.core.annotation.SynthesizingMethodParameter;
|
|||
import org.springframework.core.codec.Decoder;
|
||||
import org.springframework.core.codec.support.JacksonJsonDecoder;
|
||||
import org.springframework.core.codec.support.JsonObjectDecoder;
|
||||
import org.springframework.core.codec.support.Pojo;
|
||||
import org.springframework.core.codec.support.StringDecoder;
|
||||
import org.springframework.core.convert.support.GenericConversionService;
|
||||
import org.springframework.core.convert.support.ReactiveStreamsToCompletableFutureConverter;
|
||||
|
|
@ -102,7 +103,7 @@ public class RequestBodyArgumentResolverTests {
|
|||
public void supports() throws Exception {
|
||||
RequestBodyArgumentResolver resolver = resolver(new StringDecoder());
|
||||
|
||||
assertTrue(resolver.supportsParameter(parameter("monoPojo")));
|
||||
assertTrue(resolver.supportsParameter(parameter("monoTestBean")));
|
||||
assertFalse(resolver.supportsParameter(parameter("paramWithoutAnnotation")));
|
||||
}
|
||||
|
||||
|
|
@ -110,51 +111,51 @@ public class RequestBodyArgumentResolverTests {
|
|||
public void missingContentType() throws Exception {
|
||||
String body = "{\"bar\":\"BARBAR\",\"foo\":\"FOOFOO\"}";
|
||||
this.request.writeWith(Flux.just(dataBuffer(body)));
|
||||
Mono<Object> result = this.resolver.resolveArgument(parameter("monoPojo"), this.model, this.exchange);
|
||||
Mono<Object> result = this.resolver.resolveArgument(parameter("monoTestBean"), this.model, this.exchange);
|
||||
|
||||
TestSubscriber.subscribe(result)
|
||||
.assertError(UnsupportedMediaTypeStatusException.class);
|
||||
}
|
||||
|
||||
@Test @SuppressWarnings("unchecked")
|
||||
public void monoPojo() throws Exception {
|
||||
public void monoTestBean() throws Exception {
|
||||
String body = "{\"bar\":\"b1\",\"foo\":\"f1\"}";
|
||||
Mono<Pojo> mono = (Mono<Pojo>) resolve("monoPojo", Mono.class, body);
|
||||
assertEquals(new Pojo("f1", "b1"), mono.block());
|
||||
Mono<TestBean> mono = (Mono<TestBean>) resolve("monoTestBean", Mono.class, body);
|
||||
assertEquals(new TestBean("f1", "b1"), mono.block());
|
||||
}
|
||||
|
||||
@Test @SuppressWarnings("unchecked")
|
||||
public void fluxPojo() throws Exception {
|
||||
public void fluxTestBean() throws Exception {
|
||||
String body = "[{\"bar\":\"b1\",\"foo\":\"f1\"},{\"bar\":\"b2\",\"foo\":\"f2\"}]";
|
||||
Flux<Pojo> flux = (Flux<Pojo>) resolve("fluxPojo", Flux.class, body);
|
||||
assertEquals(Arrays.asList(new Pojo("f1", "b1"), new Pojo("f2", "b2")), flux.collectList().block());
|
||||
Flux<TestBean> flux = (Flux<TestBean>) resolve("fluxTestBean", Flux.class, body);
|
||||
assertEquals(Arrays.asList(new TestBean("f1", "b1"), new TestBean("f2", "b2")), flux.collectList().block());
|
||||
}
|
||||
|
||||
@Test @SuppressWarnings("unchecked")
|
||||
public void singlePojo() throws Exception {
|
||||
public void singleTestBean() throws Exception {
|
||||
String body = "{\"bar\":\"b1\",\"foo\":\"f1\"}";
|
||||
Single<Pojo> single = (Single<Pojo>) resolve("singlePojo", Single.class, body);
|
||||
assertEquals(new Pojo("f1", "b1"), single.toBlocking().value());
|
||||
Single<TestBean> single = (Single<TestBean>) resolve("singleTestBean", Single.class, body);
|
||||
assertEquals(new TestBean("f1", "b1"), single.toBlocking().value());
|
||||
}
|
||||
|
||||
@Test @SuppressWarnings("unchecked")
|
||||
public void observablePojo() throws Exception {
|
||||
public void observableTestBean() throws Exception {
|
||||
String body = "[{\"bar\":\"b1\",\"foo\":\"f1\"},{\"bar\":\"b2\",\"foo\":\"f2\"}]";
|
||||
Observable<?> observable = (Observable<?>) resolve("observablePojo", Observable.class, body);
|
||||
assertEquals(Arrays.asList(new Pojo("f1", "b1"), new Pojo("f2", "b2")),
|
||||
Observable<?> observable = (Observable<?>) resolve("observableTestBean", Observable.class, body);
|
||||
assertEquals(Arrays.asList(new TestBean("f1", "b1"), new TestBean("f2", "b2")),
|
||||
observable.toList().toBlocking().first());
|
||||
}
|
||||
|
||||
@Test @SuppressWarnings("unchecked")
|
||||
public void futurePojo() throws Exception {
|
||||
public void futureTestBean() throws Exception {
|
||||
String body = "{\"bar\":\"b1\",\"foo\":\"f1\"}";
|
||||
assertEquals(new Pojo("f1", "b1"), resolve("futurePojo", CompletableFuture.class, body).get());
|
||||
assertEquals(new TestBean("f1", "b1"), resolve("futureTestBean", CompletableFuture.class, body).get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pojo() throws Exception {
|
||||
public void testBean() throws Exception {
|
||||
String body = "{\"bar\":\"b1\",\"foo\":\"f1\"}";
|
||||
assertEquals(new Pojo("f1", "b1"), resolve("pojo", Pojo.class, body));
|
||||
assertEquals(new TestBean("f1", "b1"), resolve("testBean", TestBean.class, body));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -172,7 +173,7 @@ public class RequestBodyArgumentResolverTests {
|
|||
@Ignore
|
||||
public void list() throws Exception {
|
||||
String body = "[{\"bar\":\"b1\",\"foo\":\"f1\"},{\"bar\":\"b2\",\"foo\":\"f2\"}]";
|
||||
assertEquals(Arrays.asList(new Pojo("f1", "b1"), new Pojo("f2", "b2")),
|
||||
assertEquals(Arrays.asList(new TestBean("f1", "b1"), new TestBean("f2", "b2")),
|
||||
resolve("list", List.class, body));
|
||||
}
|
||||
|
||||
|
|
@ -180,8 +181,8 @@ public class RequestBodyArgumentResolverTests {
|
|||
@Ignore
|
||||
public void array() throws Exception {
|
||||
String body = "[{\"bar\":\"b1\",\"foo\":\"f1\"},{\"bar\":\"b2\",\"foo\":\"f2\"}]";
|
||||
assertArrayEquals(new Pojo[] {new Pojo("f1", "b1"), new Pojo("f2", "b2")},
|
||||
resolve("array", Pojo[].class, body));
|
||||
assertArrayEquals(new TestBean[] {new TestBean("f1", "b1"), new TestBean("f2", "b2")},
|
||||
resolve("array", TestBean[].class, body));
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -229,17 +230,71 @@ public class RequestBodyArgumentResolverTests {
|
|||
|
||||
@SuppressWarnings("unused")
|
||||
void handle(
|
||||
@RequestBody Mono<Pojo> monoPojo,
|
||||
@RequestBody Flux<Pojo> fluxPojo,
|
||||
@RequestBody Single<Pojo> singlePojo,
|
||||
@RequestBody Observable<Pojo> observablePojo,
|
||||
@RequestBody CompletableFuture<Pojo> futurePojo,
|
||||
@RequestBody Pojo pojo,
|
||||
@RequestBody Mono<TestBean> monoTestBean,
|
||||
@RequestBody Flux<TestBean> fluxTestBean,
|
||||
@RequestBody Single<TestBean> singleTestBean,
|
||||
@RequestBody Observable<TestBean> observableTestBean,
|
||||
@RequestBody CompletableFuture<TestBean> futureTestBean,
|
||||
@RequestBody TestBean testBean,
|
||||
@RequestBody Map<String, String> map,
|
||||
@RequestBody List<Pojo> list,
|
||||
@RequestBody Set<Pojo> set,
|
||||
@RequestBody Pojo[] array,
|
||||
Pojo paramWithoutAnnotation) {
|
||||
@RequestBody List<TestBean> list,
|
||||
@RequestBody Set<TestBean> set,
|
||||
@RequestBody TestBean[] array,
|
||||
TestBean paramWithoutAnnotation) {
|
||||
}
|
||||
|
||||
|
||||
@XmlRootElement
|
||||
static class TestBean {
|
||||
|
||||
private String foo;
|
||||
|
||||
private String bar;
|
||||
|
||||
public TestBean() {
|
||||
}
|
||||
|
||||
public TestBean(String foo, String bar) {
|
||||
this.foo = foo;
|
||||
this.bar = bar;
|
||||
}
|
||||
|
||||
public String getFoo() {
|
||||
return this.foo;
|
||||
}
|
||||
|
||||
public void setFoo(String foo) {
|
||||
this.foo = foo;
|
||||
}
|
||||
|
||||
public String getBar() {
|
||||
return this.bar;
|
||||
}
|
||||
|
||||
public void setBar(String bar) {
|
||||
this.bar = bar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o instanceof TestBean) {
|
||||
TestBean other = (TestBean) o;
|
||||
return this.foo.equals(other.foo) && this.bar.equals(other.bar);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 31 * foo.hashCode() + bar.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TestBean[foo='" + this.foo + "\'" + ", bar='" + this.bar + "\']";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import java.util.Arrays;
|
|||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -33,7 +34,6 @@ import reactor.core.test.TestSubscriber;
|
|||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.codec.support.JacksonJsonEncoder;
|
||||
import org.springframework.core.codec.support.Jaxb2Encoder;
|
||||
import org.springframework.core.codec.support.Pojo;
|
||||
import org.springframework.core.codec.support.StringEncoder;
|
||||
import org.springframework.core.io.buffer.support.DataBufferTestUtils;
|
||||
import org.springframework.http.HttpMethod;
|
||||
|
|
@ -156,8 +156,11 @@ public class HttpMessageConverterViewTests {
|
|||
|
||||
@Test
|
||||
public void render() throws Exception {
|
||||
this.model.addAttribute("pojo", new Pojo("foo", "bar"));
|
||||
this.view.setModelKeys(Collections.singleton("pojo"));
|
||||
Map<String, String> pojoData = new LinkedHashMap<>();
|
||||
pojoData.put("foo", "f");
|
||||
pojoData.put("bar", "b");
|
||||
this.model.addAttribute("pojoData", pojoData);
|
||||
this.view.setModelKeys(Collections.singleton("pojoData"));
|
||||
|
||||
MockServerHttpRequest request = new MockServerHttpRequest(HttpMethod.GET, new URI("/path"));
|
||||
MockServerHttpResponse response = new MockServerHttpResponse();
|
||||
|
|
@ -168,8 +171,9 @@ public class HttpMessageConverterViewTests {
|
|||
|
||||
TestSubscriber
|
||||
.subscribe(response.getBody())
|
||||
.assertValuesWith(buf -> assertEquals("{\"foo\":\"foo\",\"bar\":\"bar\"}",
|
||||
.assertValuesWith(buf -> assertEquals("{\"foo\":\"f\",\"bar\":\"b\"}",
|
||||
DataBufferTestUtils.dumpString(buf, Charset.forName("UTF-8"))));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue