Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -9,14 +9,14 @@ public class ParallelIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void runTests() {
|
||||
final Class<?>[] classes = {Example1IntegrationTest.class, Example2IntegrationTest.class};
|
||||
final Class<?>[] classes = { Example1IntegrationTest.class, Example2IntegrationTest.class };
|
||||
|
||||
JUnitCore.runClasses(new Computer(), classes);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void runTestsInParallel() {
|
||||
final Class<?>[] classes = {Example1IntegrationTest.class, Example2IntegrationTest.class};
|
||||
final Class<?>[] classes = { Example1IntegrationTest.class, Example2IntegrationTest.class };
|
||||
|
||||
JUnitCore.runClasses(new ParallelComputer(true, true), classes);
|
||||
}
|
||||
|
||||
@@ -50,5 +50,3 @@ public class Spring5JUnit4ConcurrentIntegrationTest implements ApplicationContex
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -23,10 +23,9 @@ public class FunctionalWebApplicationIntegrationTest {
|
||||
@BeforeClass
|
||||
public static void setup() throws Exception {
|
||||
server = new FunctionalWebApplication().start();
|
||||
client = WebTestClient
|
||||
.bindToServer()
|
||||
.baseUrl("http://localhost:" + server.getPort())
|
||||
.build();
|
||||
client = WebTestClient.bindToServer()
|
||||
.baseUrl("http://localhost:" + server.getPort())
|
||||
.build();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@@ -36,26 +35,24 @@ public class FunctionalWebApplicationIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void givenRouter_whenGetTest_thenGotHelloWorld() throws Exception {
|
||||
client
|
||||
.get()
|
||||
.uri("/test")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk()
|
||||
.expectBody(String.class)
|
||||
.isEqualTo("helloworld");
|
||||
client.get()
|
||||
.uri("/test")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk()
|
||||
.expectBody(String.class)
|
||||
.isEqualTo("helloworld");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenIndexFilter_whenRequestRoot_thenRewrittenToTest() throws Exception {
|
||||
client
|
||||
.get()
|
||||
.uri("/")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk()
|
||||
.expectBody(String.class)
|
||||
.isEqualTo("helloworld");
|
||||
client.get()
|
||||
.uri("/")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk()
|
||||
.expectBody(String.class)
|
||||
.isEqualTo("helloworld");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -64,16 +61,15 @@ public class FunctionalWebApplicationIntegrationTest {
|
||||
formData.add("user", "baeldung");
|
||||
formData.add("token", "you_know_what_to_do");
|
||||
|
||||
client
|
||||
.post()
|
||||
.uri("/login")
|
||||
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
|
||||
.body(BodyInserters.fromFormData(formData))
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk()
|
||||
.expectBody(String.class)
|
||||
.isEqualTo("welcome back!");
|
||||
client.post()
|
||||
.uri("/login")
|
||||
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
|
||||
.body(BodyInserters.fromFormData(formData))
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk()
|
||||
.expectBody(String.class)
|
||||
.isEqualTo("welcome back!");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -82,70 +78,64 @@ public class FunctionalWebApplicationIntegrationTest {
|
||||
formData.add("user", "baeldung");
|
||||
formData.add("token", "try_again");
|
||||
|
||||
client
|
||||
.post()
|
||||
.uri("/login")
|
||||
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
|
||||
.body(BodyInserters.fromFormData(formData))
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isBadRequest();
|
||||
client.post()
|
||||
.uri("/login")
|
||||
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
|
||||
.body(BodyInserters.fromFormData(formData))
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isBadRequest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenUploadForm_whenRequestWithMultipartData_thenSuccess() throws Exception {
|
||||
Resource resource = new ClassPathResource("/baeldung-weekly.png");
|
||||
client
|
||||
.post()
|
||||
.uri("/upload")
|
||||
.contentType(MediaType.MULTIPART_FORM_DATA)
|
||||
.body(fromResource(resource))
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk()
|
||||
.expectBody(String.class)
|
||||
.isEqualTo(String.valueOf(resource.contentLength()));
|
||||
client.post()
|
||||
.uri("/upload")
|
||||
.contentType(MediaType.MULTIPART_FORM_DATA)
|
||||
.body(fromResource(resource))
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk()
|
||||
.expectBody(String.class)
|
||||
.isEqualTo(String.valueOf(resource.contentLength()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenActors_whenAddActor_thenAdded() throws Exception {
|
||||
client
|
||||
.get()
|
||||
.uri("/actor")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk()
|
||||
.expectBodyList(Actor.class)
|
||||
.hasSize(2);
|
||||
client.get()
|
||||
.uri("/actor")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk()
|
||||
.expectBodyList(Actor.class)
|
||||
.hasSize(2);
|
||||
|
||||
client
|
||||
.post()
|
||||
.uri("/actor")
|
||||
.body(fromObject(new Actor("Clint", "Eastwood")))
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk();
|
||||
client.post()
|
||||
.uri("/actor")
|
||||
.body(fromObject(new Actor("Clint", "Eastwood")))
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk();
|
||||
|
||||
client
|
||||
.get()
|
||||
.uri("/actor")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk()
|
||||
.expectBodyList(Actor.class)
|
||||
.hasSize(3);
|
||||
client.get()
|
||||
.uri("/actor")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk()
|
||||
.expectBodyList(Actor.class)
|
||||
.hasSize(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenResources_whenAccess_thenGot() throws Exception {
|
||||
client
|
||||
.get()
|
||||
.uri("/files/hello.txt")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk()
|
||||
.expectBody(String.class)
|
||||
.isEqualTo("hello");
|
||||
client.get()
|
||||
.uri("/files/hello.txt")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk()
|
||||
.expectBody(String.class)
|
||||
.isEqualTo("hello");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,18 +11,14 @@ class Spring5JUnit5ParallelIntegrationTest {
|
||||
|
||||
@Test
|
||||
void givenTwoTestClasses_whenJUnitRunParallel_thenTheTestsExecutingParallel() {
|
||||
final Class<?>[] classes = {
|
||||
Example1IntegrationTest.class, Example2IntegrationTest.class
|
||||
};
|
||||
final Class<?>[] classes = { Example1IntegrationTest.class, Example2IntegrationTest.class };
|
||||
|
||||
JUnitCore.runClasses(new ParallelComputer(true, true), classes);
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenTwoTestClasses_whenJUnitRunParallel_thenTheTestsExecutingLinear() {
|
||||
final Class<?>[] classes = {
|
||||
Example1IntegrationTest.class, Example2IntegrationTest.class
|
||||
};
|
||||
final Class<?>[] classes = { Example1IntegrationTest.class, Example2IntegrationTest.class };
|
||||
|
||||
JUnitCore.runClasses(new Computer(), classes);
|
||||
}
|
||||
|
||||
@@ -16,18 +16,16 @@ class Spring5Java8NewFeaturesIntegrationTest {
|
||||
}
|
||||
|
||||
public class StringUtils {
|
||||
FunctionalInterfaceExample<String, String>
|
||||
functionLambdaString = s -> Pattern.compile(" +").splitAsStream(s)
|
||||
.map(word -> new StringBuilder(word).reverse())
|
||||
.collect(Collectors.joining(" "));
|
||||
FunctionalInterfaceExample<String, String> functionLambdaString = s -> Pattern.compile(" +")
|
||||
.splitAsStream(s)
|
||||
.map(word -> new StringBuilder(word).reverse())
|
||||
.collect(Collectors.joining(" "));
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenStringUtil_whenSupplierCall_thenFunctionalInterfaceReverseString()
|
||||
throws Exception {
|
||||
void givenStringUtil_whenSupplierCall_thenFunctionalInterfaceReverseString() throws Exception {
|
||||
Supplier<StringUtils> stringUtilsSupplier = StringUtils::new;
|
||||
|
||||
assertEquals(stringUtilsSupplier.get().functionLambdaString
|
||||
.reverseString("hello"), "olleh");
|
||||
assertEquals(stringUtilsSupplier.get().functionLambdaString.reverseString("hello"), "olleh");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,20 +25,15 @@ public class Spring5ReactiveServerClientIntegrationTest {
|
||||
@BeforeAll
|
||||
public static void setUp() throws Exception {
|
||||
HttpServer server = HttpServer.create("localhost", 8080);
|
||||
RouterFunction<?> route = RouterFunctions
|
||||
.route(POST("/task/process"), request -> ServerResponse
|
||||
.ok()
|
||||
.body(request
|
||||
.bodyToFlux(Task.class)
|
||||
.map(ll -> new Task("TaskName", 1)), Task.class))
|
||||
.and(RouterFunctions.route(GET("/task"), request -> ServerResponse
|
||||
.ok()
|
||||
.body(Mono.just("server is alive"), String.class)));
|
||||
RouterFunction<?> route = RouterFunctions.route(POST("/task/process"), request -> ServerResponse.ok()
|
||||
.body(request.bodyToFlux(Task.class)
|
||||
.map(ll -> new Task("TaskName", 1)), Task.class))
|
||||
.and(RouterFunctions.route(GET("/task"), request -> ServerResponse.ok()
|
||||
.body(Mono.just("server is alive"), String.class)));
|
||||
HttpHandler httpHandler = RouterFunctions.toHttpHandler(route);
|
||||
ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(httpHandler);
|
||||
nettyContext = server
|
||||
.newHandler(adapter)
|
||||
.block();
|
||||
nettyContext = server.newHandler(adapter)
|
||||
.block();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
@@ -46,55 +41,54 @@ public class Spring5ReactiveServerClientIntegrationTest {
|
||||
nettyContext.dispose();
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void givenCheckTask_whenServerHandle_thenServerResponseALiveString() throws Exception {
|
||||
// WebClient client = WebClient.create("http://localhost:8080");
|
||||
// Mono<String> result = client
|
||||
// .get()
|
||||
// .uri("/task")
|
||||
// .exchange()
|
||||
// .then(response -> response.bodyToMono(String.class));
|
||||
//
|
||||
// assertThat(result.block()).isInstanceOf(String.class);
|
||||
// }
|
||||
// @Test
|
||||
// public void givenCheckTask_whenServerHandle_thenServerResponseALiveString() throws Exception {
|
||||
// WebClient client = WebClient.create("http://localhost:8080");
|
||||
// Mono<String> result = client
|
||||
// .get()
|
||||
// .uri("/task")
|
||||
// .exchange()
|
||||
// .then(response -> response.bodyToMono(String.class));
|
||||
//
|
||||
// assertThat(result.block()).isInstanceOf(String.class);
|
||||
// }
|
||||
|
||||
// @Test
|
||||
// public void givenThreeTasks_whenServerHandleTheTasks_thenServerResponseATask() throws Exception {
|
||||
// URI uri = URI.create("http://localhost:8080/task/process");
|
||||
// ExchangeFunction exchange = ExchangeFunctions.create(new ReactorClientHttpConnector());
|
||||
// ClientRequest request = ClientRequest
|
||||
// .method(HttpMethod.POST, uri)
|
||||
// .body(BodyInserters.fromPublisher(getLatLngs(), Task.class))
|
||||
// .build();
|
||||
//
|
||||
// Flux<Task> taskResponse = exchange
|
||||
// .exchange(request)
|
||||
// .flatMap(response -> response.bodyToFlux(Task.class));
|
||||
//
|
||||
// assertThat(taskResponse.blockFirst()).isInstanceOf(Task.class);
|
||||
// }
|
||||
// @Test
|
||||
// public void givenThreeTasks_whenServerHandleTheTasks_thenServerResponseATask() throws Exception {
|
||||
// URI uri = URI.create("http://localhost:8080/task/process");
|
||||
// ExchangeFunction exchange = ExchangeFunctions.create(new ReactorClientHttpConnector());
|
||||
// ClientRequest request = ClientRequest
|
||||
// .method(HttpMethod.POST, uri)
|
||||
// .body(BodyInserters.fromPublisher(getLatLngs(), Task.class))
|
||||
// .build();
|
||||
//
|
||||
// Flux<Task> taskResponse = exchange
|
||||
// .exchange(request)
|
||||
// .flatMap(response -> response.bodyToFlux(Task.class));
|
||||
//
|
||||
// assertThat(taskResponse.blockFirst()).isInstanceOf(Task.class);
|
||||
// }
|
||||
|
||||
// @Test
|
||||
// public void givenCheckTask_whenServerHandle_thenOragicServerResponseALiveString() throws Exception {
|
||||
// URI uri = URI.create("http://localhost:8080/task");
|
||||
// ExchangeFunction exchange = ExchangeFunctions.create(new ReactorClientHttpConnector());
|
||||
// ClientRequest request = ClientRequest
|
||||
// .method(HttpMethod.GET, uri)
|
||||
// .body(BodyInserters.fromPublisher(getLatLngs(), Task.class))
|
||||
// .build();
|
||||
//
|
||||
// Flux<String> taskResponse = exchange
|
||||
// .exchange(request)
|
||||
// .flatMap(response -> response.bodyToFlux(String.class));
|
||||
//
|
||||
// assertThat(taskResponse.blockFirst()).isInstanceOf(String.class);
|
||||
// }
|
||||
// @Test
|
||||
// public void givenCheckTask_whenServerHandle_thenOragicServerResponseALiveString() throws Exception {
|
||||
// URI uri = URI.create("http://localhost:8080/task");
|
||||
// ExchangeFunction exchange = ExchangeFunctions.create(new ReactorClientHttpConnector());
|
||||
// ClientRequest request = ClientRequest
|
||||
// .method(HttpMethod.GET, uri)
|
||||
// .body(BodyInserters.fromPublisher(getLatLngs(), Task.class))
|
||||
// .build();
|
||||
//
|
||||
// Flux<String> taskResponse = exchange
|
||||
// .exchange(request)
|
||||
// .flatMap(response -> response.bodyToFlux(String.class));
|
||||
//
|
||||
// assertThat(taskResponse.blockFirst()).isInstanceOf(String.class);
|
||||
// }
|
||||
|
||||
private static Flux<Task> getLatLngs() {
|
||||
return Flux
|
||||
.range(0, 3)
|
||||
.zipWith(Flux.interval(Duration.ofSeconds(1)))
|
||||
.map(x -> new Task("taskname", 1))
|
||||
.doOnNext(ll -> System.out.println("Produced: {}" + ll));
|
||||
return Flux.range(0, 3)
|
||||
.zipWith(Flux.interval(Duration.ofSeconds(1)))
|
||||
.map(x -> new Task("taskname", 1))
|
||||
.doOnNext(ll -> System.out.println("Produced: {}" + ll));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,85 +17,85 @@ public class PathPatternsUsingHandlerMethodIntegrationTest {
|
||||
@BeforeClass
|
||||
public static void setUp() {
|
||||
client = WebTestClient.bindToController(new PathPatternController())
|
||||
.build();
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenHandlerMethod_whenMultipleURIVariablePattern_then200() {
|
||||
|
||||
client.get()
|
||||
.uri("/spring5/ab/cd")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.is2xxSuccessful()
|
||||
.expectBody()
|
||||
.equals("/ab/cd");
|
||||
.uri("/spring5/ab/cd")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.is2xxSuccessful()
|
||||
.expectBody()
|
||||
.equals("/ab/cd");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenHandlerMethod_whenURLWithWildcardTakingZeroOrMoreChar_then200() {
|
||||
|
||||
client.get()
|
||||
.uri("/spring5/userid")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.is2xxSuccessful()
|
||||
.expectBody()
|
||||
.equals("/spring5/*id");
|
||||
.uri("/spring5/userid")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.is2xxSuccessful()
|
||||
.expectBody()
|
||||
.equals("/spring5/*id");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenHandlerMethod_whenURLWithWildcardTakingExactlyOneChar_then200() {
|
||||
|
||||
client.get()
|
||||
.uri("/string5")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.is2xxSuccessful()
|
||||
.expectBody()
|
||||
.equals("/s?ring5");
|
||||
.uri("/string5")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.is2xxSuccessful()
|
||||
.expectBody()
|
||||
.equals("/s?ring5");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenHandlerMethod_whenURLWithWildcardTakingZeroOrMorePathSegments_then200() {
|
||||
|
||||
client.get()
|
||||
.uri("/resources/baeldung")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.is2xxSuccessful()
|
||||
.expectBody()
|
||||
.equals("/resources/**");
|
||||
.uri("/resources/baeldung")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.is2xxSuccessful()
|
||||
.expectBody()
|
||||
.equals("/resources/**");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenHandlerMethod_whenURLWithRegexInPathVariable_thenExpectedOutput() {
|
||||
|
||||
client.get()
|
||||
.uri("/abc")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.is2xxSuccessful()
|
||||
.expectBody()
|
||||
.equals("abc");
|
||||
.uri("/abc")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.is2xxSuccessful()
|
||||
.expectBody()
|
||||
.equals("abc");
|
||||
|
||||
client.get()
|
||||
.uri("/123")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.is4xxClientError();
|
||||
.uri("/123")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.is4xxClientError();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenHandlerMethod_whenURLWithMultiplePathVariablesInSameSegment_then200() {
|
||||
|
||||
client.get()
|
||||
.uri("/baeldung_tutorial")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.is2xxSuccessful()
|
||||
.expectBody()
|
||||
.equals("Two variables are var1=baeldung and var2=tutorial");
|
||||
.uri("/baeldung_tutorial")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.is2xxSuccessful()
|
||||
.expectBody()
|
||||
.equals("Two variables are var1=baeldung and var2=tutorial");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,38 +21,40 @@ public class WebTestClientTest {
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
|
||||
private final RouterFunction ROUTER_FUNCTION = RouterFunctions.route(
|
||||
RequestPredicates.GET("/resource"),
|
||||
request -> ServerResponse.ok().build()
|
||||
);
|
||||
private final RouterFunction ROUTER_FUNCTION = RouterFunctions.route(RequestPredicates.GET("/resource"), request -> ServerResponse.ok()
|
||||
.build());
|
||||
private final WebHandler WEB_HANDLER = exchange -> Mono.empty();
|
||||
|
||||
@Test
|
||||
public void testWebTestClientWithServerWebHandler() {
|
||||
WebTestClient.bindToWebHandler(WEB_HANDLER).build();
|
||||
WebTestClient.bindToWebHandler(WEB_HANDLER)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWebTestClientWithRouterFunction() {
|
||||
WebTestClient
|
||||
.bindToRouterFunction(ROUTER_FUNCTION)
|
||||
.build().get().uri("/resource")
|
||||
.exchange()
|
||||
.expectStatus().isOk()
|
||||
.expectBody().isEmpty();
|
||||
WebTestClient.bindToRouterFunction(ROUTER_FUNCTION)
|
||||
.build()
|
||||
.get()
|
||||
.uri("/resource")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk()
|
||||
.expectBody()
|
||||
.isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWebTestClientWithServerURL() {
|
||||
WebTestClient
|
||||
.bindToServer()
|
||||
.baseUrl("http://localhost:" + port)
|
||||
.build()
|
||||
.get()
|
||||
.uri("/resource")
|
||||
.exchange()
|
||||
.expectStatus().is4xxClientError()
|
||||
.expectBody();
|
||||
WebTestClient.bindToServer()
|
||||
.baseUrl("http://localhost:" + port)
|
||||
.build()
|
||||
.get()
|
||||
.uri("/resource")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.is4xxClientError()
|
||||
.expectBody();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user