diff --git a/spring-boot-samples/README.adoc b/spring-boot-samples/README.adoc index 7ab7709e5d..8905dcea27 100644 --- a/spring-boot-samples/README.adoc +++ b/spring-boot-samples/README.adoc @@ -132,6 +132,9 @@ The following sample applications are provided: | link:spring-boot-sample-jta-narayana[spring-boot-sample-jta-narayana] | JTA transactions with Narayana +| link:spring-boot-sample-junit-jupiter[spring-boot-sample-junit-jupiter] +| Demonstrates JUnit Jupiter-based testing + | link:spring-boot-sample-liquibase[spring-boot-sample-liquibase] | Database migrations with Liquibase diff --git a/spring-boot-samples/pom.xml b/spring-boot-samples/pom.xml index 8fa1bc4280..8e8d8ca645 100644 --- a/spring-boot-samples/pom.xml +++ b/spring-boot-samples/pom.xml @@ -63,6 +63,7 @@ spring-boot-sample-jta-bitronix spring-boot-sample-jta-narayana spring-boot-sample-jta-jndi + spring-boot-sample-junit-jupiter spring-boot-sample-liquibase spring-boot-sample-logback spring-boot-sample-metrics-dropwizard diff --git a/spring-boot-samples/spring-boot-sample-junit-jupiter/pom.xml b/spring-boot-samples/spring-boot-sample-junit-jupiter/pom.xml new file mode 100644 index 0000000000..5c3a57bfe2 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-junit-jupiter/pom.xml @@ -0,0 +1,76 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-samples + 2.0.0.BUILD-SNAPSHOT + + spring-boot-sample-junit-jupiter + Spring Boot JUnit Jupiter Sample + Spring Boot JUnit Jupiter Sample + http://projects.spring.io/spring-boot/ + + Pivotal Software, Inc. + http://www.spring.io + + + ${basedir}/../.. + 5.0.0-M6 + 1.0.0-M6 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + junit + junit + + + + + org.junit.jupiter + junit-jupiter-api + ${junit.jupiter.version} + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + + + org.junit.platform + junit-platform-surefire-provider + ${junit.platform.version} + + + org.junit.jupiter + junit-jupiter-engine + ${junit.jupiter.version} + + + + + + + diff --git a/spring-boot-samples/spring-boot-sample-junit-jupiter/src/main/java/sample/MessageController.java b/spring-boot-samples/spring-boot-sample-junit-jupiter/src/main/java/sample/MessageController.java new file mode 100644 index 0000000000..eda8760f30 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-junit-jupiter/src/main/java/sample/MessageController.java @@ -0,0 +1,33 @@ +/* + * 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; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author EddĂș MelĂ©ndez + */ +@RestController +public class MessageController { + + @GetMapping("/hi") + public String hello() { + return "Hello World"; + } + +} diff --git a/spring-boot-samples/spring-boot-sample-junit-jupiter/src/main/java/sample/SampleJunitJupiterApplication.java b/spring-boot-samples/spring-boot-sample-junit-jupiter/src/main/java/sample/SampleJunitJupiterApplication.java new file mode 100644 index 0000000000..2fd500d7ce --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-junit-jupiter/src/main/java/sample/SampleJunitJupiterApplication.java @@ -0,0 +1,29 @@ +/* + * 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; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleJunitJupiterApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleJunitJupiterApplication.class, args); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-junit-jupiter/src/test/java/sample/SampleJunitJupiterApplicationTests.java b/spring-boot-samples/spring-boot-sample-junit-jupiter/src/test/java/sample/SampleJunitJupiterApplicationTests.java new file mode 100644 index 0000000000..4fcc0b5b52 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-junit-jupiter/src/test/java/sample/SampleJunitJupiterApplicationTests.java @@ -0,0 +1,43 @@ +/* + * 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; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import static org.assertj.core.api.Assertions.assertThat; + +@ExtendWith(SpringExtension.class) +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +class SampleJunitJupiterApplicationTests { + + @Autowired + private TestRestTemplate restTemplate; + + @Test + void testMessage() { + String message = this.restTemplate.getForObject("/hi", String.class); + assertThat(message).isEqualTo("Hello World"); + } + +}