Polishing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -77,10 +77,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Chris Beams
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
public class AspectJAutoProxyCreatorTests {
|
||||
class AspectJAutoProxyCreatorTests {
|
||||
|
||||
@Test
|
||||
public void testAspectsAreApplied() {
|
||||
void aspectsAreApplied() {
|
||||
ClassPathXmlApplicationContext bf = newContext("aspects.xml");
|
||||
|
||||
ITestBean tb = (ITestBean) bf.getBean("adrian");
|
||||
@@ -91,7 +91,7 @@ public class AspectJAutoProxyCreatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleAspectsWithParameterApplied() {
|
||||
void multipleAspectsWithParameterApplied() {
|
||||
ClassPathXmlApplicationContext bf = newContext("aspects.xml");
|
||||
|
||||
ITestBean tb = (ITestBean) bf.getBean("adrian");
|
||||
@@ -100,7 +100,7 @@ public class AspectJAutoProxyCreatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAspectsAreAppliedInDefinedOrder() {
|
||||
void aspectsAreAppliedInDefinedOrder() {
|
||||
ClassPathXmlApplicationContext bf = newContext("aspectsWithOrdering.xml");
|
||||
|
||||
ITestBean tb = (ITestBean) bf.getBean("adrian");
|
||||
@@ -108,7 +108,7 @@ public class AspectJAutoProxyCreatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAspectsAndAdvisorAreApplied() {
|
||||
void aspectsAndAdvisorAreApplied() {
|
||||
ClassPathXmlApplicationContext ac = newContext("aspectsPlusAdvisor.xml");
|
||||
|
||||
ITestBean shouldBeWeaved = (ITestBean) ac.getBean("adrian");
|
||||
@@ -116,7 +116,7 @@ public class AspectJAutoProxyCreatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAspectsAndAdvisorAreAppliedEvenIfComingFromParentFactory() {
|
||||
void aspectsAndAdvisorAreAppliedEvenIfComingFromParentFactory() {
|
||||
ClassPathXmlApplicationContext ac = newContext("aspectsPlusAdvisor.xml");
|
||||
|
||||
GenericApplicationContext childAc = new GenericApplicationContext(ac);
|
||||
@@ -153,7 +153,7 @@ public class AspectJAutoProxyCreatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPerThisAspect() {
|
||||
void perThisAspect() {
|
||||
ClassPathXmlApplicationContext bf = newContext("perthis.xml");
|
||||
|
||||
ITestBean adrian1 = (ITestBean) bf.getBean("adrian");
|
||||
@@ -173,7 +173,7 @@ public class AspectJAutoProxyCreatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPerTargetAspect() throws SecurityException, NoSuchMethodException {
|
||||
void perTargetAspect() throws SecurityException, NoSuchMethodException {
|
||||
ClassPathXmlApplicationContext bf = newContext("pertarget.xml");
|
||||
|
||||
ITestBean adrian1 = (ITestBean) bf.getBean("adrian");
|
||||
@@ -209,7 +209,7 @@ public class AspectJAutoProxyCreatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTwoAdviceAspect() {
|
||||
void twoAdviceAspect() {
|
||||
ClassPathXmlApplicationContext bf = newContext("twoAdviceAspect.xml");
|
||||
|
||||
ITestBean adrian1 = (ITestBean) bf.getBean("adrian");
|
||||
@@ -217,7 +217,7 @@ public class AspectJAutoProxyCreatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTwoAdviceAspectSingleton() {
|
||||
void twoAdviceAspectSingleton() {
|
||||
ClassPathXmlApplicationContext bf = newContext("twoAdviceAspectSingleton.xml");
|
||||
|
||||
ITestBean adrian1 = (ITestBean) bf.getBean("adrian");
|
||||
@@ -228,7 +228,7 @@ public class AspectJAutoProxyCreatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTwoAdviceAspectPrototype() {
|
||||
void twoAdviceAspectPrototype() {
|
||||
ClassPathXmlApplicationContext bf = newContext("twoAdviceAspectPrototype.xml");
|
||||
|
||||
ITestBean adrian1 = (ITestBean) bf.getBean("adrian");
|
||||
@@ -244,13 +244,13 @@ public class AspectJAutoProxyCreatorTests {
|
||||
assertThat(adrian.age()).isEqualTo(start);
|
||||
int newAge = 32;
|
||||
adrian.setAge(newAge);
|
||||
assertThat(adrian.age()).isEqualTo((start + increment));
|
||||
assertThat(adrian.age()).isEqualTo(start + increment);
|
||||
adrian.setAge(0);
|
||||
assertThat(adrian.age()).isEqualTo((start + increment * 2));
|
||||
assertThat(adrian.age()).isEqualTo(start + increment * 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdviceUsingJoinPoint() {
|
||||
void adviceUsingJoinPoint() {
|
||||
ClassPathXmlApplicationContext bf = newContext("usesJoinPointAspect.xml");
|
||||
|
||||
ITestBean adrian1 = (ITestBean) bf.getBean("adrian");
|
||||
@@ -262,7 +262,7 @@ public class AspectJAutoProxyCreatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncludeMechanism() {
|
||||
void includeMechanism() {
|
||||
ClassPathXmlApplicationContext bf = newContext("usesInclude.xml");
|
||||
|
||||
ITestBean adrian = (ITestBean) bf.getBean("adrian");
|
||||
@@ -271,7 +271,7 @@ public class AspectJAutoProxyCreatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForceProxyTargetClass() {
|
||||
void forceProxyTargetClass() {
|
||||
ClassPathXmlApplicationContext bf = newContext("aspectsWithCGLIB.xml");
|
||||
|
||||
ProxyConfig pc = (ProxyConfig) bf.getBean(AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME);
|
||||
@@ -280,7 +280,7 @@ public class AspectJAutoProxyCreatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithAbstractFactoryBeanAreApplied() {
|
||||
void withAbstractFactoryBeanAreApplied() {
|
||||
ClassPathXmlApplicationContext bf = newContext("aspectsWithAbstractBean.xml");
|
||||
|
||||
ITestBean adrian = (ITestBean) bf.getBean("adrian");
|
||||
@@ -289,7 +289,7 @@ public class AspectJAutoProxyCreatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRetryAspect() {
|
||||
void retryAspect() {
|
||||
ClassPathXmlApplicationContext bf = newContext("retryAspect.xml");
|
||||
|
||||
UnreliableBean bean = (UnreliableBean) bf.getBean("unreliableBean");
|
||||
@@ -302,7 +302,7 @@ public class AspectJAutoProxyCreatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithBeanNameAutoProxyCreator() {
|
||||
void withBeanNameAutoProxyCreator() {
|
||||
ClassPathXmlApplicationContext bf = newContext("withBeanNameAutoProxyCreator.xml");
|
||||
|
||||
ITestBean tb = (ITestBean) bf.getBean("adrian");
|
||||
@@ -571,11 +571,11 @@ class RetryAspect {
|
||||
@SuppressWarnings("serial")
|
||||
class RetryableException extends NestedRuntimeException {
|
||||
|
||||
public RetryableException(String msg) {
|
||||
RetryableException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public RetryableException(String msg, Throwable cause) {
|
||||
RetryableException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,6 @@ import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
import okhttp3.mockwebserver.RecordedRequest;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Named;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
@@ -49,9 +48,12 @@ import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.junit.jupiter.api.Named.named;
|
||||
import static org.junit.jupiter.params.provider.Arguments.arguments;
|
||||
|
||||
/**
|
||||
* Unit tests for various {@link Resource} implementations.
|
||||
@@ -67,11 +69,11 @@ class ResourceTests {
|
||||
@MethodSource("resource")
|
||||
void resourceIsValid(Resource resource) throws Exception {
|
||||
assertThat(resource.getFilename()).isEqualTo("Resource.class");
|
||||
assertThat(resource.getURL().getFile().endsWith("Resource.class")).isTrue();
|
||||
assertThat(resource.getURL().getFile()).endsWith("Resource.class");
|
||||
assertThat(resource.exists()).isTrue();
|
||||
assertThat(resource.isReadable()).isTrue();
|
||||
assertThat(resource.contentLength() > 0).isTrue();
|
||||
assertThat(resource.lastModified() > 0).isTrue();
|
||||
assertThat(resource.contentLength()).isGreaterThan(0);
|
||||
assertThat(resource.lastModified()).isGreaterThan(0);
|
||||
assertThat(resource.getContentAsByteArray()).containsExactly(Files.readAllBytes(Path.of(resource.getURI())));
|
||||
}
|
||||
|
||||
@@ -83,8 +85,8 @@ class ResourceTests {
|
||||
assertThat(relative1.getURL().getFile().endsWith("ClassPathResource.class")).isTrue();
|
||||
assertThat(relative1.exists()).isTrue();
|
||||
assertThat(relative1.isReadable()).isTrue();
|
||||
assertThat(relative1.contentLength() > 0).isTrue();
|
||||
assertThat(relative1.lastModified() > 0).isTrue();
|
||||
assertThat(relative1.contentLength()).isGreaterThan(0);
|
||||
assertThat(relative1.lastModified()).isGreaterThan(0);
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{index}: {0}")
|
||||
@@ -92,11 +94,11 @@ class ResourceTests {
|
||||
void resourceCreateRelativeWithFolder(Resource resource) throws Exception {
|
||||
Resource relative2 = resource.createRelative("support/ResourcePatternResolver.class");
|
||||
assertThat(relative2.getFilename()).isEqualTo("ResourcePatternResolver.class");
|
||||
assertThat(relative2.getURL().getFile().endsWith("ResourcePatternResolver.class")).isTrue();
|
||||
assertThat(relative2.getURL().getFile()).endsWith("ResourcePatternResolver.class");
|
||||
assertThat(relative2.exists()).isTrue();
|
||||
assertThat(relative2.isReadable()).isTrue();
|
||||
assertThat(relative2.contentLength() > 0).isTrue();
|
||||
assertThat(relative2.lastModified() > 0).isTrue();
|
||||
assertThat(relative2.contentLength()).isGreaterThan(0);
|
||||
assertThat(relative2.lastModified()).isGreaterThan(0);
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{index}: {0}")
|
||||
@@ -104,11 +106,11 @@ class ResourceTests {
|
||||
void resourceCreateRelativeWithDotPath(Resource resource) throws Exception {
|
||||
Resource relative3 = resource.createRelative("../SpringVersion.class");
|
||||
assertThat(relative3.getFilename()).isEqualTo("SpringVersion.class");
|
||||
assertThat(relative3.getURL().getFile().endsWith("SpringVersion.class")).isTrue();
|
||||
assertThat(relative3.getURL().getFile()).endsWith("SpringVersion.class");
|
||||
assertThat(relative3.exists()).isTrue();
|
||||
assertThat(relative3.isReadable()).isTrue();
|
||||
assertThat(relative3.contentLength() > 0).isTrue();
|
||||
assertThat(relative3.lastModified() > 0).isTrue();
|
||||
assertThat(relative3.contentLength()).isGreaterThan(0);
|
||||
assertThat(relative3.lastModified()).isGreaterThan(0);
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{index}: {0}")
|
||||
@@ -122,21 +124,20 @@ class ResourceTests {
|
||||
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(relative4::getInputStream);
|
||||
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(relative4::readableChannel);
|
||||
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(relative4::getContentAsByteArray);
|
||||
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(
|
||||
() -> relative4.getContentAsString(StandardCharsets.UTF_8));
|
||||
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(() -> relative4.getContentAsString(UTF_8));
|
||||
}
|
||||
|
||||
private static Stream<Arguments> resource() throws URISyntaxException {
|
||||
URL resourceClass = ResourceTests.class.getResource("Resource.class");
|
||||
Path resourceClassFilePath = Paths.get(resourceClass.toURI());
|
||||
return Stream.of(
|
||||
Arguments.of(Named.of("ClassPathResource", new ClassPathResource("org/springframework/core/io/Resource.class"))),
|
||||
Arguments.of(Named.of("ClassPathResource with ClassLoader", new ClassPathResource("org/springframework/core/io/Resource.class", ResourceTests.class.getClassLoader()))),
|
||||
Arguments.of(Named.of("ClassPathResource with Class", new ClassPathResource("Resource.class", ResourceTests.class))),
|
||||
Arguments.of(Named.of("FileSystemResource", new FileSystemResource(resourceClass.getFile()))),
|
||||
Arguments.of(Named.of("FileSystemResource with File", new FileSystemResource(new File(resourceClass.getFile())))),
|
||||
Arguments.of(Named.of("FileSystemResource with File path", new FileSystemResource(resourceClassFilePath))),
|
||||
Arguments.of(Named.of("UrlResource", new UrlResource(resourceClass)))
|
||||
arguments(named("ClassPathResource", new ClassPathResource("org/springframework/core/io/Resource.class"))),
|
||||
arguments(named("ClassPathResource with ClassLoader", new ClassPathResource("org/springframework/core/io/Resource.class", ResourceTests.class.getClassLoader()))),
|
||||
arguments(named("ClassPathResource with Class", new ClassPathResource("Resource.class", ResourceTests.class))),
|
||||
arguments(named("FileSystemResource", new FileSystemResource(resourceClass.getFile()))),
|
||||
arguments(named("FileSystemResource with File", new FileSystemResource(new File(resourceClass.getFile())))),
|
||||
arguments(named("FileSystemResource with File path", new FileSystemResource(resourceClassFilePath))),
|
||||
arguments(named("UrlResource", new UrlResource(resourceClass)))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -258,7 +259,7 @@ class ResourceTests {
|
||||
ByteBuffer buffer = ByteBuffer.allocate((int) resource.contentLength());
|
||||
channel.read(buffer);
|
||||
buffer.rewind();
|
||||
assertThat(buffer.limit() > 0).isTrue();
|
||||
assertThat(buffer.limit()).isGreaterThan(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -621,6 +621,7 @@ class DataBufferTests extends AbstractDataBufferAllocatingTests {
|
||||
buffer.write(new byte[]{'a', 'b', 'c'});
|
||||
buffer.read(); // skip a
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
ByteBuffer result = buffer.toByteBuffer();
|
||||
assertThat(result.capacity()).isEqualTo(2);
|
||||
assertThat(result.remaining()).isEqualTo(2);
|
||||
@@ -639,6 +640,7 @@ class DataBufferTests extends AbstractDataBufferAllocatingTests {
|
||||
DataBuffer buffer = createDataBuffer(3);
|
||||
buffer.write(new byte[]{'a', 'b', 'c'});
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
ByteBuffer result = buffer.toByteBuffer(1, 2);
|
||||
assertThat(result.capacity()).isEqualTo(2);
|
||||
assertThat(result.remaining()).isEqualTo(2);
|
||||
|
||||
@@ -211,6 +211,7 @@ class MetadataEncoderTests {
|
||||
.encode()
|
||||
.block();
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
ByteBuf byteBuf = new NettyDataBufferFactory(ByteBufAllocator.DEFAULT)
|
||||
.wrap(buffer.toByteBuffer())
|
||||
.getNativeBuffer();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -68,7 +68,7 @@ import static org.springframework.http.MediaType.APPLICATION_XML;
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Sebastien Deleuze
|
||||
*/
|
||||
public class RequestMappingMessageConversionIntegrationTests extends AbstractRequestMappingIntegrationTests {
|
||||
class RequestMappingMessageConversionIntegrationTests extends AbstractRequestMappingIntegrationTests {
|
||||
|
||||
private static final ParameterizedTypeReference<List<Person>> PERSON_LIST =
|
||||
new ParameterizedTypeReference<>() {};
|
||||
@@ -78,15 +78,12 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
|
||||
@Override
|
||||
protected ApplicationContext initApplicationContext() {
|
||||
AnnotationConfigApplicationContext wac = new AnnotationConfigApplicationContext();
|
||||
wac.register(WebConfig.class);
|
||||
wac.refresh();
|
||||
return wac;
|
||||
return new AnnotationConfigApplicationContext(WebConfig.class);
|
||||
}
|
||||
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
public void byteBufferResponseBodyWithPublisher(HttpServer httpServer) throws Exception {
|
||||
void byteBufferResponseBodyWithPublisher(HttpServer httpServer) throws Exception {
|
||||
startServer(httpServer);
|
||||
|
||||
Person expected = new Person("Robert");
|
||||
@@ -94,7 +91,7 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
public void byteBufferResponseBodyWithFlux(HttpServer httpServer) throws Exception {
|
||||
void byteBufferResponseBodyWithFlux(HttpServer httpServer) throws Exception {
|
||||
startServer(httpServer);
|
||||
|
||||
String expected = "Hello!";
|
||||
@@ -102,7 +99,7 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
public void byteBufferResponseBodyWithMono(HttpServer httpServer) throws Exception {
|
||||
void byteBufferResponseBodyWithMono(HttpServer httpServer) throws Exception {
|
||||
startServer(httpServer);
|
||||
|
||||
String expected = "Hello!";
|
||||
@@ -112,7 +109,7 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
public void byteBufferResponseBodyWithObservable(HttpServer httpServer) throws Exception {
|
||||
void byteBufferResponseBodyWithObservable(HttpServer httpServer) throws Exception {
|
||||
startServer(httpServer);
|
||||
|
||||
String expected = "Hello!";
|
||||
@@ -121,7 +118,7 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
public void byteBufferResponseBodyWithFlowable(HttpServer httpServer) throws Exception {
|
||||
void byteBufferResponseBodyWithFlowable(HttpServer httpServer) throws Exception {
|
||||
startServer(httpServer);
|
||||
|
||||
String expected = "Hello!";
|
||||
@@ -129,7 +126,7 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
public void personResponseBody(HttpServer httpServer) throws Exception {
|
||||
void personResponseBody(HttpServer httpServer) throws Exception {
|
||||
startServer(httpServer);
|
||||
|
||||
Person expected = new Person("Robert");
|
||||
@@ -139,7 +136,7 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
public void personResponseBodyWithCompletableFuture(HttpServer httpServer) throws Exception {
|
||||
void personResponseBodyWithCompletableFuture(HttpServer httpServer) throws Exception {
|
||||
startServer(httpServer);
|
||||
|
||||
Person expected = new Person("Robert");
|
||||
@@ -149,7 +146,7 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
public void personResponseBodyWithMono(HttpServer httpServer) throws Exception {
|
||||
void personResponseBodyWithMono(HttpServer httpServer) throws Exception {
|
||||
startServer(httpServer);
|
||||
|
||||
Person expected = new Person("Robert");
|
||||
@@ -159,7 +156,7 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest // SPR-17506
|
||||
public void personResponseBodyWithEmptyMono(HttpServer httpServer) throws Exception {
|
||||
void personResponseBodyWithEmptyMono(HttpServer httpServer) throws Exception {
|
||||
startServer(httpServer);
|
||||
|
||||
ResponseEntity<Person> responseEntity = performGet("/person-response/mono-empty", JSON, Person.class);
|
||||
@@ -174,7 +171,7 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
public void personResponseBodyWithMonoDeclaredAsObject(HttpServer httpServer) throws Exception {
|
||||
void personResponseBodyWithMonoDeclaredAsObject(HttpServer httpServer) throws Exception {
|
||||
startServer(httpServer);
|
||||
|
||||
Person expected = new Person("Robert");
|
||||
@@ -184,7 +181,7 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
public void personResponseBodyWithSingle(HttpServer httpServer) throws Exception {
|
||||
void personResponseBodyWithSingle(HttpServer httpServer) throws Exception {
|
||||
startServer(httpServer);
|
||||
|
||||
Person expected = new Person("Robert");
|
||||
@@ -194,7 +191,7 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
public void personResponseBodyWithMonoResponseEntity(HttpServer httpServer) throws Exception {
|
||||
void personResponseBodyWithMonoResponseEntity(HttpServer httpServer) throws Exception {
|
||||
startServer(httpServer);
|
||||
|
||||
Person expected = new Person("Robert");
|
||||
@@ -204,7 +201,7 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest // SPR-16172
|
||||
public void personResponseBodyWithMonoResponseEntityXml(HttpServer httpServer) throws Exception {
|
||||
void personResponseBodyWithMonoResponseEntityXml(HttpServer httpServer) throws Exception {
|
||||
startServer(httpServer);
|
||||
|
||||
|
||||
@@ -218,7 +215,7 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
public void personResponseBodyWithList(HttpServer httpServer) throws Exception {
|
||||
void personResponseBodyWithList(HttpServer httpServer) throws Exception {
|
||||
startServer(httpServer);
|
||||
|
||||
List<?> expected = asList(new Person("Robert"), new Person("Marie"));
|
||||
@@ -228,7 +225,7 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
public void personResponseBodyWithPublisher(HttpServer httpServer) throws Exception {
|
||||
void personResponseBodyWithPublisher(HttpServer httpServer) throws Exception {
|
||||
startServer(httpServer);
|
||||
|
||||
List<?> expected = asList(new Person("Robert"), new Person("Marie"));
|
||||
@@ -238,7 +235,7 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
public void personResponseBodyWithFlux(HttpServer httpServer) throws Exception {
|
||||
void personResponseBodyWithFlux(HttpServer httpServer) throws Exception {
|
||||
startServer(httpServer);
|
||||
|
||||
List<?> expected = asList(new Person("Robert"), new Person("Marie"));
|
||||
@@ -246,7 +243,7 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
public void personResponseBodyWithObservable(HttpServer httpServer) throws Exception {
|
||||
void personResponseBodyWithObservable(HttpServer httpServer) throws Exception {
|
||||
startServer(httpServer);
|
||||
|
||||
List<?> expected = asList(new Person("Robert"), new Person("Marie"));
|
||||
@@ -254,7 +251,7 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
public void resource(HttpServer httpServer) throws Exception {
|
||||
void resource(HttpServer httpServer) throws Exception {
|
||||
startServer(httpServer);
|
||||
|
||||
ResponseEntity<byte[]> response = performGet("/resource", new HttpHeaders(), byte[].class);
|
||||
@@ -267,7 +264,7 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
public void personTransform(HttpServer httpServer) throws Exception {
|
||||
void personTransform(HttpServer httpServer) throws Exception {
|
||||
startServer(httpServer);
|
||||
|
||||
assertThat(performPost("/person-transform/person", JSON, new Person("Robert"),
|
||||
@@ -275,7 +272,7 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
public void personTransformWithCompletableFuture(HttpServer httpServer) throws Exception {
|
||||
void personTransformWithCompletableFuture(HttpServer httpServer) throws Exception {
|
||||
startServer(httpServer);
|
||||
|
||||
assertThat(performPost("/person-transform/completable-future", JSON, new Person("Robert"),
|
||||
@@ -283,7 +280,7 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
public void personTransformWithMono(HttpServer httpServer) throws Exception {
|
||||
void personTransformWithMono(HttpServer httpServer) throws Exception {
|
||||
startServer(httpServer);
|
||||
|
||||
assertThat(performPost("/person-transform/mono", JSON, new Person("Robert"),
|
||||
@@ -291,7 +288,7 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest // SPR-16759
|
||||
public void personTransformWithMonoAndXml(HttpServer httpServer) throws Exception {
|
||||
void personTransformWithMonoAndXml(HttpServer httpServer) throws Exception {
|
||||
startServer(httpServer);
|
||||
|
||||
assertThat(performPost("/person-transform/mono", MediaType.APPLICATION_XML, new Person("Robert"),
|
||||
@@ -299,7 +296,7 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
public void personTransformWithSingle(HttpServer httpServer) throws Exception {
|
||||
void personTransformWithSingle(HttpServer httpServer) throws Exception {
|
||||
startServer(httpServer);
|
||||
|
||||
assertThat(performPost("/person-transform/single", JSON, new Person("Robert"),
|
||||
@@ -307,7 +304,7 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
public void personTransformWithMaybe(HttpServer httpServer) throws Exception {
|
||||
void personTransformWithMaybe(HttpServer httpServer) throws Exception {
|
||||
startServer(httpServer);
|
||||
|
||||
assertThat(performPost("/person-transform/maybe", JSON, new Person("Robert"),
|
||||
@@ -315,7 +312,7 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
public void personTransformWithPublisher(HttpServer httpServer) throws Exception {
|
||||
void personTransformWithPublisher(HttpServer httpServer) throws Exception {
|
||||
startServer(httpServer);
|
||||
|
||||
List<?> req = asList(new Person("Robert"), new Person("Marie"));
|
||||
@@ -324,7 +321,7 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
public void personTransformWithFlux(HttpServer httpServer) throws Exception {
|
||||
void personTransformWithFlux(HttpServer httpServer) throws Exception {
|
||||
startServer(httpServer);
|
||||
|
||||
List<?> req = asList(new Person("Robert"), new Person("Marie"));
|
||||
@@ -333,7 +330,7 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
public void personTransformWithObservable(HttpServer httpServer) throws Exception {
|
||||
void personTransformWithObservable(HttpServer httpServer) throws Exception {
|
||||
startServer(httpServer);
|
||||
|
||||
List<?> req = asList(new Person("Robert"), new Person("Marie"));
|
||||
@@ -342,7 +339,7 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
public void personTransformWithFlowable(HttpServer httpServer) throws Exception {
|
||||
void personTransformWithFlowable(HttpServer httpServer) throws Exception {
|
||||
startServer(httpServer);
|
||||
|
||||
List<?> req = asList(new Person("Robert"), new Person("Marie"));
|
||||
@@ -351,7 +348,7 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
public void personCreateWithPublisherJson(HttpServer httpServer) throws Exception {
|
||||
void personCreateWithPublisherJson(HttpServer httpServer) throws Exception {
|
||||
startServer(httpServer);
|
||||
|
||||
ResponseEntity<Void> entity = performPost("/person-create/publisher", JSON,
|
||||
@@ -362,7 +359,7 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
public void personCreateWithPublisherXml(HttpServer httpServer) throws Exception {
|
||||
void personCreateWithPublisherXml(HttpServer httpServer) throws Exception {
|
||||
startServer(httpServer);
|
||||
|
||||
People people = new People(new Person("Robert"), new Person("Marie"));
|
||||
@@ -373,7 +370,7 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
public void personCreateWithMono(HttpServer httpServer) throws Exception {
|
||||
void personCreateWithMono(HttpServer httpServer) throws Exception {
|
||||
startServer(httpServer);
|
||||
|
||||
ResponseEntity<Void> entity = performPost(
|
||||
@@ -384,7 +381,7 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
public void personCreateWithSingle(HttpServer httpServer) throws Exception {
|
||||
void personCreateWithSingle(HttpServer httpServer) throws Exception {
|
||||
startServer(httpServer);
|
||||
|
||||
ResponseEntity<Void> entity = performPost(
|
||||
@@ -395,7 +392,7 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
public void personCreateWithFluxJson(HttpServer httpServer) throws Exception {
|
||||
void personCreateWithFluxJson(HttpServer httpServer) throws Exception {
|
||||
startServer(httpServer);
|
||||
|
||||
ResponseEntity<Void> entity = performPost("/person-create/flux", JSON,
|
||||
@@ -406,7 +403,7 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
public void personCreateWithFluxXml(HttpServer httpServer) throws Exception {
|
||||
void personCreateWithFluxXml(HttpServer httpServer) throws Exception {
|
||||
startServer(httpServer);
|
||||
|
||||
People people = new People(new Person("Robert"), new Person("Marie"));
|
||||
@@ -417,7 +414,7 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
public void personCreateWithObservableJson(HttpServer httpServer) throws Exception {
|
||||
void personCreateWithObservableJson(HttpServer httpServer) throws Exception {
|
||||
startServer(httpServer);
|
||||
|
||||
ResponseEntity<Void> entity = performPost("/person-create/observable", JSON,
|
||||
@@ -428,7 +425,7 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
public void personCreateWithObservableXml(HttpServer httpServer) throws Exception {
|
||||
void personCreateWithObservableXml(HttpServer httpServer) throws Exception {
|
||||
startServer(httpServer);
|
||||
|
||||
People people = new People(new Person("Robert"), new Person("Marie"));
|
||||
@@ -439,7 +436,7 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
public void personCreateWithFlowableJson(HttpServer httpServer) throws Exception {
|
||||
void personCreateWithFlowableJson(HttpServer httpServer) throws Exception {
|
||||
startServer(httpServer);
|
||||
|
||||
ResponseEntity<Void> entity = performPost("/person-create/flowable", JSON,
|
||||
@@ -450,7 +447,7 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
public void personCreateWithFlowableXml(HttpServer httpServer) throws Exception {
|
||||
void personCreateWithFlowableXml(HttpServer httpServer) throws Exception {
|
||||
startServer(httpServer);
|
||||
|
||||
People people = new People(new Person("Robert"), new Person("Marie"));
|
||||
@@ -461,7 +458,7 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest // gh-23791
|
||||
public void personCreateViaDefaultMethodWithGenerics(HttpServer httpServer) throws Exception {
|
||||
void personCreateViaDefaultMethodWithGenerics(HttpServer httpServer) throws Exception {
|
||||
startServer(httpServer);
|
||||
ResponseEntity<String> entity = performPost("/23791", JSON, new Person("Robert"), null, String.class);
|
||||
|
||||
@@ -484,29 +481,30 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
private static class RawResponseBodyController {
|
||||
|
||||
@GetMapping("/publisher")
|
||||
public Publisher<ByteBuffer> getPublisher() {
|
||||
@SuppressWarnings("deprecation")
|
||||
Publisher<ByteBuffer> getPublisher() {
|
||||
Jackson2JsonEncoder encoder = new Jackson2JsonEncoder();
|
||||
return encoder.encode(Mono.just(new Person("Robert")), DefaultDataBufferFactory.sharedInstance,
|
||||
ResolvableType.forClass(Person.class), JSON, Collections.emptyMap()).map(DataBuffer::toByteBuffer);
|
||||
}
|
||||
|
||||
@GetMapping("/flux")
|
||||
public Flux<ByteBuffer> getFlux() {
|
||||
Flux<ByteBuffer> getFlux() {
|
||||
return Flux.just(ByteBuffer.wrap("Hello!".getBytes()));
|
||||
}
|
||||
|
||||
@GetMapping("/mono")
|
||||
public Mono<ByteBuffer> getMonoString() {
|
||||
Mono<ByteBuffer> getMonoString() {
|
||||
return Mono.just(ByteBuffer.wrap("Hello!".getBytes()));
|
||||
}
|
||||
|
||||
@GetMapping("/observable")
|
||||
public Observable<ByteBuffer> getObservable() {
|
||||
Observable<ByteBuffer> getObservable() {
|
||||
return Observable.just(ByteBuffer.wrap("Hello!".getBytes()));
|
||||
}
|
||||
|
||||
@GetMapping("/flowable")
|
||||
public Flowable<ByteBuffer> getFlowable() {
|
||||
Flowable<ByteBuffer> getFlowable() {
|
||||
return Flowable.just(ByteBuffer.wrap("Hello!".getBytes()));
|
||||
}
|
||||
}
|
||||
@@ -518,64 +516,64 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
private static class PersonResponseBodyController {
|
||||
|
||||
@GetMapping("/person")
|
||||
public Person getPerson() {
|
||||
Person getPerson() {
|
||||
return new Person("Robert");
|
||||
}
|
||||
|
||||
@GetMapping("/completable-future")
|
||||
public CompletableFuture<Person> getCompletableFuture() {
|
||||
CompletableFuture<Person> getCompletableFuture() {
|
||||
return CompletableFuture.completedFuture(new Person("Robert"));
|
||||
}
|
||||
|
||||
@GetMapping("/mono")
|
||||
public Mono<Person> getMono() {
|
||||
Mono<Person> getMono() {
|
||||
return Mono.just(new Person("Robert"));
|
||||
}
|
||||
|
||||
@GetMapping("/mono-empty")
|
||||
public Mono<Person> getMonoEmpty() {
|
||||
Mono<Person> getMonoEmpty() {
|
||||
return Mono.empty();
|
||||
}
|
||||
|
||||
@GetMapping("/mono-declared-as-object")
|
||||
public Object getMonoDeclaredAsObject() {
|
||||
Object getMonoDeclaredAsObject() {
|
||||
return Mono.just(new Person("Robert"));
|
||||
}
|
||||
|
||||
@GetMapping("/single")
|
||||
public Single<Person> getSingle() {
|
||||
Single<Person> getSingle() {
|
||||
return Single.just(new Person("Robert"));
|
||||
}
|
||||
|
||||
@GetMapping("/mono-response-entity")
|
||||
public ResponseEntity<Mono<Person>> getMonoResponseEntity() {
|
||||
ResponseEntity<Mono<Person>> getMonoResponseEntity() {
|
||||
Mono<Person> body = Mono.just(new Person("Robert"));
|
||||
return ResponseEntity.ok(body);
|
||||
}
|
||||
|
||||
@GetMapping("/mono-response-entity-xml")
|
||||
public ResponseEntity<Mono<Person>> getMonoResponseEntityXml() {
|
||||
ResponseEntity<Mono<Person>> getMonoResponseEntityXml() {
|
||||
Mono<Person> body = Mono.just(new Person("Robert"));
|
||||
return ResponseEntity.ok().contentType(MediaType.APPLICATION_XML).body(body);
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
public List<Person> getList() {
|
||||
List<Person> getList() {
|
||||
return asList(new Person("Robert"), new Person("Marie"));
|
||||
}
|
||||
|
||||
@GetMapping("/publisher")
|
||||
public Publisher<Person> getPublisher() {
|
||||
Publisher<Person> getPublisher() {
|
||||
return Flux.just(new Person("Robert"), new Person("Marie"));
|
||||
}
|
||||
|
||||
@GetMapping("/flux")
|
||||
public Flux<Person> getFlux() {
|
||||
Flux<Person> getFlux() {
|
||||
return Flux.just(new Person("Robert"), new Person("Marie"));
|
||||
}
|
||||
|
||||
@GetMapping("/observable")
|
||||
public Observable<Person> getObservable() {
|
||||
Observable<Person> getObservable() {
|
||||
return Observable.just(new Person("Robert"), new Person("Marie"));
|
||||
}
|
||||
}
|
||||
@@ -586,7 +584,7 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
private static class ResourceController {
|
||||
|
||||
@GetMapping("/resource")
|
||||
public Resource resource() {
|
||||
Resource resource() {
|
||||
return new ClassPathResource("/org/springframework/web/reactive/spring.png");
|
||||
}
|
||||
}
|
||||
@@ -598,47 +596,47 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
private static class PersonTransformationController {
|
||||
|
||||
@PostMapping("/person")
|
||||
public Person transformPerson(@RequestBody Person person) {
|
||||
Person transformPerson(@RequestBody Person person) {
|
||||
return new Person(person.getName().toUpperCase());
|
||||
}
|
||||
|
||||
@PostMapping("/completable-future")
|
||||
public CompletableFuture<Person> transformCompletableFuture(@RequestBody CompletableFuture<Person> future) {
|
||||
CompletableFuture<Person> transformCompletableFuture(@RequestBody CompletableFuture<Person> future) {
|
||||
return future.thenApply(person -> new Person(person.getName().toUpperCase()));
|
||||
}
|
||||
|
||||
@PostMapping("/mono")
|
||||
public Mono<Person> transformMono(@RequestBody Mono<Person> personFuture) {
|
||||
Mono<Person> transformMono(@RequestBody Mono<Person> personFuture) {
|
||||
return personFuture.map(person -> new Person(person.getName().toUpperCase()));
|
||||
}
|
||||
|
||||
@PostMapping("/single")
|
||||
public Single<Person> transformSingle(@RequestBody Single<Person> personFuture) {
|
||||
Single<Person> transformSingle(@RequestBody Single<Person> personFuture) {
|
||||
return personFuture.map(person -> new Person(person.getName().toUpperCase()));
|
||||
}
|
||||
|
||||
@PostMapping("/maybe")
|
||||
public Maybe<Person> transformMaybe(@RequestBody Maybe<Person> personFuture) {
|
||||
Maybe<Person> transformMaybe(@RequestBody Maybe<Person> personFuture) {
|
||||
return personFuture.map(person -> new Person(person.getName().toUpperCase()));
|
||||
}
|
||||
|
||||
@PostMapping("/publisher")
|
||||
public Publisher<Person> transformPublisher(@RequestBody Publisher<Person> persons) {
|
||||
Publisher<Person> transformPublisher(@RequestBody Publisher<Person> persons) {
|
||||
return Flux.from(persons).map(person -> new Person(person.getName().toUpperCase()));
|
||||
}
|
||||
|
||||
@PostMapping("/flux")
|
||||
public Flux<Person> transformFlux(@RequestBody Flux<Person> persons) {
|
||||
Flux<Person> transformFlux(@RequestBody Flux<Person> persons) {
|
||||
return persons.map(person -> new Person(person.getName().toUpperCase()));
|
||||
}
|
||||
|
||||
@PostMapping("/observable")
|
||||
public Observable<Person> transformObservable(@RequestBody Observable<Person> persons) {
|
||||
Observable<Person> transformObservable(@RequestBody Observable<Person> persons) {
|
||||
return persons.map(person -> new Person(person.getName().toUpperCase()));
|
||||
}
|
||||
|
||||
@PostMapping("/flowable")
|
||||
public Flowable<Person> transformFlowable(@RequestBody Flowable<Person> persons) {
|
||||
Flowable<Person> transformFlowable(@RequestBody Flowable<Person> persons) {
|
||||
return persons.map(person -> new Person(person.getName().toUpperCase()));
|
||||
}
|
||||
}
|
||||
@@ -652,32 +650,32 @@ public class RequestMappingMessageConversionIntegrationTests extends AbstractReq
|
||||
final List<Person> persons = new ArrayList<>();
|
||||
|
||||
@PostMapping("/publisher")
|
||||
public Publisher<Void> createWithPublisher(@RequestBody Publisher<Person> publisher) {
|
||||
Publisher<Void> createWithPublisher(@RequestBody Publisher<Person> publisher) {
|
||||
return Flux.from(publisher).doOnNext(persons::add).then();
|
||||
}
|
||||
|
||||
@PostMapping("/mono")
|
||||
public Mono<Void> createWithMono(@RequestBody Mono<Person> mono) {
|
||||
Mono<Void> createWithMono(@RequestBody Mono<Person> mono) {
|
||||
return mono.doOnNext(persons::add).then();
|
||||
}
|
||||
|
||||
@PostMapping("/single")
|
||||
public Completable createWithSingle(@RequestBody Single<Person> single) {
|
||||
Completable createWithSingle(@RequestBody Single<Person> single) {
|
||||
return single.map(persons::add).ignoreElement();
|
||||
}
|
||||
|
||||
@PostMapping("/flux")
|
||||
public Mono<Void> createWithFlux(@RequestBody Flux<Person> flux) {
|
||||
Mono<Void> createWithFlux(@RequestBody Flux<Person> flux) {
|
||||
return flux.doOnNext(persons::add).then();
|
||||
}
|
||||
|
||||
@PostMapping("/observable")
|
||||
public Completable createWithObservable(@RequestBody Observable<Person> observable) {
|
||||
Completable createWithObservable(@RequestBody Observable<Person> observable) {
|
||||
return observable.toList().doOnSuccess(persons::addAll).ignoreElement();
|
||||
}
|
||||
|
||||
@PostMapping("/flowable")
|
||||
public Completable createWithFlowable(@RequestBody Flowable<Person> flowable) {
|
||||
Completable createWithFlowable(@RequestBody Flowable<Person> flowable) {
|
||||
return flowable.toList().doOnSuccess(persons::addAll).ignoreElement();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -48,12 +48,14 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
public class FreeMarkerViewTests {
|
||||
class FreeMarkerViewTests {
|
||||
|
||||
private static final String TEMPLATE_PATH =
|
||||
"classpath*:org/springframework/web/reactive/view/freemarker/";
|
||||
|
||||
|
||||
private final FreeMarkerView freeMarkerView = new FreeMarkerView();
|
||||
|
||||
private final MockServerWebExchange exchange =
|
||||
MockServerWebExchange.from(MockServerHttpRequest.get("/path"));
|
||||
|
||||
@@ -63,7 +65,7 @@ public class FreeMarkerViewTests {
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() throws Exception {
|
||||
void setup() throws Exception {
|
||||
this.context.refresh();
|
||||
|
||||
FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
|
||||
@@ -75,42 +77,39 @@ public class FreeMarkerViewTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void noFreeMarkerConfig() throws Exception {
|
||||
FreeMarkerView view = new FreeMarkerView();
|
||||
view.setApplicationContext(this.context);
|
||||
view.setUrl("anythingButNull");
|
||||
void noFreeMarkerConfig() {
|
||||
freeMarkerView.setApplicationContext(this.context);
|
||||
freeMarkerView.setUrl("anythingButNull");
|
||||
|
||||
assertThatExceptionOfType(ApplicationContextException.class)
|
||||
.isThrownBy(view::afterPropertiesSet)
|
||||
.isThrownBy(freeMarkerView::afterPropertiesSet)
|
||||
.withMessageContaining("Must define a single FreeMarkerConfig bean");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noTemplateName() throws Exception {
|
||||
FreeMarkerView freeMarkerView = new FreeMarkerView();
|
||||
void noTemplateName() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(freeMarkerView::afterPropertiesSet)
|
||||
.withMessageContaining("Property 'url' is required");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkResourceExists() throws Exception {
|
||||
FreeMarkerView view = new FreeMarkerView();
|
||||
view.setConfiguration(this.freeMarkerConfig);
|
||||
view.setUrl("test.ftl");
|
||||
void checkResourceExists() throws Exception {
|
||||
freeMarkerView.setConfiguration(this.freeMarkerConfig);
|
||||
freeMarkerView.setUrl("test.ftl");
|
||||
|
||||
assertThat(view.checkResourceExists(Locale.US)).isTrue();
|
||||
assertThat(freeMarkerView.checkResourceExists(Locale.US)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void render() {
|
||||
FreeMarkerView view = new FreeMarkerView();
|
||||
view.setApplicationContext(this.context);
|
||||
view.setConfiguration(this.freeMarkerConfig);
|
||||
view.setUrl("test.ftl");
|
||||
void render() {
|
||||
freeMarkerView.setApplicationContext(this.context);
|
||||
freeMarkerView.setConfiguration(this.freeMarkerConfig);
|
||||
freeMarkerView.setUrl("test.ftl");
|
||||
|
||||
ModelMap model = new ExtendedModelMap();
|
||||
model.addAttribute("hello", "hi FreeMarker");
|
||||
view.render(model, null, this.exchange).block(Duration.ofMillis(5000));
|
||||
freeMarkerView.render(model, null, this.exchange).block(Duration.ofMillis(5000));
|
||||
|
||||
StepVerifier.create(this.exchange.getResponse().getBody())
|
||||
.consumeNextWith(buf -> assertThat(asString(buf)).isEqualTo("<html><body>hi FreeMarker</body></html>"))
|
||||
@@ -119,21 +118,20 @@ public class FreeMarkerViewTests {
|
||||
}
|
||||
|
||||
@Test // gh-22754
|
||||
public void subscribeWithoutDemand() {
|
||||
void subscribeWithoutDemand() {
|
||||
ZeroDemandResponse response = new ZeroDemandResponse();
|
||||
ServerWebExchange exchange = new DefaultServerWebExchange(
|
||||
MockServerHttpRequest.get("/path").build(), response,
|
||||
new DefaultWebSessionManager(), ServerCodecConfigurer.create(),
|
||||
new AcceptHeaderLocaleContextResolver());
|
||||
|
||||
FreeMarkerView view = new FreeMarkerView();
|
||||
view.setApplicationContext(this.context);
|
||||
view.setConfiguration(this.freeMarkerConfig);
|
||||
view.setUrl("test.ftl");
|
||||
freeMarkerView.setApplicationContext(this.context);
|
||||
freeMarkerView.setConfiguration(this.freeMarkerConfig);
|
||||
freeMarkerView.setUrl("test.ftl");
|
||||
|
||||
ModelMap model = new ExtendedModelMap();
|
||||
model.addAttribute("hello", "hi FreeMarker");
|
||||
view.render(model, null, exchange).subscribe();
|
||||
freeMarkerView.render(model, null, exchange).subscribe();
|
||||
|
||||
response.cancelWrite();
|
||||
response.checkForLeaks();
|
||||
@@ -141,8 +139,9 @@ public class FreeMarkerViewTests {
|
||||
|
||||
|
||||
private static String asString(DataBuffer dataBuffer) {
|
||||
@SuppressWarnings("deprecation")
|
||||
ByteBuffer byteBuffer = dataBuffer.toByteBuffer();
|
||||
final byte[] bytes = new byte[byteBuffer.remaining()];
|
||||
byte[] bytes = new byte[byteBuffer.remaining()];
|
||||
byteBuffer.get(bytes);
|
||||
return new String(bytes, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ import org.springframework.web.testfixture.servlet.MockServletContext;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.assertj.core.api.InstanceOfAssertFactories.type;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
@@ -55,36 +56,36 @@ import static org.mockito.Mockito.mock;
|
||||
* @author Sam Brannen
|
||||
* @since 14.03.2004
|
||||
*/
|
||||
public class FreeMarkerViewTests {
|
||||
class FreeMarkerViewTests {
|
||||
|
||||
private static final String TEMPLATE_NAME = "templateName";
|
||||
|
||||
|
||||
private final FreeMarkerView freeMarkerView = new FreeMarkerView();
|
||||
|
||||
|
||||
@Test
|
||||
public void noFreeMarkerConfig() throws Exception {
|
||||
FreeMarkerView fv = new FreeMarkerView();
|
||||
|
||||
void noFreeMarkerConfig() {
|
||||
WebApplicationContext wac = mock();
|
||||
given(wac.getBeansOfType(FreeMarkerConfig.class, true, false)).willReturn(new HashMap<>());
|
||||
given(wac.getServletContext()).willReturn(new MockServletContext());
|
||||
|
||||
fv.setUrl("anythingButNull");
|
||||
freeMarkerView.setUrl("anythingButNull");
|
||||
|
||||
assertThatExceptionOfType(ApplicationContextException.class).isThrownBy(() ->
|
||||
fv.setApplicationContext(wac))
|
||||
.withMessageContaining("FreeMarkerConfig");
|
||||
assertThatExceptionOfType(ApplicationContextException.class)
|
||||
.isThrownBy(() -> freeMarkerView.setApplicationContext(wac))
|
||||
.withMessageContaining("Must define a single FreeMarkerConfig bean");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noTemplateName() throws Exception {
|
||||
FreeMarkerView fv = new FreeMarkerView();
|
||||
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
fv.afterPropertiesSet())
|
||||
.withMessageContaining("url");
|
||||
void noTemplateName() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(freeMarkerView::afterPropertiesSet)
|
||||
.withMessageContaining("Property 'url' is required");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validTemplateName() throws Exception {
|
||||
FreeMarkerView fv = new FreeMarkerView();
|
||||
|
||||
void validTemplateName() throws Exception {
|
||||
WebApplicationContext wac = mock();
|
||||
MockServletContext sc = new MockServletContext();
|
||||
|
||||
@@ -95,8 +96,8 @@ public class FreeMarkerViewTests {
|
||||
given(wac.getBeansOfType(FreeMarkerConfig.class, true, false)).willReturn(configs);
|
||||
given(wac.getServletContext()).willReturn(sc);
|
||||
|
||||
fv.setUrl("templateName");
|
||||
fv.setApplicationContext(wac);
|
||||
freeMarkerView.setUrl(TEMPLATE_NAME);
|
||||
freeMarkerView.setApplicationContext(wac);
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.addPreferredLocale(Locale.US);
|
||||
@@ -104,17 +105,14 @@ public class FreeMarkerViewTests {
|
||||
request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
|
||||
HttpServletResponse response = new MockHttpServletResponse();
|
||||
|
||||
Map<String, Object> model = new HashMap<>();
|
||||
model.put("myattr", "myvalue");
|
||||
fv.render(model, request, response);
|
||||
Map<String, Object> model = Map.of("myattr", "myvalue");
|
||||
freeMarkerView.render(model, request, response);
|
||||
|
||||
assertThat(response.getContentType()).isEqualTo(AbstractView.DEFAULT_CONTENT_TYPE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void keepExistingContentType() throws Exception {
|
||||
FreeMarkerView fv = new FreeMarkerView();
|
||||
|
||||
void keepExistingContentType() throws Exception {
|
||||
WebApplicationContext wac = mock();
|
||||
MockServletContext sc = new MockServletContext();
|
||||
|
||||
@@ -125,8 +123,8 @@ public class FreeMarkerViewTests {
|
||||
given(wac.getBeansOfType(FreeMarkerConfig.class, true, false)).willReturn(configs);
|
||||
given(wac.getServletContext()).willReturn(sc);
|
||||
|
||||
fv.setUrl("templateName");
|
||||
fv.setApplicationContext(wac);
|
||||
freeMarkerView.setUrl(TEMPLATE_NAME);
|
||||
freeMarkerView.setApplicationContext(wac);
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.addPreferredLocale(Locale.US);
|
||||
@@ -135,17 +133,14 @@ public class FreeMarkerViewTests {
|
||||
HttpServletResponse response = new MockHttpServletResponse();
|
||||
response.setContentType("myContentType");
|
||||
|
||||
Map<String, Object> model = new HashMap<>();
|
||||
model.put("myattr", "myvalue");
|
||||
fv.render(model, request, response);
|
||||
Map<String, Object> model = Map.of("myattr", "myvalue");
|
||||
freeMarkerView.render(model, request, response);
|
||||
|
||||
assertThat(response.getContentType()).isEqualTo("myContentType");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestAttributeVisible() throws Exception {
|
||||
FreeMarkerView fv = new FreeMarkerView();
|
||||
|
||||
void requestAttributeVisible() throws Exception {
|
||||
WebApplicationContext wac = mock();
|
||||
MockServletContext sc = new MockServletContext();
|
||||
|
||||
@@ -156,8 +151,8 @@ public class FreeMarkerViewTests {
|
||||
given(wac.getBeansOfType(FreeMarkerConfig.class, true, false)).willReturn(configs);
|
||||
given(wac.getServletContext()).willReturn(sc);
|
||||
|
||||
fv.setUrl("templateName");
|
||||
fv.setApplicationContext(wac);
|
||||
freeMarkerView.setUrl(TEMPLATE_NAME);
|
||||
freeMarkerView.setApplicationContext(wac);
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.addPreferredLocale(Locale.US);
|
||||
@@ -166,11 +161,11 @@ public class FreeMarkerViewTests {
|
||||
HttpServletResponse response = new MockHttpServletResponse();
|
||||
|
||||
request.setAttribute("myattr", "myvalue");
|
||||
fv.render(null, request, response);
|
||||
freeMarkerView.render(null, request, response);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void freeMarkerViewResolver() throws Exception {
|
||||
void freeMarkerViewResolver() throws Exception {
|
||||
MockServletContext sc = new MockServletContext();
|
||||
|
||||
FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
|
||||
@@ -181,23 +176,26 @@ public class FreeMarkerViewTests {
|
||||
wac.getBeanFactory().registerSingleton("configurer", configurer);
|
||||
wac.refresh();
|
||||
|
||||
FreeMarkerViewResolver vr = new FreeMarkerViewResolver("prefix_", "_suffix");
|
||||
FreeMarkerViewResolver vr = new FreeMarkerViewResolver("templates/", ".ftl");
|
||||
vr.setApplicationContext(wac);
|
||||
|
||||
View view = vr.resolveViewName("test", Locale.CANADA);
|
||||
assertThat(view.getClass()).as("Correct view class").isEqualTo(FreeMarkerView.class);
|
||||
assertThat(((FreeMarkerView) view).getUrl()).as("Correct URL").isEqualTo("prefix_test_suffix");
|
||||
assertThat(view).asInstanceOf(type(FreeMarkerView.class))
|
||||
.extracting(FreeMarkerView::getUrl)
|
||||
.isEqualTo("templates/test.ftl");
|
||||
|
||||
view = vr.resolveViewName("non-existing", Locale.CANADA);
|
||||
assertThat(view).isNull();
|
||||
|
||||
view = vr.resolveViewName("redirect:myUrl", Locale.getDefault());
|
||||
assertThat(view.getClass()).as("Correct view class").isEqualTo(RedirectView.class);
|
||||
assertThat(((RedirectView) view).getUrl()).as("Correct URL").isEqualTo("myUrl");
|
||||
view = vr.resolveViewName("redirect:myRedirectUrl", Locale.getDefault());
|
||||
assertThat(view).asInstanceOf(type(RedirectView.class))
|
||||
.extracting(RedirectView::getUrl)
|
||||
.isEqualTo("myRedirectUrl");
|
||||
|
||||
view = vr.resolveViewName("forward:myUrl", Locale.getDefault());
|
||||
assertThat(view.getClass()).as("Correct view class").isEqualTo(InternalResourceView.class);
|
||||
assertThat(((InternalResourceView) view).getUrl()).as("Correct URL").isEqualTo("myUrl");
|
||||
view = vr.resolveViewName("forward:myForwardUrl", Locale.getDefault());
|
||||
assertThat(view).asInstanceOf(type(InternalResourceView.class))
|
||||
.extracting(InternalResourceView::getUrl)
|
||||
.isEqualTo("myForwardUrl");
|
||||
}
|
||||
|
||||
|
||||
@@ -209,14 +207,13 @@ public class FreeMarkerViewTests {
|
||||
|
||||
@Override
|
||||
public Template getTemplate(String name, final Locale locale) throws IOException {
|
||||
if (name.equals("templateName") || name.equals("prefix_test_suffix")) {
|
||||
if (name.equals(TEMPLATE_NAME) || name.equals("templates/test.ftl")) {
|
||||
return new Template(name, new StringReader("test"), this) {
|
||||
@Override
|
||||
public void process(Object model, Writer writer) throws TemplateException, IOException {
|
||||
assertThat(locale).isEqualTo(Locale.US);
|
||||
assertThat(model instanceof SimpleHash).isTrue();
|
||||
SimpleHash fmModel = (SimpleHash) model;
|
||||
assertThat(String.valueOf(fmModel.get("myattr"))).isEqualTo("myvalue");
|
||||
assertThat(model).asInstanceOf(type(SimpleHash.class)).satisfies(
|
||||
fmModel -> assertThat(fmModel.get("myattr")).asString().isEqualTo("myvalue"));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user