Migrate rest of test suite from JUnit 4 to JUnit Jupiter

This commit migrates the rest of Spring's test suite to JUnit Jupiter,
except spring-test which will be migrated in a separate commit.

See gh-23451
This commit is contained in:
Sam Brannen
2019-08-13 12:57:37 +02:00
parent 3df85c783f
commit 3f3e41923f
1487 changed files with 5428 additions and 4782 deletions

View File

@@ -21,8 +21,8 @@ import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
@@ -67,7 +67,7 @@ public class DispatcherHandlerErrorTests {
private DispatcherHandler dispatcherHandler;
@Before
@BeforeEach
public void setup() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(TestConfig.class);

View File

@@ -20,7 +20,7 @@ import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.function.Supplier;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import org.springframework.context.support.StaticApplicationContext;

View File

@@ -19,8 +19,6 @@ package org.springframework.web.reactive;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import org.junit.Before;
import org.junit.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
@@ -30,6 +28,7 @@ import org.springframework.http.server.reactive.AbstractHttpHandlerIntegrationTe
import org.springframework.http.server.reactive.HttpHandler;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.http.server.reactive.bootstrap.HttpServer;
import org.springframework.web.reactive.function.client.WebClient;
import static org.assertj.core.api.Assertions.assertThat;
@@ -39,22 +38,25 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Sebastien Deleuze
* @author Rossen Stoyanchev
* @author Sam Brannen
* @since 5.0
*/
public class FlushingIntegrationTests extends AbstractHttpHandlerIntegrationTests {
class FlushingIntegrationTests extends AbstractHttpHandlerIntegrationTests {
private WebClient webClient;
@Before
public void setup() throws Exception {
super.setup();
@Override
protected void startServer(HttpServer httpServer) throws Exception {
super.startServer(httpServer);
this.webClient = WebClient.create("http://localhost:" + this.port);
}
@Test
public void writeAndFlushWith() {
@ParameterizedHttpServerTest
void writeAndFlushWith(HttpServer httpServer) throws Exception {
startServer(httpServer);
Mono<String> result = this.webClient.get()
.uri("/write-and-flush")
.retrieve()
@@ -68,8 +70,10 @@ public class FlushingIntegrationTests extends AbstractHttpHandlerIntegrationTest
.verify(Duration.ofSeconds(10L));
}
@Test // SPR-14991
public void writeAndAutoFlushOnComplete() {
@ParameterizedHttpServerTest // SPR-14991
void writeAndAutoFlushOnComplete(HttpServer httpServer) throws Exception {
startServer(httpServer);
Mono<String> result = this.webClient.get()
.uri("/write-and-complete")
.retrieve()
@@ -93,8 +97,10 @@ public class FlushingIntegrationTests extends AbstractHttpHandlerIntegrationTest
}
}
@Test // SPR-14992
public void writeAndAutoFlushBeforeComplete() {
@ParameterizedHttpServerTest // SPR-14992
void writeAndAutoFlushBeforeComplete(HttpServer httpServer) throws Exception {
startServer(httpServer);
Mono<String> result = this.webClient.get()
.uri("/write-and-never-complete")
.retrieve()

View File

@@ -18,7 +18,7 @@ package org.springframework.web.reactive.accept;
import java.util.List;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;

View File

@@ -19,7 +19,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;

View File

@@ -18,7 +18,7 @@ package org.springframework.web.reactive.accept;
import java.util.Collections;
import java.util.List;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;

View File

@@ -19,7 +19,7 @@ package org.springframework.web.reactive.config;
import java.util.Arrays;
import java.util.Map;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.web.cors.CorsConfiguration;

View File

@@ -19,13 +19,13 @@ package org.springframework.web.reactive.config;
import java.util.Collections;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.springframework.context.support.StaticApplicationContext;
import org.springframework.core.ReactiveAdapterRegistry;
@@ -49,7 +49,7 @@ import static org.mockito.Mockito.verify;
*
* @author Brian Clozel
*/
@RunWith(MockitoJUnitRunner.class)
@MockitoSettings(strictness = Strictness.LENIENT)
public class DelegatingWebFluxConfigurationTests {
@Mock
@@ -67,7 +67,7 @@ public class DelegatingWebFluxConfigurationTests {
private DelegatingWebFluxConfiguration delegatingConfig;
@Before
@BeforeEach
public void setup() {
delegatingConfig = new DelegatingWebFluxConfiguration();
delegatingConfig.setApplicationContext(new StaticApplicationContext());

View File

@@ -21,8 +21,8 @@ import java.time.Duration;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import reactor.test.StepVerifier;
@@ -62,7 +62,7 @@ public class ResourceHandlerRegistryTests {
private ResourceHandlerRegistration registration;
@Before
@BeforeEach
public void setup() {
this.registry = new ResourceHandlerRegistry(new GenericApplicationContext());
this.registration = this.registry.addResourceHandler("/resources/**");

View File

@@ -17,8 +17,8 @@ package org.springframework.web.reactive.config;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.core.Ordered;
@@ -45,7 +45,7 @@ public class ViewResolverRegistryTests {
private ViewResolverRegistry registry;
@Before
@BeforeEach
public void setup() {
StaticWebApplicationContext context = new StaticWebApplicationContext();
context.registerSingleton("freeMarkerConfigurer", FreeMarkerConfigurer.class);

View File

@@ -25,7 +25,7 @@ import java.util.Map;
import javax.xml.bind.annotation.XmlRootElement;
import com.google.protobuf.Message;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

View File

@@ -29,8 +29,8 @@ import java.util.Optional;
import com.fasterxml.jackson.annotation.JsonView;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.util.IllegalReferenceCountException;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
@@ -81,7 +81,7 @@ public class BodyExtractorsTests {
private Optional<ServerHttpResponse> serverResponse = Optional.empty();
@Before
@BeforeEach
public void createContext() {
final List<HttpMessageReader<?>> messageReaders = new ArrayList<>();
messageReaders.add(new DecoderHttpMessageReader<>(new ByteBufferDecoder()));

View File

@@ -31,8 +31,8 @@ import java.util.Optional;
import com.fasterxml.jackson.annotation.JsonView;
import io.reactivex.Single;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
@@ -82,7 +82,7 @@ public class BodyInsertersTests {
private Map<String, Object> hints;
@Before
@BeforeEach
public void createContext() {
final List<HttpMessageWriter<?>> messageWriters = new ArrayList<>();
messageWriters.add(new EncoderHttpMessageWriter<>(new ByteBufferEncoder()));

View File

@@ -22,7 +22,6 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;
import org.junit.Test;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
@@ -33,6 +32,7 @@ import org.springframework.http.client.MultipartBodyBuilder;
import org.springframework.http.codec.multipart.FilePart;
import org.springframework.http.codec.multipart.FormFieldPart;
import org.springframework.http.codec.multipart.Part;
import org.springframework.http.server.reactive.bootstrap.HttpServer;
import org.springframework.util.FileCopyUtils;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.client.ClientResponse;
@@ -49,15 +49,17 @@ import static org.springframework.web.reactive.function.server.RouterFunctions.r
/**
* @author Sebastien Deleuze
*/
public class MultipartIntegrationTests extends AbstractRouterFunctionIntegrationTests {
class MultipartIntegrationTests extends AbstractRouterFunctionIntegrationTests {
private final WebClient webClient = WebClient.create();
private ClassPathResource resource = new ClassPathResource("org/springframework/http/codec/multipart/foo.txt");
@Test
public void multipartData() {
@ParameterizedHttpServerTest
void multipartData(HttpServer httpServer) throws Exception {
startServer(httpServer);
Mono<ClientResponse> result = webClient
.post()
.uri("http://localhost:" + this.port + "/multipartData")
@@ -70,8 +72,10 @@ public class MultipartIntegrationTests extends AbstractRouterFunctionIntegration
.verifyComplete();
}
@Test
public void parts() {
@ParameterizedHttpServerTest
void parts(HttpServer httpServer) throws Exception {
startServer(httpServer);
Mono<ClientResponse> result = webClient
.post()
.uri("http://localhost:" + this.port + "/parts")
@@ -84,8 +88,10 @@ public class MultipartIntegrationTests extends AbstractRouterFunctionIntegration
.verifyComplete();
}
@Test
public void transferTo() {
@ParameterizedHttpServerTest
void transferTo(HttpServer httpServer) throws Exception {
startServer(httpServer);
Mono<String> result = webClient
.post()
.uri("http://localhost:" + this.port + "/transferTo")

View File

@@ -21,7 +21,7 @@ import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;

View File

@@ -18,7 +18,7 @@ package org.springframework.web.reactive.function.client;
import java.nio.charset.StandardCharsets;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.test.StepVerifier;

View File

@@ -24,8 +24,8 @@ import java.util.List;
import java.util.Optional;
import java.util.OptionalLong;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@@ -65,7 +65,7 @@ public class DefaultClientResponseTests {
private DefaultClientResponse defaultClientResponse;
@Before
@BeforeEach
public void createMocks() {
mockResponse = mock(ClientHttpResponse.class);
mockExchangeStrategies = mock(ExchangeStrategies.class);

View File

@@ -21,13 +21,13 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
@@ -50,7 +50,7 @@ import static org.mockito.Mockito.verifyZeroInteractions;
* @author Rossen Stoyanchev
* @author Brian Clozel
*/
@RunWith(MockitoJUnitRunner.class)
@MockitoSettings(strictness = Strictness.LENIENT)
public class DefaultWebClientTests {
@Mock
@@ -62,7 +62,7 @@ public class DefaultWebClientTests {
private WebClient.Builder builder;
@Before
@BeforeEach
public void setup() {
ClientResponse mockResponse = mock(ClientResponse.class);
given(this.exchangeFunction.exchange(this.captor.capture())).willReturn(Mono.just(mockResponse));

View File

@@ -19,7 +19,7 @@ package org.springframework.web.reactive.function.client;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;

View File

@@ -16,7 +16,7 @@
package org.springframework.web.reactive.function.client;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -18,22 +18,25 @@ package org.springframework.web.reactive.function.client;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.net.URI;
import java.nio.file.Files;
import java.time.Duration;
import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Stream;
import java.util.zip.CRC32;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
@@ -64,44 +67,46 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Rossen Stoyanchev
* @author Denys Ivano
* @author Sebastien Deleuze
* @author Sam Brannen
*/
@RunWith(Parameterized.class)
public class WebClientIntegrationTests {
class WebClientIntegrationTests {
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@ParameterizedTest(name = "webClient [{0}]")
@MethodSource("arguments")
@interface ParameterizedWebClientTest {
}
static Stream<ClientHttpConnector> arguments() {
return Stream.of(new JettyClientHttpConnector(), new ReactorClientHttpConnector());
}
private MockWebServer server;
private WebClient webClient;
@Parameterized.Parameter(0)
public ClientHttpConnector connector;
@Parameterized.Parameters(name = "webClient [{0}]")
public static Object[][] arguments() {
return new Object[][] {
{new JettyClientHttpConnector()},
{new ReactorClientHttpConnector()}
};
}
@Before
public void setup() {
private void startServer(ClientHttpConnector connector) {
this.server = new MockWebServer();
this.webClient = WebClient
.builder()
.clientConnector(this.connector)
.clientConnector(connector)
.baseUrl(this.server.url("/").toString())
.build();
}
@After
public void shutdown() throws IOException {
@AfterEach
void shutdown() throws IOException {
this.server.shutdown();
}
@Test
public void shouldReceiveResponseHeaders() {
@ParameterizedWebClientTest
void shouldReceiveResponseHeaders(ClientHttpConnector connector) {
startServer(connector);
prepareResponse(response -> response
.setHeader("Content-Type", "text/plain")
.setBody("Hello Spring!"));
@@ -126,8 +131,10 @@ public class WebClientIntegrationTests {
});
}
@Test
public void shouldReceivePlainText() {
@ParameterizedWebClientTest
void shouldReceivePlainText(ClientHttpConnector connector) {
startServer(connector);
prepareResponse(response -> response.setBody("Hello Spring!"));
Mono<String> result = this.webClient.get()
@@ -148,8 +155,10 @@ public class WebClientIntegrationTests {
});
}
@Test
public void shouldReceivePlainTextFlux() throws Exception {
@ParameterizedWebClientTest
void shouldReceivePlainTextFlux(ClientHttpConnector connector) {
startServer(connector);
prepareResponse(response -> response.setBody("Hello Spring!"));
Flux<String> result = this.webClient.get()
@@ -170,8 +179,10 @@ public class WebClientIntegrationTests {
});
}
@Test
public void shouldReceiveJsonAsString() {
@ParameterizedWebClientTest
void shouldReceiveJsonAsString(ClientHttpConnector connector) {
startServer(connector);
String content = "{\"bar\":\"barbar\",\"foo\":\"foofoo\"}";
prepareResponse(response -> response
.setHeader("Content-Type", "application/json").setBody(content));
@@ -192,8 +203,10 @@ public class WebClientIntegrationTests {
});
}
@Test // SPR-16715
public void shouldReceiveJsonAsTypeReferenceString() {
@ParameterizedWebClientTest // SPR-16715
void shouldReceiveJsonAsTypeReferenceString(ClientHttpConnector connector) {
startServer(connector);
String content = "{\"containerValue\":{\"fooValue\":\"bar\"}}";
prepareResponse(response -> response
.setHeader("Content-Type", "application/json").setBody(content));
@@ -218,8 +231,10 @@ public class WebClientIntegrationTests {
});
}
@Test
public void exchangeShouldReceiveJsonAsResponseEntityString() {
@ParameterizedWebClientTest
void exchangeShouldReceiveJsonAsResponseEntityString(ClientHttpConnector connector) {
startServer(connector);
String content = "{\"bar\":\"barbar\",\"foo\":\"foofoo\"}";
prepareResponse(response -> response
.setHeader("Content-Type", "application/json").setBody(content));
@@ -245,8 +260,10 @@ public class WebClientIntegrationTests {
});
}
@Test
public void retrieveShouldReceiveJsonAsResponseEntityString() {
@ParameterizedWebClientTest
void retrieveShouldReceiveJsonAsResponseEntityString(ClientHttpConnector connector) {
startServer(connector);
String content = "{\"bar\":\"barbar\",\"foo\":\"foofoo\"}";
prepareResponse(response -> response
.setHeader("Content-Type", "application/json").setBody(content));
@@ -272,8 +289,10 @@ public class WebClientIntegrationTests {
});
}
@Test
public void retrieveEntityWithServerError() {
@ParameterizedWebClientTest
void retrieveEntityWithServerError(ClientHttpConnector connector) {
startServer(connector);
prepareResponse(response -> response.setResponseCode(500)
.setHeader("Content-Type", "text/plain").setBody("Internal Server error"));
@@ -293,8 +312,10 @@ public class WebClientIntegrationTests {
});
}
@Test
public void retrieveEntityWithServerErrorStatusHandler() {
@ParameterizedWebClientTest
void retrieveEntityWithServerErrorStatusHandler(ClientHttpConnector connector) {
startServer(connector);
String content = "Internal Server error";
prepareResponse(response -> response.setResponseCode(500)
.setHeader("Content-Type", "text/plain").setBody(content));
@@ -320,8 +341,10 @@ public class WebClientIntegrationTests {
});
}
@Test
public void exchangeShouldReceiveJsonAsResponseEntityList() {
@ParameterizedWebClientTest
void exchangeShouldReceiveJsonAsResponseEntityList(ClientHttpConnector connector) {
startServer(connector);
String content = "[{\"bar\":\"bar1\",\"foo\":\"foo1\"}, {\"bar\":\"bar2\",\"foo\":\"foo2\"}]";
prepareResponse(response -> response
.setHeader("Content-Type", "application/json").setBody(content));
@@ -349,8 +372,10 @@ public class WebClientIntegrationTests {
});
}
@Test
public void retrieveShouldReceiveJsonAsResponseEntityList() {
@ParameterizedWebClientTest
void retrieveShouldReceiveJsonAsResponseEntityList(ClientHttpConnector connector) {
startServer(connector);
String content = "[{\"bar\":\"bar1\",\"foo\":\"foo1\"}, {\"bar\":\"bar2\",\"foo\":\"foo2\"}]";
prepareResponse(response -> response
.setHeader("Content-Type", "application/json").setBody(content));
@@ -378,8 +403,10 @@ public class WebClientIntegrationTests {
});
}
@Test
public void retrieveEntityListWithServerError() {
@ParameterizedWebClientTest
void retrieveEntityListWithServerError(ClientHttpConnector connector) {
startServer(connector);
prepareResponse(response -> response.setResponseCode(500)
.setHeader("Content-Type", "text/plain").setBody("Internal Server error"));
@@ -399,9 +426,10 @@ public class WebClientIntegrationTests {
});
}
@ParameterizedWebClientTest
void shouldReceiveJsonAsFluxString(ClientHttpConnector connector) {
startServer(connector);
@Test
public void shouldReceiveJsonAsFluxString() {
String content = "{\"bar\":\"barbar\",\"foo\":\"foofoo\"}";
prepareResponse(response -> response
.setHeader("Content-Type", "application/json").setBody(content));
@@ -422,8 +450,10 @@ public class WebClientIntegrationTests {
});
}
@Test
public void shouldReceiveJsonAsPojo() {
@ParameterizedWebClientTest
void shouldReceiveJsonAsPojo(ClientHttpConnector connector) {
startServer(connector);
prepareResponse(response -> response
.setHeader("Content-Type", "application/json")
.setBody("{\"bar\":\"barbar\",\"foo\":\"foofoo\"}"));
@@ -446,8 +476,10 @@ public class WebClientIntegrationTests {
});
}
@Test
public void shouldReceiveJsonAsFluxPojo() {
@ParameterizedWebClientTest
void shouldReceiveJsonAsFluxPojo(ClientHttpConnector connector) {
startServer(connector);
prepareResponse(response -> response
.setHeader("Content-Type", "application/json")
.setBody("[{\"bar\":\"bar1\",\"foo\":\"foo1\"},{\"bar\":\"bar2\",\"foo\":\"foo2\"}]"));
@@ -471,8 +503,10 @@ public class WebClientIntegrationTests {
});
}
@Test
public void shouldSendPojoAsJson() {
@ParameterizedWebClientTest
void shouldSendPojoAsJson(ClientHttpConnector connector) {
startServer(connector);
prepareResponse(response -> response.setHeader("Content-Type", "application/json")
.setBody("{\"bar\":\"BARBAR\",\"foo\":\"FOOFOO\"}"));
@@ -499,8 +533,10 @@ public class WebClientIntegrationTests {
});
}
@Test
public void shouldSendCookies() {
@ParameterizedWebClientTest
void shouldSendCookies(ClientHttpConnector connector) {
startServer(connector);
prepareResponse(response -> response
.setHeader("Content-Type", "text/plain").setBody("test"));
@@ -522,8 +558,10 @@ public class WebClientIntegrationTests {
});
}
@Test // SPR-16246
public void shouldSendLargeTextFile() throws IOException {
@ParameterizedWebClientTest // SPR-16246
void shouldSendLargeTextFile(ClientHttpConnector connector) throws Exception {
startServer(connector);
prepareResponse(response -> {});
Resource resource = new ClassPathResource("largeTextFile.txt", getClass());
@@ -556,8 +594,10 @@ public class WebClientIntegrationTests {
return crc.getValue();
}
@Test
public void shouldReceive404Response() {
@ParameterizedWebClientTest
void shouldReceive404Response(ClientHttpConnector connector) {
startServer(connector);
prepareResponse(response -> response.setResponseCode(404)
.setHeader("Content-Type", "text/plain").setBody("Not Found"));
@@ -575,8 +615,10 @@ public class WebClientIntegrationTests {
});
}
@Test
public void shouldGetErrorSignalOn404() {
@ParameterizedWebClientTest
void shouldGetErrorSignalOn404(ClientHttpConnector connector) {
startServer(connector);
prepareResponse(response -> response.setResponseCode(404)
.setHeader("Content-Type", "text/plain").setBody("Not Found"));
@@ -596,8 +638,10 @@ public class WebClientIntegrationTests {
});
}
@Test // SPR-15946
public void shouldGetErrorSignalOnEmptyErrorResponse() {
@ParameterizedWebClientTest // SPR-15946
void shouldGetErrorSignalOnEmptyErrorResponse(ClientHttpConnector connector) {
startServer(connector);
prepareResponse(response -> response.setResponseCode(404)
.setHeader("Content-Type", "text/plain"));
@@ -616,8 +660,10 @@ public class WebClientIntegrationTests {
});
}
@Test
public void shouldGetInternalServerErrorSignal() {
@ParameterizedWebClientTest
void shouldGetInternalServerErrorSignal(ClientHttpConnector connector) {
startServer(connector);
String errorMessage = "Internal Server error";
prepareResponse(response -> response.setResponseCode(500)
.setHeader("Content-Type", "text/plain").setBody(errorMessage));
@@ -652,8 +698,10 @@ public class WebClientIntegrationTests {
});
}
@Test
public void shouldSupportUnknownStatusCode() {
@ParameterizedWebClientTest
void shouldSupportUnknownStatusCode(ClientHttpConnector connector) {
startServer(connector);
int errorStatus = 555;
assertThat((Object) HttpStatus.resolve(errorStatus)).isNull();
String errorMessage = "Something went wrong";
@@ -676,8 +724,10 @@ public class WebClientIntegrationTests {
});
}
@Test
public void shouldGetErrorSignalWhenRetrievingUnknownStatusCode() {
@ParameterizedWebClientTest
void shouldGetErrorSignalWhenRetrievingUnknownStatusCode(ClientHttpConnector connector) {
startServer(connector);
int errorStatus = 555;
assertThat((Object) HttpStatus.resolve(errorStatus)).isNull();
String errorMessage = "Something went wrong";
@@ -708,8 +758,10 @@ public class WebClientIntegrationTests {
});
}
@Test
public void shouldApplyCustomStatusHandler() {
@ParameterizedWebClientTest
void shouldApplyCustomStatusHandler(ClientHttpConnector connector) {
startServer(connector);
prepareResponse(response -> response.setResponseCode(500)
.setHeader("Content-Type", "text/plain").setBody("Internal Server error"));
@@ -730,8 +782,10 @@ public class WebClientIntegrationTests {
});
}
@Test
public void shouldApplyCustomRawStatusHandler() {
@ParameterizedWebClientTest
void shouldApplyCustomRawStatusHandler(ClientHttpConnector connector) {
startServer(connector);
prepareResponse(response -> response.setResponseCode(500)
.setHeader("Content-Type", "text/plain").setBody("Internal Server error"));
@@ -752,8 +806,10 @@ public class WebClientIntegrationTests {
});
}
@Test
public void shouldApplyCustomStatusHandlerParameterizedTypeReference() {
@ParameterizedWebClientTest
void shouldApplyCustomStatusHandlerParameterizedTypeReference(ClientHttpConnector connector) {
startServer(connector);
prepareResponse(response -> response.setResponseCode(500)
.setHeader("Content-Type", "text/plain").setBody("Internal Server error"));
@@ -774,8 +830,10 @@ public class WebClientIntegrationTests {
});
}
@Test
public void emptyStatusHandlerShouldReturnBody() {
@ParameterizedWebClientTest
void emptyStatusHandlerShouldReturnBody(ClientHttpConnector connector) {
startServer(connector);
prepareResponse(response -> response.setResponseCode(500)
.setHeader("Content-Type", "text/plain").setBody("Internal Server error"));
@@ -796,8 +854,10 @@ public class WebClientIntegrationTests {
});
}
@Test
public void emptyStatusHandlerShouldReturnBodyFlux() {
@ParameterizedWebClientTest
void emptyStatusHandlerShouldReturnBodyFlux(ClientHttpConnector connector) {
startServer(connector);
prepareResponse(response -> response.setResponseCode(500)
.setHeader("Content-Type", "text/plain").setBody("Internal Server error"));
@@ -818,8 +878,10 @@ public class WebClientIntegrationTests {
});
}
@Test
public void shouldReceiveNotFoundEntity() {
@ParameterizedWebClientTest
void shouldReceiveNotFoundEntity(ClientHttpConnector connector) {
startServer(connector);
prepareResponse(response -> response.setResponseCode(404)
.setHeader("Content-Type", "text/plain").setBody("Not Found"));
@@ -840,8 +902,10 @@ public class WebClientIntegrationTests {
});
}
@Test
public void shouldApplyExchangeFilter() {
@ParameterizedWebClientTest
void shouldApplyExchangeFilter(ClientHttpConnector connector) {
startServer(connector);
prepareResponse(response -> response.setHeader("Content-Type", "text/plain")
.setBody("Hello Spring!"));
@@ -867,8 +931,9 @@ public class WebClientIntegrationTests {
expectRequest(request -> assertThat(request.getHeader("foo")).isEqualTo("bar"));
}
@Test
public void shouldApplyErrorHandlingFilter() {
@ParameterizedWebClientTest
void shouldApplyErrorHandlingFilter(ClientHttpConnector connector) {
startServer(connector);
ExchangeFilterFunction filter = ExchangeFilterFunction.ofResponseProcessor(
clientResponse -> {
@@ -910,8 +975,10 @@ public class WebClientIntegrationTests {
expectRequestCount(2);
}
@Test
public void shouldReceiveEmptyResponse() {
@ParameterizedWebClientTest
void shouldReceiveEmptyResponse(ClientHttpConnector connector) {
startServer(connector);
prepareResponse(response -> response.setHeader("Content-Length", "0").setBody(""));
Mono<ResponseEntity<Void>> result = this.webClient.get()
@@ -924,8 +991,10 @@ public class WebClientIntegrationTests {
).verifyComplete();
}
@Test // SPR-15782
public void shouldFailWithRelativeUrls() {
@ParameterizedWebClientTest // SPR-15782
void shouldFailWithRelativeUrls(ClientHttpConnector connector) {
startServer(connector);
String uri = "/api/v4/groups/1";
Mono<ClientResponse> responseMono = WebClient.builder().build().get().uri(uri).exchange();

View File

@@ -18,8 +18,8 @@ package org.springframework.web.reactive.function.client.support;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@@ -47,7 +47,7 @@ public class ClientResponseWrapperTests {
private ClientResponseWrapper wrapper;
@Before
@BeforeEach
public void createWrapper() {
this.mockResponse = mock(ClientResponse.class);
this.wrapper = new ClientResponseWrapper(mockResponse);

View File

@@ -25,7 +25,7 @@ import java.util.List;
import java.util.Set;
import io.reactivex.Single;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

View File

@@ -26,7 +26,7 @@ import java.util.Locale;
import java.util.Map;
import java.util.Set;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;

View File

@@ -18,7 +18,7 @@ package org.springframework.web.reactive.function.server;
import java.nio.charset.StandardCharsets;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.test.StepVerifier;

View File

@@ -29,7 +29,7 @@ import java.util.Map;
import java.util.Optional;
import java.util.OptionalLong;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;

View File

@@ -25,7 +25,7 @@ import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;

View File

@@ -19,7 +19,6 @@ package org.springframework.web.reactive.function.server;
import java.util.List;
import java.util.Map;
import org.junit.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@@ -32,6 +31,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.server.reactive.AbstractHttpHandlerIntegrationTests;
import org.springframework.http.server.reactive.HttpHandler;
import org.springframework.http.server.reactive.bootstrap.HttpServer;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@@ -53,7 +53,7 @@ import static org.springframework.web.reactive.function.server.RouterFunctions.r
*
* @author Arjen Poutsma
*/
public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegrationTests {
class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegrationTests {
private final RestTemplate restTemplate = new RestTemplate();
@@ -73,8 +73,10 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
}
@Test
public void mono() {
@ParameterizedHttpServerTest
void mono(HttpServer httpServer) throws Exception {
startServer(httpServer);
ResponseEntity<Person> result =
this.restTemplate.getForEntity("http://localhost:" + this.port + "/mono", Person.class);
@@ -82,8 +84,10 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
assertThat(result.getBody().getName()).isEqualTo("John");
}
@Test
public void flux() {
@ParameterizedHttpServerTest
void flux(HttpServer httpServer) throws Exception {
startServer(httpServer);
ParameterizedTypeReference<List<Person>> reference = new ParameterizedTypeReference<List<Person>>() {};
ResponseEntity<List<Person>> result =
this.restTemplate
@@ -96,8 +100,10 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
assertThat(body.get(1).getName()).isEqualTo("Jane");
}
@Test
public void controller() {
@ParameterizedHttpServerTest
void controller(HttpServer httpServer) throws Exception {
startServer(httpServer);
ResponseEntity<Person> result =
this.restTemplate.getForEntity("http://localhost:" + this.port + "/controller", Person.class);
@@ -105,8 +111,10 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
assertThat(result.getBody().getName()).isEqualTo("John");
}
@Test
public void attributes() {
@ParameterizedHttpServerTest
void attributes(HttpServer httpServer) throws Exception {
startServer(httpServer);
ResponseEntity<String> result =
this.restTemplate
.getForEntity("http://localhost:" + this.port + "/attributes/bar", String.class);

View File

@@ -16,7 +16,7 @@
package org.springframework.web.reactive.function.server;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -24,8 +24,8 @@ import java.util.List;
import java.util.Optional;
import java.util.OptionalLong;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpRange;
@@ -46,7 +46,7 @@ public class HeadersWrapperTests {
private ServerRequestWrapper.HeadersWrapper wrapper;
@Before
@BeforeEach
public void createWrapper() {
mockHeaders = mock(ServerRequest.Headers.class);
wrapper = new ServerRequestWrapper.HeadersWrapper(mockHeaders);

View File

@@ -16,19 +16,18 @@
package org.springframework.web.reactive.function.server;
import java.io.IOException;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.junit.Test;
import org.springframework.http.server.reactive.bootstrap.HttpServer;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Arjen Poutsma
*/
public class InvalidHttpMethodIntegrationTests extends AbstractRouterFunctionIntegrationTests {
class InvalidHttpMethodIntegrationTests extends AbstractRouterFunctionIntegrationTests {
@Override
protected RouterFunction<?> routerFunction() {
@@ -37,8 +36,10 @@ public class InvalidHttpMethodIntegrationTests extends AbstractRouterFunctionInt
.andRoute(RequestPredicates.all(), request -> ServerResponse.ok().body("BAR"));
}
@Test
public void invalidHttpMethod() throws IOException {
@ParameterizedHttpServerTest
void invalidHttpMethod(HttpServer httpServer) throws Exception {
startServer(httpServer);
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()

View File

@@ -21,12 +21,12 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.junit.Test;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.server.reactive.bootstrap.HttpServer;
import org.springframework.lang.Nullable;
import org.springframework.web.reactive.function.client.ClientResponse;
import org.springframework.web.reactive.function.client.WebClient;
@@ -40,7 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Sebastien Deleuze
*/
public class LocaleContextResolverIntegrationTests extends AbstractRouterFunctionIntegrationTests {
class LocaleContextResolverIntegrationTests extends AbstractRouterFunctionIntegrationTests {
private final WebClient webClient = WebClient.create();
@@ -50,7 +50,7 @@ public class LocaleContextResolverIntegrationTests extends AbstractRouterFunctio
return RouterFunctions.route(RequestPredicates.path("/"), this::render);
}
public Mono<RenderingResponse> render(ServerRequest request) {
Mono<RenderingResponse> render(ServerRequest request) {
return RenderingResponse.create("foo").build();
}
@@ -62,9 +62,10 @@ public class LocaleContextResolverIntegrationTests extends AbstractRouterFunctio
.build();
}
@ParameterizedHttpServerTest
void fixedLocale(HttpServer httpServer) throws Exception {
startServer(httpServer);
@Test
public void fixedLocale() {
Mono<ClientResponse> result = webClient
.get()
.uri("http://localhost:" + this.port + "/")

View File

@@ -18,13 +18,13 @@ package org.springframework.web.reactive.function.server;
import java.util.Map;
import org.junit.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.server.reactive.bootstrap.HttpServer;
import org.springframework.lang.Nullable;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.pattern.PathPattern;
@@ -40,7 +40,7 @@ import static org.springframework.web.reactive.function.server.RouterFunctions.r
/**
* @author Arjen Poutsma
*/
public class NestedRouteIntegrationTests extends AbstractRouterFunctionIntegrationTests {
class NestedRouteIntegrationTests extends AbstractRouterFunctionIntegrationTests {
private final RestTemplate restTemplate = new RestTemplate();
@@ -60,8 +60,10 @@ public class NestedRouteIntegrationTests extends AbstractRouterFunctionIntegrati
}
@Test
public void bar() {
@ParameterizedHttpServerTest
void bar(HttpServer httpServer) throws Exception {
startServer(httpServer);
ResponseEntity<String> result =
restTemplate.getForEntity("http://localhost:" + port + "/foo/bar", String.class);
@@ -69,8 +71,10 @@ public class NestedRouteIntegrationTests extends AbstractRouterFunctionIntegrati
assertThat(result.getBody()).isEqualTo("/foo/bar");
}
@Test
public void baz() {
@ParameterizedHttpServerTest
void baz(HttpServer httpServer) throws Exception {
startServer(httpServer);
ResponseEntity<String> result =
restTemplate.getForEntity("http://localhost:" + port + "/foo/baz", String.class);
@@ -78,8 +82,10 @@ public class NestedRouteIntegrationTests extends AbstractRouterFunctionIntegrati
assertThat(result.getBody()).isEqualTo("/foo/baz");
}
@Test
public void variables() {
@ParameterizedHttpServerTest
void variables(HttpServer httpServer) throws Exception {
startServer(httpServer);
ResponseEntity<String> result =
restTemplate.getForEntity("http://localhost:" + port + "/1/2/3", String.class);
@@ -88,8 +94,10 @@ public class NestedRouteIntegrationTests extends AbstractRouterFunctionIntegrati
}
// SPR-16868
@Test
public void parentVariables() {
@ParameterizedHttpServerTest
void parentVariables(HttpServer httpServer) throws Exception {
startServer(httpServer);
ResponseEntity<String> result =
restTemplate.getForEntity("http://localhost:" + port + "/1/bar", String.class);
@@ -99,8 +107,10 @@ public class NestedRouteIntegrationTests extends AbstractRouterFunctionIntegrati
}
// SPR 16692
@Test
public void removeFailedNestedPathVariables() {
@ParameterizedHttpServerTest
void removeFailedNestedPathVariables(HttpServer httpServer) throws Exception {
startServer(httpServer);
ResponseEntity<String> result =
restTemplate.getForEntity("http://localhost:" + port + "/qux/quux", String.class);
@@ -110,8 +120,10 @@ public class NestedRouteIntegrationTests extends AbstractRouterFunctionIntegrati
}
// SPR 17210
@Test
public void removeFailedPathVariablesAnd() {
@ParameterizedHttpServerTest
void removeFailedPathVariablesAnd(HttpServer httpServer) throws Exception {
startServer(httpServer);
ResponseEntity<String> result =
restTemplate.postForEntity("http://localhost:" + port + "/qux/quux", "", String.class);

View File

@@ -21,7 +21,7 @@ import java.io.IOException;
import java.net.URI;
import java.util.function.Function;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;

View File

@@ -19,7 +19,6 @@ package org.springframework.web.reactive.function.server;
import java.net.URI;
import java.util.List;
import org.junit.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@@ -28,6 +27,7 @@ import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.http.server.reactive.bootstrap.HttpServer;
import org.springframework.web.client.RestTemplate;
import static org.assertj.core.api.Assertions.assertThat;
@@ -40,7 +40,7 @@ import static org.springframework.web.reactive.function.server.RouterFunctions.r
/**
* @author Arjen Poutsma
*/
public class PublisherHandlerFunctionIntegrationTests extends AbstractRouterFunctionIntegrationTests {
class PublisherHandlerFunctionIntegrationTests extends AbstractRouterFunctionIntegrationTests {
private final RestTemplate restTemplate = new RestTemplate();
@@ -54,20 +54,24 @@ public class PublisherHandlerFunctionIntegrationTests extends AbstractRouterFunc
}
@Test
public void mono() {
@ParameterizedHttpServerTest
void mono(HttpServer httpServer) throws Exception {
startServer(httpServer);
ResponseEntity<Person> result =
restTemplate.getForEntity("http://localhost:" + port + "/mono", Person.class);
restTemplate.getForEntity("http://localhost:" + super.port + "/mono", Person.class);
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(result.getBody().getName()).isEqualTo("John");
}
@Test
public void flux() {
@ParameterizedHttpServerTest
void flux(HttpServer httpServer) throws Exception {
startServer(httpServer);
ParameterizedTypeReference<List<Person>> reference = new ParameterizedTypeReference<List<Person>>() {};
ResponseEntity<List<Person>> result =
restTemplate.exchange("http://localhost:" + port + "/flux", HttpMethod.GET, null, reference);
restTemplate.exchange("http://localhost:" + super.port + "/flux", HttpMethod.GET, null, reference);
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
List<Person> body = result.getBody();
@@ -76,9 +80,11 @@ public class PublisherHandlerFunctionIntegrationTests extends AbstractRouterFunc
assertThat(body.get(1).getName()).isEqualTo("Jane");
}
@Test
public void postMono() {
URI uri = URI.create("http://localhost:" + port + "/mono");
@ParameterizedHttpServerTest
void postMono(HttpServer httpServer) throws Exception {
startServer(httpServer);
URI uri = URI.create("http://localhost:" + super.port + "/mono");
Person person = new Person("Jack");
RequestEntity<Person> requestEntity = RequestEntity.post(uri).body(person);
ResponseEntity<Person> result = restTemplate.exchange(requestEntity, Person.class);

View File

@@ -23,7 +23,6 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.junit.Test;
import reactor.core.publisher.Mono;
import org.springframework.core.io.buffer.DataBuffer;
@@ -31,6 +30,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.http.server.reactive.bootstrap.HttpServer;
import org.springframework.lang.Nullable;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.reactive.result.view.View;
@@ -46,7 +46,7 @@ import static org.springframework.web.reactive.function.server.RouterFunctions.r
* @author Arjen Poutsma
* @since 5.0
*/
public class RenderingResponseIntegrationTests extends AbstractRouterFunctionIntegrationTests {
class RenderingResponseIntegrationTests extends AbstractRouterFunctionIntegrationTests {
private final RestTemplate restTemplate = new RestTemplate();
@@ -72,8 +72,10 @@ public class RenderingResponseIntegrationTests extends AbstractRouterFunctionInt
}
@Test
public void normal() {
@ParameterizedHttpServerTest
void normal(HttpServer httpServer) throws Exception {
startServer(httpServer);
ResponseEntity<String> result =
restTemplate.getForEntity("http://localhost:" + port + "/normal", String.class);
@@ -84,8 +86,10 @@ public class RenderingResponseIntegrationTests extends AbstractRouterFunctionInt
assertThat(body.get("bar")).isEqualTo("baz");
}
@Test
public void filter() {
@ParameterizedHttpServerTest
void filter(HttpServer httpServer) throws Exception {
startServer(httpServer);
ResponseEntity<String> result =
restTemplate.getForEntity("http://localhost:" + port + "/filter", String.class);

View File

@@ -18,8 +18,8 @@ package org.springframework.web.reactive.function.server;
import java.util.Collections;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.core.codec.StringDecoder;
import org.springframework.http.codec.DecoderHttpMessageReader;
@@ -35,7 +35,7 @@ public class RequestPredicateAttributesTests {
private DefaultServerRequest request;
@Before
@BeforeEach
public void createRequest() {
MockServerHttpRequest request = MockServerHttpRequest.get("https://example.com/path").build();
MockServerWebExchange webExchange = MockServerWebExchange.from(request);

View File

@@ -16,7 +16,7 @@
package org.springframework.web.reactive.function.server;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -20,7 +20,7 @@ import java.net.URI;
import java.util.Collections;
import java.util.function.Function;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;

View File

@@ -21,8 +21,8 @@ import java.nio.file.Files;
import java.util.EnumSet;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
@@ -52,7 +52,7 @@ public class ResourceHandlerFunctionTests {
private ServerResponse.Context context;
@Before
@BeforeEach
public void createContext() {
HandlerStrategies strategies = HandlerStrategies.withDefaults();
context = new ServerResponse.Context() {

View File

@@ -19,7 +19,7 @@ package org.springframework.web.reactive.function.server;
import java.net.URI;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;

View File

@@ -16,7 +16,7 @@
package org.springframework.web.reactive.function.server;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;

View File

@@ -19,7 +19,7 @@ package org.springframework.web.reactive.function.server;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;

View File

@@ -18,8 +18,6 @@ package org.springframework.web.reactive.function.server;
import java.time.Duration;
import org.junit.Before;
import org.junit.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
@@ -27,6 +25,7 @@ import reactor.test.StepVerifier;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.MediaType;
import org.springframework.http.codec.ServerSentEvent;
import org.springframework.http.server.reactive.bootstrap.HttpServer;
import org.springframework.web.reactive.function.client.WebClient;
import static org.assertj.core.api.Assertions.assertThat;
@@ -36,15 +35,16 @@ import static org.springframework.web.reactive.function.server.RouterFunctions.r
/**
* @author Arjen Poutsma
* @author Sam Brannen
*/
public class SseHandlerFunctionIntegrationTests extends AbstractRouterFunctionIntegrationTests {
class SseHandlerFunctionIntegrationTests extends AbstractRouterFunctionIntegrationTests {
private WebClient webClient;
@Before
public void setup() throws Exception {
super.setup();
@Override
protected void startServer(HttpServer httpServer) throws Exception {
super.startServer(httpServer);
this.webClient = WebClient.create("http://localhost:" + this.port);
}
@@ -57,8 +57,10 @@ public class SseHandlerFunctionIntegrationTests extends AbstractRouterFunctionIn
}
@Test
public void sseAsString() {
@ParameterizedHttpServerTest
void sseAsString(HttpServer httpServer) throws Exception {
startServer(httpServer);
Flux<String> result = this.webClient.get()
.uri("/string")
.accept(TEXT_EVENT_STREAM)
@@ -72,8 +74,10 @@ public class SseHandlerFunctionIntegrationTests extends AbstractRouterFunctionIn
.verify(Duration.ofSeconds(5L));
}
@Test
public void sseAsPerson() {
@ParameterizedHttpServerTest
void sseAsPerson(HttpServer httpServer) throws Exception {
startServer(httpServer);
Flux<Person> result = this.webClient.get()
.uri("/person")
.accept(TEXT_EVENT_STREAM)
@@ -87,8 +91,10 @@ public class SseHandlerFunctionIntegrationTests extends AbstractRouterFunctionIn
.verify(Duration.ofSeconds(5L));
}
@Test
public void sseAsEvent() {
@ParameterizedHttpServerTest
void sseAsEvent(HttpServer httpServer) throws Exception {
startServer(httpServer);
Flux<ServerSentEvent<String>> result = this.webClient.get()
.uri("/event")
.accept(TEXT_EVENT_STREAM)

View File

@@ -16,7 +16,7 @@
package org.springframework.web.reactive.function.server;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import org.springframework.http.HttpMethod;

View File

@@ -16,7 +16,6 @@
package org.springframework.web.reactive.function.server.support;
import org.junit.Test;
import reactor.core.publisher.Mono;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@@ -26,6 +25,7 @@ import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.server.reactive.AbstractHttpHandlerIntegrationTests;
import org.springframework.http.server.reactive.HttpHandler;
import org.springframework.http.server.reactive.bootstrap.HttpServer;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.reactive.DispatcherHandler;
import org.springframework.web.reactive.config.EnableWebFlux;
@@ -41,7 +41,7 @@ import static org.springframework.web.reactive.function.server.RouterFunctions.r
/**
* @author Arjen Poutsma
*/
public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegrationTests {
class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegrationTests {
private final RestTemplate restTemplate = new RestTemplate();
@@ -56,8 +56,10 @@ public class DispatcherHandlerIntegrationTests extends AbstractHttpHandlerIntegr
}
@Test
public void nested() {
@ParameterizedHttpServerTest
void nested(HttpServer httpServer) throws Exception {
startServer(httpServer);
ResponseEntity<String> result = this.restTemplate
.getForEntity("http://localhost:" + this.port + "/foo/bar", String.class);

View File

@@ -16,7 +16,7 @@
package org.springframework.web.reactive.function.server.support;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;

View File

@@ -21,7 +21,7 @@ import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

View File

@@ -17,8 +17,8 @@ package org.springframework.web.reactive.handler;
import java.util.Collections;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
@@ -45,7 +45,7 @@ public class CorsUrlHandlerMappingTests {
private CorsAwareHandler corsController = new CorsAwareHandler();
@Before
@BeforeEach
public void setup() {
this.handlerMapping = new AbstractUrlHandlerMapping() {};
this.handlerMapping.registerHandler("/welcome.html", this.welcomeController);

View File

@@ -18,7 +18,7 @@ package org.springframework.web.reactive.handler;
import java.net.URI;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;

View File

@@ -18,7 +18,7 @@ package org.springframework.web.reactive.handler;
import java.time.Duration;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;

View File

@@ -21,8 +21,8 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
@@ -47,7 +47,7 @@ public class AppCacheManifestTransformerTests {
private ResourceTransformerChain chain;
@Before
@BeforeEach
public void setup() {
VersionResourceResolver versionResolver = new VersionResourceResolver();
versionResolver.setStrategyMap(Collections.singletonMap("/**", new ContentVersionStrategy()));

View File

@@ -21,8 +21,8 @@ import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.cache.Cache;
@@ -51,7 +51,7 @@ public class CachingResourceResolverTests {
private List<Resource> locations;
@Before
@BeforeEach
public void setup() {
this.cache = new ConcurrentMapCache("resourceCache");

View File

@@ -18,8 +18,8 @@ package org.springframework.web.reactive.resource;
import java.util.Collections;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
@@ -38,7 +38,7 @@ public class ContentBasedVersionStrategyTests {
private ContentVersionStrategy strategy = new ContentVersionStrategy();
@Before
@BeforeEach
public void setup() {
VersionResourceResolver versionResourceResolver = new VersionResourceResolver();
versionResourceResolver.setStrategyMap(Collections.singletonMap("/**", this.strategy));

View File

@@ -21,8 +21,8 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import reactor.test.StepVerifier;
@@ -46,7 +46,7 @@ public class CssLinkResourceTransformerTests {
private ResourceTransformerChain transformerChain;
@Before
@BeforeEach
public void setup() {
VersionResourceResolver versionResolver = new VersionResourceResolver();
versionResolver.setStrategyMap(Collections.singletonMap("/**", new ContentVersionStrategy()));

View File

@@ -28,9 +28,9 @@ import java.util.Collections;
import java.util.List;
import java.util.zip.GZIPOutputStream;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.cache.Cache;
import org.springframework.cache.concurrent.ConcurrentMapCache;
@@ -59,7 +59,7 @@ public class EncodedResourceResolverTests {
private List<Resource> locations;
@BeforeClass
@BeforeAll
public static void createGzippedResources() throws IOException {
createGzippedFile("/js/foo.js");
createGzippedFile("foo.css");
@@ -79,7 +79,7 @@ public class EncodedResourceResolverTests {
}
@Before
@BeforeEach
public void setup() {
Cache cache = new ConcurrentMapCache("resourceCache");

View File

@@ -16,8 +16,8 @@
package org.springframework.web.reactive.resource;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
@@ -37,7 +37,7 @@ public class FixedVersionStrategyTests {
private FixedVersionStrategy strategy;
@Before
@BeforeEach
public void setup() {
this.strategy = new FixedVersionStrategy(VERSION);
}

View File

@@ -19,7 +19,7 @@ import java.io.IOException;
import java.time.Duration;
import java.util.List;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileUrlResource;

View File

@@ -21,8 +21,8 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import org.springframework.core.io.ClassPathResource;
@@ -49,7 +49,7 @@ public class ResourceTransformerSupportTests {
private TestResourceTransformerSupport transformer;
@Before
@BeforeEach
public void setup() {
VersionResourceResolver versionResolver = new VersionResourceResolver();
versionResolver.setStrategyMap(Collections.singletonMap("/**", new ContentVersionStrategy()));

View File

@@ -24,8 +24,8 @@ import java.util.List;
import java.util.Map;
import org.assertj.core.api.Condition;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -61,7 +61,7 @@ public class ResourceUrlProviderTests {
private final MockServerWebExchange exchange = MockServerWebExchange.from(get("/"));
@Before
@BeforeEach
public void setup() throws Exception {
this.locations.add(new ClassPathResource("test/", getClass()));
this.locations.add(new ClassPathResource("testalternatepath/", getClass()));

View File

@@ -26,8 +26,8 @@ import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
@@ -78,7 +78,7 @@ public class ResourceWebHandlerTests {
private DataBufferFactory bufferFactory = new DefaultDataBufferFactory();
@Before
@BeforeEach
public void setup() throws Exception {
List<Resource> locations = new ArrayList<>(2);
locations.add(new ClassPathResource("test/", getClass()));

View File

@@ -23,8 +23,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import org.springframework.core.io.ClassPathResource;
@@ -56,7 +56,7 @@ public class VersionResourceResolverTests {
private VersionStrategy versionStrategy;
@Before
@BeforeEach
public void setup() {
this.locations = new ArrayList<>();
this.locations.add(new ClassPathResource("test/", getClass()));

View File

@@ -19,8 +19,8 @@ package org.springframework.web.reactive.resource;
import java.time.Duration;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import org.springframework.core.io.ClassPathResource;
@@ -57,7 +57,7 @@ public class WebJarsResourceResolverTests {
private ServerWebExchange exchange;
@Before
@BeforeEach
public void setup() {
// for this to work, an actual WebJar must be on the test classpath
this.locations = singletonList(new ClassPathResource("/META-INF/resources/webjars"));

View File

@@ -20,7 +20,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.core.ReactiveAdapterRegistry;
import org.springframework.http.MediaType;

View File

@@ -21,7 +21,6 @@ import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@@ -36,6 +35,7 @@ import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.http.server.reactive.AbstractHttpHandlerIntegrationTests;
import org.springframework.http.server.reactive.HttpHandler;
import org.springframework.http.server.reactive.bootstrap.HttpServer;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.reactive.DispatcherHandler;
@@ -52,7 +52,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Rossen Stoyanchev
*/
public class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandlerIntegrationTests {
class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandlerIntegrationTests {
@Override
protected HttpHandler createHttpHandler() {
@@ -66,8 +66,10 @@ public class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandler
}
@Test
public void testRequestToFooHandler() throws Exception {
@ParameterizedHttpServerTest
void testRequestToFooHandler(HttpServer httpServer) throws Exception {
startServer(httpServer);
URI url = new URI("http://localhost:" + this.port + "/foo");
RequestEntity<Void> request = RequestEntity.get(url).build();
ResponseEntity<byte[]> response = new RestTemplate().exchange(request, byte[].class);
@@ -76,8 +78,10 @@ public class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandler
assertThat(response.getBody()).isEqualTo("foo".getBytes("UTF-8"));
}
@Test
public void testRequestToBarHandler() throws Exception {
@ParameterizedHttpServerTest
public void testRequestToBarHandler(HttpServer httpServer) throws Exception {
startServer(httpServer);
URI url = new URI("http://localhost:" + this.port + "/bar");
RequestEntity<Void> request = RequestEntity.get(url).build();
ResponseEntity<byte[]> response = new RestTemplate().exchange(request, byte[].class);
@@ -86,8 +90,10 @@ public class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandler
assertThat(response.getBody()).isEqualTo("bar".getBytes("UTF-8"));
}
@Test
public void testRequestToHeaderSettingHandler() throws Exception {
@ParameterizedHttpServerTest
void testRequestToHeaderSettingHandler(HttpServer httpServer) throws Exception {
startServer(httpServer);
URI url = new URI("http://localhost:" + this.port + "/header");
RequestEntity<Void> request = RequestEntity.get(url).build();
ResponseEntity<byte[]> response = new RestTemplate().exchange(request, byte[].class);
@@ -96,8 +102,10 @@ public class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandler
assertThat(response.getHeaders().getFirst("foo")).isEqualTo("bar");
}
@Test
public void testHandlerNotFound() throws Exception {
@ParameterizedHttpServerTest
void testHandlerNotFound(HttpServer httpServer) throws Exception {
startServer(httpServer);
URI url = new URI("http://localhost:" + this.port + "/oops");
RequestEntity<Void> request = RequestEntity.get(url).build();
try {

View File

@@ -16,8 +16,8 @@
package org.springframework.web.reactive.result.condition;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
import org.springframework.mock.web.test.server.MockServerWebExchange;
@@ -42,7 +42,7 @@ public class CompositeRequestConditionTests {
private HeadersRequestCondition header3;
@Before
@BeforeEach
public void setup() throws Exception {
this.param1 = new ParamsRequestCondition("param1");
this.param2 = new ParamsRequestCondition("param2");

View File

@@ -19,7 +19,7 @@ package org.springframework.web.reactive.result.condition;
import java.util.Collection;
import java.util.Collections;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpHeaders;
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;

View File

@@ -18,7 +18,7 @@ package org.springframework.web.reactive.result.condition;
import java.util.Collection;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.mock.web.test.server.MockServerWebExchange;
import org.springframework.web.server.ServerWebExchange;

View File

@@ -18,7 +18,7 @@ package org.springframework.web.reactive.result.condition;
import java.util.Collection;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.mock.web.test.server.MockServerWebExchange;
import org.springframework.web.server.ServerWebExchange;

View File

@@ -20,7 +20,7 @@ import java.util.Arrays;
import java.util.Iterator;
import java.util.stream.Collectors;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.mock.web.test.server.MockServerWebExchange;
import org.springframework.web.server.ServerWebExchange;

View File

@@ -19,7 +19,7 @@ package org.springframework.web.reactive.result.condition;
import java.util.Collection;
import java.util.Collections;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;
import org.springframework.mock.web.test.server.MockServerWebExchange;

View File

@@ -16,7 +16,7 @@
package org.springframework.web.reactive.result.condition;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
import org.springframework.mock.web.test.server.MockServerWebExchange;

View File

@@ -21,8 +21,8 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
@@ -47,7 +47,7 @@ import static org.springframework.web.reactive.result.method.RequestMappingInfo.
*/
public class RequestMappingInfoTests {
// TODO: CORS pre-flight (see @Ignore)
// TODO: CORS pre-flight (see @Disabled)
@Test
@@ -274,7 +274,7 @@ public class RequestMappingInfoTests {
}
@Test
@Ignore
@Disabled
public void preFlightRequest() throws Exception {
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.options("/foo")
.header("Origin", "https://domain.com")

View File

@@ -19,8 +19,8 @@ package org.springframework.web.reactive.result.condition;
import java.net.URISyntaxException;
import java.util.Collections;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
@@ -44,7 +44,7 @@ import static org.springframework.web.bind.annotation.RequestMethod.PUT;
*/
public class RequestMethodsRequestConditionTests {
// TODO: custom method, CORS pre-flight (see @Ignored)
// TODO: custom method, CORS pre-flight (see @Disabledd)
@Test
public void getMatchingCondition() throws Exception {
@@ -73,7 +73,7 @@ public class RequestMethodsRequestConditionTests {
}
@Test
@Ignore
@Disabled
public void getMatchingConditionWithCustomMethod() throws Exception {
ServerWebExchange exchange = getExchange("PROPFIND");
assertThat(new RequestMethodsRequestCondition().getMatchingCondition(exchange)).isNotNull();
@@ -81,7 +81,7 @@ public class RequestMethodsRequestConditionTests {
}
@Test
@Ignore
@Disabled
public void getMatchingConditionWithCorsPreFlight() throws Exception {
ServerWebExchange exchange = getExchange("OPTIONS");
exchange.getRequest().getHeaders().add("Origin", "https://example.com");

View File

@@ -20,8 +20,8 @@ import java.lang.reflect.Method;
import java.util.Comparator;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
@@ -55,7 +55,7 @@ public class HandlerMethodMappingTests {
private Method method2;
@Before
@BeforeEach
public void setup() throws Exception {
this.mapping = new MyHandlerMethodMapping();
this.handler = new MyHandler();

View File

@@ -23,7 +23,7 @@ import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;

View File

@@ -27,8 +27,8 @@ import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
@@ -87,7 +87,7 @@ public class RequestMappingInfoHandlerMappingTests {
private TestRequestMappingInfoHandlerMapping handlerMapping;
@Before
@BeforeEach
public void setup() {
this.handlerMapping = new TestRequestMappingInfoHandlerMapping();
this.handlerMapping.registerHandler(new TestController());

View File

@@ -17,7 +17,7 @@ package org.springframework.web.reactive.result.method.annotation;
import java.io.File;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;

View File

@@ -20,7 +20,7 @@ import java.lang.reflect.Method;
import java.time.Duration;
import java.util.Collections;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.beans.FatalBeanException;
import org.springframework.context.ApplicationContext;

View File

@@ -16,7 +16,6 @@
package org.springframework.web.reactive.result.method.annotation;
import org.junit.Test;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
@@ -24,6 +23,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.http.server.reactive.bootstrap.HttpServer;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.MatrixVariable;
import org.springframework.web.bind.annotation.RequestParam;
@@ -41,7 +41,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* </ul>
* @author Rossen Stoyanchev
*/
public class ControllerInputIntegrationTests extends AbstractRequestMappingIntegrationTests {
class ControllerInputIntegrationTests extends AbstractRequestMappingIntegrationTests {
@Override
protected ApplicationContext initApplicationContext() {
@@ -52,20 +52,26 @@ public class ControllerInputIntegrationTests extends AbstractRequestMappingInteg
}
@Test
public void handleWithParam() throws Exception {
@ParameterizedHttpServerTest
void handleWithParam(HttpServer httpServer) throws Exception {
startServer(httpServer);
String expected = "Hello George!";
assertThat(performGet("/param?name=George", new HttpHeaders(), String.class).getBody()).isEqualTo(expected);
}
@Test // SPR-15140
public void handleWithEncodedParam() throws Exception {
@ParameterizedHttpServerTest // SPR-15140
void handleWithEncodedParam(HttpServer httpServer) throws Exception {
startServer(httpServer);
String expected = "Hello + \u00e0!";
assertThat(performGet("/param?name=%20%2B+%C3%A0", new HttpHeaders(), String.class).getBody()).isEqualTo(expected);
}
@Test
public void matrixVariable() throws Exception {
@ParameterizedHttpServerTest
void matrixVariable(HttpServer httpServer) throws Exception {
startServer(httpServer);
String expected = "p=11, q2=22, q4=44";
String url = "/first;p=11/second;q=22/third-fourth;q=44";
assertThat(performGet(url, new HttpHeaders(), String.class).getBody()).isEqualTo(expected);

View File

@@ -20,8 +20,8 @@ import java.lang.reflect.Method;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@@ -61,7 +61,7 @@ public class ControllerMethodResolverTests {
private HandlerMethod handlerMethod;
@Before
@BeforeEach
public void setup() {
ArgumentResolverConfigurer resolvers = new ArgumentResolverConfigurer();
resolvers.addCustomResolver(new CustomArgumentResolver());

View File

@@ -18,8 +18,8 @@ package org.springframework.web.reactive.result.method.annotation;
import java.lang.reflect.Method;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
@@ -55,7 +55,7 @@ public class CookieValueMethodArgumentResolverTests {
private MethodParameter cookieMonoParameter;
@Before
@BeforeEach
@SuppressWarnings("resource")
public void setup() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();

View File

@@ -18,9 +18,6 @@ package org.springframework.web.reactive.result.method.annotation;
import java.util.Properties;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
@@ -32,6 +29,7 @@ import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.server.reactive.bootstrap.HttpServer;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
@@ -49,20 +47,19 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Sebastien Deleuze
* @author Rossen Stoyanchev
* @author Sam Brannen
*/
public class CrossOriginAnnotationIntegrationTests extends AbstractRequestMappingIntegrationTests {
class CrossOriginAnnotationIntegrationTests extends AbstractRequestMappingIntegrationTests {
private HttpHeaders headers;
private final HttpHeaders headers = new HttpHeaders();
@Before
public void setup() throws Exception {
super.setup();
this.headers = new HttpHeaders();
@Override
protected void startServer(HttpServer httpServer) throws Exception {
super.startServer(httpServer);
this.headers.setOrigin("https://site1.com");
}
@Override
protected ApplicationContext initApplicationContext() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
@@ -82,24 +79,30 @@ public class CrossOriginAnnotationIntegrationTests extends AbstractRequestMappin
}
@Test
public void actualGetRequestWithoutAnnotation() throws Exception {
@ParameterizedHttpServerTest
void actualGetRequestWithoutAnnotation(HttpServer httpServer) throws Exception {
startServer(httpServer);
ResponseEntity<String> entity = performGet("/no", this.headers, String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getHeaders().getAccessControlAllowOrigin()).isNull();
assertThat(entity.getBody()).isEqualTo("no");
}
@Test
public void actualPostRequestWithoutAnnotation() throws Exception {
@ParameterizedHttpServerTest
void actualPostRequestWithoutAnnotation(HttpServer httpServer) throws Exception {
startServer(httpServer);
ResponseEntity<String> entity = performPost("/no", this.headers, null, String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getHeaders().getAccessControlAllowOrigin()).isNull();
assertThat(entity.getBody()).isEqualTo("no-post");
}
@Test
public void actualRequestWithDefaultAnnotation() throws Exception {
@ParameterizedHttpServerTest
void actualRequestWithDefaultAnnotation(HttpServer httpServer) throws Exception {
startServer(httpServer);
ResponseEntity<String> entity = performGet("/default", this.headers, String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getHeaders().getAccessControlAllowOrigin()).isEqualTo("*");
@@ -107,8 +110,10 @@ public class CrossOriginAnnotationIntegrationTests extends AbstractRequestMappin
assertThat(entity.getBody()).isEqualTo("default");
}
@Test
public void preflightRequestWithDefaultAnnotation() throws Exception {
@ParameterizedHttpServerTest
void preflightRequestWithDefaultAnnotation(HttpServer httpServer) throws Exception {
startServer(httpServer);
this.headers.add(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
ResponseEntity<Void> entity = performOptions("/default", this.headers, Void.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
@@ -117,8 +122,10 @@ public class CrossOriginAnnotationIntegrationTests extends AbstractRequestMappin
assertThat(entity.getHeaders().getAccessControlAllowCredentials()).isFalse();
}
@Test
public void actualRequestWithDefaultAnnotationAndNoOrigin() throws Exception {
@ParameterizedHttpServerTest
void actualRequestWithDefaultAnnotationAndNoOrigin(HttpServer httpServer) throws Exception {
startServer(httpServer);
HttpHeaders headers = new HttpHeaders();
ResponseEntity<String> entity = performGet("/default", headers, String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
@@ -126,8 +133,10 @@ public class CrossOriginAnnotationIntegrationTests extends AbstractRequestMappin
assertThat(entity.getBody()).isEqualTo("default");
}
@Test
public void actualRequestWithCustomizedAnnotation() throws Exception {
@ParameterizedHttpServerTest
void actualRequestWithCustomizedAnnotation(HttpServer httpServer) throws Exception {
startServer(httpServer);
ResponseEntity<String> entity = performGet("/customized", this.headers, String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getHeaders().getAccessControlAllowOrigin()).isEqualTo("https://site1.com");
@@ -136,8 +145,10 @@ public class CrossOriginAnnotationIntegrationTests extends AbstractRequestMappin
assertThat(entity.getBody()).isEqualTo("customized");
}
@Test
public void preflightRequestWithCustomizedAnnotation() throws Exception {
@ParameterizedHttpServerTest
void preflightRequestWithCustomizedAnnotation(HttpServer httpServer) throws Exception {
startServer(httpServer);
this.headers.add(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
this.headers.add(HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS, "header1, header2");
ResponseEntity<String> entity = performOptions("/customized", this.headers, String.class);
@@ -151,24 +162,30 @@ public class CrossOriginAnnotationIntegrationTests extends AbstractRequestMappin
assertThat(entity.getHeaders().getAccessControlMaxAge()).isEqualTo(123);
}
@Test
public void customOriginDefinedViaValueAttribute() throws Exception {
@ParameterizedHttpServerTest
void customOriginDefinedViaValueAttribute(HttpServer httpServer) throws Exception {
startServer(httpServer);
ResponseEntity<String> entity = performGet("/origin-value-attribute", this.headers, String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getHeaders().getAccessControlAllowOrigin()).isEqualTo("https://site1.com");
assertThat(entity.getBody()).isEqualTo("value-attribute");
}
@Test
public void customOriginDefinedViaPlaceholder() throws Exception {
@ParameterizedHttpServerTest
void customOriginDefinedViaPlaceholder(HttpServer httpServer) throws Exception {
startServer(httpServer);
ResponseEntity<String> entity = performGet("/origin-placeholder", this.headers, String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getHeaders().getAccessControlAllowOrigin()).isEqualTo("https://site1.com");
assertThat(entity.getBody()).isEqualTo("placeholder");
}
@Test
public void classLevel() throws Exception {
@ParameterizedHttpServerTest
void classLevel(HttpServer httpServer) throws Exception {
startServer(httpServer);
ResponseEntity<String> entity = performGet("/foo", this.headers, String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getHeaders().getAccessControlAllowOrigin()).isEqualTo("*");
@@ -188,8 +205,10 @@ public class CrossOriginAnnotationIntegrationTests extends AbstractRequestMappin
assertThat(entity.getBody()).isEqualTo("baz");
}
@Test
public void ambiguousHeaderPreflightRequest() throws Exception {
@ParameterizedHttpServerTest
void ambiguousHeaderPreflightRequest(HttpServer httpServer) throws Exception {
startServer(httpServer);
this.headers.add(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
this.headers.add(HttpHeaders.ACCESS_CONTROL_REQUEST_HEADERS, "header1");
ResponseEntity<String> entity = performOptions("/ambiguous-header", this.headers, String.class);
@@ -201,8 +220,10 @@ public class CrossOriginAnnotationIntegrationTests extends AbstractRequestMappin
assertThat(entity.getHeaders().getAccessControlAllowCredentials()).isTrue();
}
@Test
public void ambiguousProducesPreflightRequest() throws Exception {
@ParameterizedHttpServerTest
void ambiguousProducesPreflightRequest(HttpServer httpServer) throws Exception {
startServer(httpServer);
this.headers.add(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
ResponseEntity<String> entity = performOptions("/ambiguous-produces", this.headers, String.class);

View File

@@ -18,7 +18,7 @@ package org.springframework.web.reactive.result.method.annotation;
import java.time.Duration;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import reactor.core.publisher.MonoProcessor;

View File

@@ -18,8 +18,8 @@ package org.springframework.web.reactive.result.method.annotation;
import java.lang.reflect.Method;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import org.springframework.beans.factory.annotation.Value;
@@ -50,7 +50,7 @@ public class ExpressionValueMethodArgumentResolverTests {
private MethodParameter paramAlsoNotSupported;
@Before
@BeforeEach
@SuppressWarnings("resource")
public void setup() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();

View File

@@ -16,9 +16,6 @@
package org.springframework.web.reactive.result.method.annotation;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
@@ -29,6 +26,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.server.reactive.bootstrap.HttpServer;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.HttpClientErrorException;
@@ -46,26 +44,22 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
*
* @author Sebastien Deleuze
* @author Rossen Stoyanchev
* @author Sam Brannen
*/
public class GlobalCorsConfigIntegrationTests extends AbstractRequestMappingIntegrationTests {
class GlobalCorsConfigIntegrationTests extends AbstractRequestMappingIntegrationTests {
private HttpHeaders headers;
@Before
public void setup() throws Exception {
super.setup();
this.headers = new HttpHeaders();
this.headers.setOrigin("http://localhost:9000");
}
private final HttpHeaders headers = new HttpHeaders();
@Override
protected void startServer(HttpServer httpServer) throws Exception {
super.startServer(httpServer);
this.headers.setOrigin("http://localhost:9000");
}
@Override
protected ApplicationContext initApplicationContext() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(WebConfig.class);
context.refresh();
return context;
return new AnnotationConfigApplicationContext(WebConfig.class);
}
@Override
@@ -75,39 +69,49 @@ public class GlobalCorsConfigIntegrationTests extends AbstractRequestMappingInte
}
@Test
public void actualRequestWithCorsEnabled() throws Exception {
@ParameterizedHttpServerTest
void actualRequestWithCorsEnabled(HttpServer httpServer) throws Exception {
startServer(httpServer);
ResponseEntity<String> entity = performGet("/cors", this.headers, String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getHeaders().getAccessControlAllowOrigin()).isEqualTo("*");
assertThat(entity.getBody()).isEqualTo("cors");
}
@Test
public void actualRequestWithCorsRejected() throws Exception {
@ParameterizedHttpServerTest
void actualRequestWithCorsRejected(HttpServer httpServer) throws Exception {
startServer(httpServer);
assertThatExceptionOfType(HttpClientErrorException.class).isThrownBy(() ->
performGet("/cors-restricted", this.headers, String.class))
.satisfies(ex -> assertThat(ex.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN));
}
@Test
public void actualRequestWithoutCorsEnabled() throws Exception {
@ParameterizedHttpServerTest
void actualRequestWithoutCorsEnabled(HttpServer httpServer) throws Exception {
startServer(httpServer);
ResponseEntity<String> entity = performGet("/welcome", this.headers, String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getHeaders().getAccessControlAllowOrigin()).isNull();
assertThat(entity.getBody()).isEqualTo("welcome");
}
@Test
public void actualRequestWithAmbiguousMapping() throws Exception {
@ParameterizedHttpServerTest
void actualRequestWithAmbiguousMapping(HttpServer httpServer) throws Exception {
startServer(httpServer);
this.headers.add(HttpHeaders.ACCEPT, MediaType.TEXT_HTML_VALUE);
ResponseEntity<String> entity = performGet("/ambiguous", this.headers, String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getHeaders().getAccessControlAllowOrigin()).isEqualTo("*");
}
@Test
public void preFlightRequestWithCorsEnabled() throws Exception {
@ParameterizedHttpServerTest
void preFlightRequestWithCorsEnabled(HttpServer httpServer) throws Exception {
startServer(httpServer);
this.headers.add(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
ResponseEntity<String> entity = performOptions("/cors", this.headers, String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
@@ -116,24 +120,30 @@ public class GlobalCorsConfigIntegrationTests extends AbstractRequestMappingInte
.containsExactly(HttpMethod.GET, HttpMethod.HEAD, HttpMethod.POST);
}
@Test
public void preFlightRequestWithCorsRejected() throws Exception {
@ParameterizedHttpServerTest
void preFlightRequestWithCorsRejected(HttpServer httpServer) throws Exception {
startServer(httpServer);
this.headers.add(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
assertThatExceptionOfType(HttpClientErrorException.class).isThrownBy(() ->
performOptions("/cors-restricted", this.headers, String.class))
.satisfies(ex -> assertThat(ex.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN));
}
@Test
public void preFlightRequestWithoutCorsEnabled() throws Exception {
@ParameterizedHttpServerTest
void preFlightRequestWithoutCorsEnabled(HttpServer httpServer) throws Exception {
startServer(httpServer);
this.headers.add(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
assertThatExceptionOfType(HttpClientErrorException.class).isThrownBy(() ->
performOptions("/welcome", this.headers, String.class))
.satisfies(ex -> assertThat(ex.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN));
}
@Test
public void preFlightRequestWithCorsRestricted() throws Exception {
@ParameterizedHttpServerTest
void preFlightRequestWithCorsRestricted(HttpServer httpServer) throws Exception {
startServer(httpServer);
this.headers.set(HttpHeaders.ORIGIN, "https://foo");
this.headers.add(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
ResponseEntity<String> entity = performOptions("/cors-restricted", this.headers, String.class);
@@ -143,8 +153,10 @@ public class GlobalCorsConfigIntegrationTests extends AbstractRequestMappingInte
.containsExactly(HttpMethod.GET, HttpMethod.POST);
}
@Test
public void preFlightRequestWithAmbiguousMapping() throws Exception {
@ParameterizedHttpServerTest
void preFlightRequestWithAmbiguousMapping(HttpServer httpServer) throws Exception {
startServer(httpServer);
this.headers.add(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
ResponseEntity<String> entity = performOptions("/ambiguous", this.headers, String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);

View File

@@ -24,7 +24,7 @@ import java.util.concurrent.CompletableFuture;
import io.reactivex.BackpressureStrategy;
import io.reactivex.Flowable;
import io.reactivex.Maybe;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;

View File

@@ -21,7 +21,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
import org.springframework.core.ReactiveAdapterRegistry;

View File

@@ -20,7 +20,6 @@ import java.util.Arrays;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonView;
import org.junit.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@@ -31,6 +30,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpEntity;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.server.reactive.bootstrap.HttpServer;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@@ -42,7 +42,7 @@ import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Sebastien Deleuze
*/
public class JacksonHintsIntegrationTests extends AbstractRequestMappingIntegrationTests {
class JacksonHintsIntegrationTests extends AbstractRequestMappingIntegrationTests {
@Override
protected ApplicationContext initApplicationContext() {
@@ -53,54 +53,70 @@ public class JacksonHintsIntegrationTests extends AbstractRequestMappingIntegrat
}
@Test
public void jsonViewResponse() throws Exception {
@ParameterizedHttpServerTest
void jsonViewResponse(HttpServer httpServer) throws Exception {
startServer(httpServer);
String expected = "{\"withView1\":\"with\"}";
assertThat(performGet("/response/raw", MediaType.APPLICATION_JSON, String.class).getBody()).isEqualTo(expected);
}
@Test
public void jsonViewWithMonoResponse() throws Exception {
@ParameterizedHttpServerTest
void jsonViewWithMonoResponse(HttpServer httpServer) throws Exception {
startServer(httpServer);
String expected = "{\"withView1\":\"with\"}";
assertThat(performGet("/response/mono", MediaType.APPLICATION_JSON, String.class).getBody()).isEqualTo(expected);
}
@Test // SPR-16098
public void jsonViewWithMonoResponseEntity() throws Exception {
@ParameterizedHttpServerTest // SPR-16098
void jsonViewWithMonoResponseEntity(HttpServer httpServer) throws Exception {
startServer(httpServer);
String expected = "{\"withView1\":\"with\"}";
assertThat(performGet("/response/entity", MediaType.APPLICATION_JSON, String.class).getBody()).isEqualTo(expected);
}
@Test
public void jsonViewWithFluxResponse() throws Exception {
@ParameterizedHttpServerTest
void jsonViewWithFluxResponse(HttpServer httpServer) throws Exception {
startServer(httpServer);
String expected = "[{\"withView1\":\"with\"},{\"withView1\":\"with\"}]";
assertThat(performGet("/response/flux", MediaType.APPLICATION_JSON, String.class).getBody()).isEqualTo(expected);
}
@Test
public void jsonViewWithRequest() throws Exception {
@ParameterizedHttpServerTest
void jsonViewWithRequest(HttpServer httpServer) throws Exception {
startServer(httpServer);
String expected = "{\"withView1\":\"with\",\"withView2\":null,\"withoutView\":null}";
assertThat(performPost("/request/raw", MediaType.APPLICATION_JSON,
new JacksonViewBean("with", "with", "without"), MediaType.APPLICATION_JSON, String.class).getBody()).isEqualTo(expected);
}
@Test
public void jsonViewWithMonoRequest() throws Exception {
@ParameterizedHttpServerTest
void jsonViewWithMonoRequest(HttpServer httpServer) throws Exception {
startServer(httpServer);
String expected = "{\"withView1\":\"with\",\"withView2\":null,\"withoutView\":null}";
assertThat(performPost("/request/mono", MediaType.APPLICATION_JSON,
new JacksonViewBean("with", "with", "without"), MediaType.APPLICATION_JSON, String.class).getBody()).isEqualTo(expected);
}
@Test // SPR-16098
public void jsonViewWithEntityMonoRequest() throws Exception {
@ParameterizedHttpServerTest // SPR-16098
void jsonViewWithEntityMonoRequest(HttpServer httpServer) throws Exception {
startServer(httpServer);
String expected = "{\"withView1\":\"with\",\"withView2\":null,\"withoutView\":null}";
assertThat(performPost("/request/entity/mono", MediaType.APPLICATION_JSON,
new JacksonViewBean("with", "with", "without"),
MediaType.APPLICATION_JSON, String.class).getBody()).isEqualTo(expected);
}
@Test // SPR-16098
public void jsonViewWithEntityFluxRequest() throws Exception {
@ParameterizedHttpServerTest // SPR-16098
void jsonViewWithEntityFluxRequest(HttpServer httpServer) throws Exception {
startServer(httpServer);
String expected = "[" +
"{\"withView1\":\"with\",\"withView2\":null,\"withoutView\":null}," +
"{\"withView1\":\"with\",\"withView2\":null,\"withoutView\":null}]";
@@ -110,8 +126,10 @@ public class JacksonHintsIntegrationTests extends AbstractRequestMappingIntegrat
MediaType.APPLICATION_JSON, String.class).getBody()).isEqualTo(expected);
}
@Test
public void jsonViewWithFluxRequest() throws Exception {
@ParameterizedHttpServerTest
void jsonViewWithFluxRequest(HttpServer httpServer) throws Exception {
startServer(httpServer);
String expected = "[" +
"{\"withView1\":\"with\",\"withView2\":null,\"withoutView\":null}," +
"{\"withView1\":\"with\",\"withView2\":null,\"withoutView\":null}]";

View File

@@ -18,8 +18,6 @@ package org.springframework.web.reactive.result.method.annotation;
import java.time.Duration;
import org.junit.Before;
import org.junit.Test;
import reactor.core.publisher.Flux;
import reactor.test.StepVerifier;
@@ -29,6 +27,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.http.server.reactive.AbstractHttpHandlerIntegrationTests;
import org.springframework.http.server.reactive.HttpHandler;
import org.springframework.http.server.reactive.bootstrap.HttpServer;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.reactive.DispatcherHandler;
@@ -41,22 +40,15 @@ import static org.springframework.http.MediaType.APPLICATION_STREAM_JSON_VALUE;
/**
* @author Sebastien Deleuze
* @author Sam Brannen
*/
public class JacksonStreamingIntegrationTests extends AbstractHttpHandlerIntegrationTests {
class JacksonStreamingIntegrationTests extends AbstractHttpHandlerIntegrationTests {
private AnnotationConfigApplicationContext wac;
private WebClient webClient;
@Override
@Before
public void setup() throws Exception {
super.setup();
this.webClient = WebClient.create("http://localhost:" + this.port);
}
@Override
protected HttpHandler createHttpHandler() {
this.wac = new AnnotationConfigApplicationContext();
@@ -66,8 +58,17 @@ public class JacksonStreamingIntegrationTests extends AbstractHttpHandlerIntegra
return WebHttpHandlerBuilder.webHandler(new DispatcherHandler(this.wac)).build();
}
@Test
public void jsonStreaming() {
@Override
protected void startServer(HttpServer httpServer) throws Exception {
super.startServer(httpServer);
this.webClient = WebClient.create("http://localhost:" + this.port);
}
@ParameterizedHttpServerTest
void jsonStreaming(HttpServer httpServer) throws Exception {
startServer(httpServer);
Flux<Person> result = this.webClient.get()
.uri("/stream")
.accept(APPLICATION_STREAM_JSON)
@@ -81,8 +82,10 @@ public class JacksonStreamingIntegrationTests extends AbstractHttpHandlerIntegra
.verify();
}
@Test
public void smileStreaming() {
@ParameterizedHttpServerTest
void smileStreaming(HttpServer httpServer) throws Exception {
startServer(httpServer);
Flux<Person> result = this.webClient.get()
.uri("/stream")
.accept(new MediaType("application", "stream+x-jackson-smile"))
@@ -96,6 +99,7 @@ public class JacksonStreamingIntegrationTests extends AbstractHttpHandlerIntegra
.verify();
}
@RestController
@SuppressWarnings("unused")
static class JacksonStreamingController {

View File

@@ -21,8 +21,8 @@ import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.core.MethodParameter;
import org.springframework.core.ReactiveAdapterRegistry;
@@ -53,7 +53,7 @@ public class MatrixVariablesMapMethodArgumentResolverTests {
private final ResolvableMethod testMethod = ResolvableMethod.on(this.getClass()).named("handle").build();
@Before
@BeforeEach
public void setUp() throws Exception {
this.exchange.getAttributes().put(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE, new LinkedHashMap<>());
}

View File

@@ -21,8 +21,8 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.core.MethodParameter;
import org.springframework.core.ReactiveAdapterRegistry;
@@ -56,7 +56,7 @@ public class MatrixVariablesMethodArgumentResolverTests {
private ResolvableMethod testMethod = ResolvableMethod.on(this.getClass()).named("handle").build();
@Before
@BeforeEach
public void setUp() throws Exception {
this.exchange.getAttributes().put(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE, new LinkedHashMap<>());
}

View File

@@ -30,8 +30,8 @@ import javax.xml.bind.annotation.XmlRootElement;
import io.reactivex.Flowable;
import io.reactivex.Maybe;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
@@ -77,7 +77,7 @@ public class MessageReaderArgumentResolverTests {
private ResolvableMethod testMethod = ResolvableMethod.on(getClass()).named("handle").build();
@Before
@BeforeEach
public void setup() throws Exception {
ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
initializer.setValidator(new TestBeanValidator());

View File

@@ -29,7 +29,7 @@ import java.util.List;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeName;
import io.reactivex.Flowable;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;

View File

@@ -21,8 +21,8 @@ import java.time.Duration;
import java.util.Map;
import java.util.function.Function;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
import rx.RxReactiveStreams;
@@ -58,7 +58,7 @@ public class ModelAttributeMethodArgumentResolverTests {
private ResolvableMethod testMethod = ResolvableMethod.on(getClass()).named("handle").build();
@Before
@BeforeEach
public void setup() throws Exception {
LocalValidatorFactoryBean validator = new LocalValidatorFactoryBean();
validator.afterPropertiesSet();

View File

@@ -23,8 +23,8 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import rx.Single;
@@ -69,7 +69,7 @@ public class ModelInitializerTests {
private final ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path"));
@Before
@BeforeEach
public void setup() {
ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance();

View File

@@ -19,7 +19,7 @@ package org.springframework.web.reactive.result.method.annotation;
import java.time.Duration;
import java.util.Map;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.core.MethodParameter;
import org.springframework.core.ReactiveAdapterRegistry;

View File

@@ -25,8 +25,6 @@ import java.util.stream.Collectors;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.junit.Before;
import org.junit.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
@@ -45,6 +43,7 @@ import org.springframework.http.codec.multipart.MultipartHttpMessageReader;
import org.springframework.http.codec.multipart.Part;
import org.springframework.http.server.reactive.AbstractHttpHandlerIntegrationTests;
import org.springframework.http.server.reactive.HttpHandler;
import org.springframework.http.server.reactive.bootstrap.HttpServer;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
@@ -59,19 +58,11 @@ import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
import static org.assertj.core.api.Assertions.assertThat;
public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTests {
class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTests {
private WebClient webClient;
@Override
@Before
public void setup() throws Exception {
super.setup();
this.webClient = WebClient.create("http://localhost:" + this.port);
}
@Override
protected HttpHandler createHttpHandler() {
AnnotationConfigApplicationContext wac = new AnnotationConfigApplicationContext();
@@ -80,8 +71,17 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes
return WebHttpHandlerBuilder.webHandler(new DispatcherHandler(wac)).build();
}
@Test
public void requestPart() {
@Override
protected void startServer(HttpServer httpServer) throws Exception {
super.startServer(httpServer);
this.webClient = WebClient.create("http://localhost:" + this.port);
}
@ParameterizedHttpServerTest
void requestPart(HttpServer httpServer) throws Exception {
startServer(httpServer);
Mono<ClientResponse> result = webClient
.post()
.uri("/requestPart")
@@ -94,8 +94,10 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes
.verifyComplete();
}
@Test
public void requestBodyMap() {
@ParameterizedHttpServerTest
void requestBodyMap(HttpServer httpServer) throws Exception {
startServer(httpServer);
Mono<String> result = webClient
.post()
.uri("/requestBodyMap")
@@ -108,8 +110,10 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes
.verifyComplete();
}
@Test
public void requestBodyFlux() {
@ParameterizedHttpServerTest
void requestBodyFlux(HttpServer httpServer) throws Exception {
startServer(httpServer);
Mono<String> result = webClient
.post()
.uri("/requestBodyFlux")
@@ -122,8 +126,10 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes
.verifyComplete();
}
@Test
public void filePartsFlux() {
@ParameterizedHttpServerTest
void filePartsFlux(HttpServer httpServer) throws Exception {
startServer(httpServer);
Mono<String> result = webClient
.post()
.uri("/filePartFlux")
@@ -136,8 +142,10 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes
.verifyComplete();
}
@Test
public void filePartsMono() {
@ParameterizedHttpServerTest
void filePartsMono(HttpServer httpServer) throws Exception {
startServer(httpServer);
Mono<String> result = webClient
.post()
.uri("/filePartMono")
@@ -150,8 +158,10 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes
.verifyComplete();
}
@Test
public void transferTo() {
@ParameterizedHttpServerTest
void transferTo(HttpServer httpServer) throws Exception {
startServer(httpServer);
Flux<String> result = webClient
.post()
.uri("/transferTo")
@@ -166,20 +176,10 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes
}
private static void verifyContents(Path tempFile, Resource resource) {
try {
byte[] tempBytes = Files.readAllBytes(tempFile);
byte[] resourceBytes = Files.readAllBytes(resource.getFile().toPath());
assertThat(tempBytes).isEqualTo(resourceBytes);
}
catch (IOException ex) {
throw new AssertionError(ex);
}
}
@ParameterizedHttpServerTest
void modelAttribute(HttpServer httpServer) throws Exception {
startServer(httpServer);
@Test
public void modelAttribute() {
Mono<String> result = webClient
.post()
.uri("/modelAttribute")
@@ -201,6 +201,17 @@ public class MultipartIntegrationTests extends AbstractHttpHandlerIntegrationTes
return builder.build();
}
private static void verifyContents(Path tempFile, Resource resource) {
try {
byte[] tempBytes = Files.readAllBytes(tempFile);
byte[] resourceBytes = Files.readAllBytes(resource.getFile().toPath());
assertThat(tempBytes).isEqualTo(resourceBytes);
}
catch (IOException ex) {
throw new AssertionError(ex);
}
}
@Configuration
@EnableWebFlux

View File

@@ -21,8 +21,8 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import org.springframework.core.MethodParameter;
@@ -54,7 +54,7 @@ public class PathVariableMapMethodArgumentResolverTests {
private MethodParameter paramMonoMap;
@Before
@BeforeEach
public void setup() throws Exception {
this.resolver = new PathVariableMapMethodArgumentResolver(ReactiveAdapterRegistry.getSharedInstance());

View File

@@ -21,8 +21,8 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
@@ -61,7 +61,7 @@ public class PathVariableMethodArgumentResolverTests {
private MethodParameter paramMono;
@Before
@BeforeEach
public void setup() throws Exception {
this.resolver = new PathVariableMethodArgumentResolver(null, ReactiveAdapterRegistry.getSharedInstance());

Some files were not shown because too many files have changed in this diff Show More