From c1e93d8991516229771ab123b9ad1409396f5e25 Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Thu, 23 Feb 2017 11:33:56 +0100 Subject: [PATCH] Add WebFlux application sample This commit adds a sample application for the annotation variant of Spring WebFlux. --- spring-boot-samples/pom.xml | 1 + .../spring-boot-sample-webflux/pom.xml | 54 ++++++++++++++++ .../webflux/SampleWebFluxApplication.java | 30 +++++++++ .../sample/webflux/WelcomeController.java | 30 +++++++++ .../src/main/resources/application.properties | 0 ...pleWebFluxApplicationIntegrationTests.java | 64 +++++++++++++++++++ .../SampleWebFluxApplicationTests.java | 41 ++++++++++++ 7 files changed, 220 insertions(+) create mode 100644 spring-boot-samples/spring-boot-sample-webflux/pom.xml create mode 100644 spring-boot-samples/spring-boot-sample-webflux/src/main/java/sample/webflux/SampleWebFluxApplication.java create mode 100644 spring-boot-samples/spring-boot-sample-webflux/src/main/java/sample/webflux/WelcomeController.java create mode 100644 spring-boot-samples/spring-boot-sample-webflux/src/main/resources/application.properties create mode 100644 spring-boot-samples/spring-boot-sample-webflux/src/test/java/sample/webflux/SampleWebFluxApplicationIntegrationTests.java create mode 100644 spring-boot-samples/spring-boot-sample-webflux/src/test/java/sample/webflux/SampleWebFluxApplicationTests.java diff --git a/spring-boot-samples/pom.xml b/spring-boot-samples/pom.xml index 200297db25..a6e3d53c1d 100644 --- a/spring-boot-samples/pom.xml +++ b/spring-boot-samples/pom.xml @@ -101,6 +101,7 @@ spring-boot-sample-web-secure-jdbc spring-boot-sample-web-static spring-boot-sample-web-ui + spring-boot-sample-webflux spring-boot-sample-websocket-jetty spring-boot-sample-websocket-tomcat spring-boot-sample-websocket-undertow diff --git a/spring-boot-samples/spring-boot-sample-webflux/pom.xml b/spring-boot-samples/spring-boot-sample-webflux/pom.xml new file mode 100644 index 0000000000..956da70874 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-webflux/pom.xml @@ -0,0 +1,54 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-samples + 2.0.0.BUILD-SNAPSHOT + + spring-boot-sample-webflux + Spring Boot WebFlux Sample + Spring Boot WebFlux Sample + http://projects.spring.io/spring-boot/ + + Pivotal Software, Inc. + http://www.spring.io + + + ${basedir}/../.. + / + + + + + org.springframework.boot + spring-boot-starter-webflux + + + + org.springframework.boot + spring-boot-starter-test + test + + + io.projectreactor.addons + reactor-test + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + + false + + + + + diff --git a/spring-boot-samples/spring-boot-sample-webflux/src/main/java/sample/webflux/SampleWebFluxApplication.java b/spring-boot-samples/spring-boot-sample-webflux/src/main/java/sample/webflux/SampleWebFluxApplication.java new file mode 100644 index 0000000000..f247a517d6 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-webflux/src/main/java/sample/webflux/SampleWebFluxApplication.java @@ -0,0 +1,30 @@ +/* + * Copyright 2012-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.webflux; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.WebApplicationType; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleWebFluxApplication { + + public static void main(String[] args) throws Exception { + SpringApplication.run(SampleWebFluxApplication.class); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-webflux/src/main/java/sample/webflux/WelcomeController.java b/spring-boot-samples/spring-boot-sample-webflux/src/main/java/sample/webflux/WelcomeController.java new file mode 100644 index 0000000000..b0d2c0dbb5 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-webflux/src/main/java/sample/webflux/WelcomeController.java @@ -0,0 +1,30 @@ +/* + * Copyright 2012-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.webflux; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class WelcomeController { + + @GetMapping("/") + public String welcome() { + return "Hello World"; + } + +} diff --git a/spring-boot-samples/spring-boot-sample-webflux/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-webflux/src/main/resources/application.properties new file mode 100644 index 0000000000..e69de29bb2 diff --git a/spring-boot-samples/spring-boot-sample-webflux/src/test/java/sample/webflux/SampleWebFluxApplicationIntegrationTests.java b/spring-boot-samples/spring-boot-sample-webflux/src/test/java/sample/webflux/SampleWebFluxApplicationIntegrationTests.java new file mode 100644 index 0000000000..66ced9899e --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-webflux/src/test/java/sample/webflux/SampleWebFluxApplicationIntegrationTests.java @@ -0,0 +1,64 @@ +/* + * Copyright 2012-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.webflux; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import reactor.core.publisher.Mono; +import reactor.test.StepVerifier; + +import org.springframework.boot.context.embedded.LocalServerPort; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.http.MediaType; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.reactive.function.client.WebClient; + +/** + * Basic integration tests for WebFlux application. + * + * @author Brian Clozel + */ +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +public class SampleWebFluxApplicationIntegrationTests { + + @LocalServerPort + private int port; + + private WebClient webClient; + + @Before + public void setUp() throws Exception { + this.webClient = WebClient.create("http://localhost:" + this.port); + } + + @Test + public void testWelcome() throws Exception { + Mono body = this.webClient + .get().uri("/") + .accept(MediaType.TEXT_PLAIN) + .exchange() + .then(response -> response.bodyToMono(String.class)); + + StepVerifier.create(body) + .expectNext("Hello World") + .verifyComplete(); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-webflux/src/test/java/sample/webflux/SampleWebFluxApplicationTests.java b/spring-boot-samples/spring-boot-sample-webflux/src/test/java/sample/webflux/SampleWebFluxApplicationTests.java new file mode 100644 index 0000000000..7574467f43 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-webflux/src/test/java/sample/webflux/SampleWebFluxApplicationTests.java @@ -0,0 +1,41 @@ +/* + * Copyright 2012-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.webflux; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * Basic integration tests for WebFlux application. + * + * @author Brian Clozel + */ +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = WebEnvironment.NONE) +public class SampleWebFluxApplicationTests { + + @Test + public void testSomething() throws Exception { + + } + + +}