From eeb2d87c147414de5459845f23b9ec81a31b6d39 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Fri, 7 Feb 2020 13:43:30 +0100 Subject: [PATCH] made junit5 default test generation framework (#1320) fixes #1249 --- .../standalone/dsl/http-client/build.gradle | 6 +- .../java/com/example/loan/Application.java | 3 - .../main/java/com/example/loan/Listener.java | 13 +++-- .../src/main/resources/application.yml | 8 ++- .../com/example/loan/GoodbyeWorldTests.java | 8 +-- ...oanApplicationServiceContextPathTests.java | 8 +-- .../loan/LoanApplicationServiceTests.java | 12 ++-- .../example/loan/MessageConsumedTests.java | 7 +-- .../com/example/loan/TestControllerTests.java | 8 +-- .../standalone/dsl/http-server/build.gradle | 4 ++ samples/standalone/dsl/http-server/pom.xml | 6 ++ .../java/com/example/fraud/BinaryBase.java | 4 +- .../java/com/example/fraud/FraudBase.java | 4 +- .../java/com/example/fraud/FraudnameBase.java | 4 +- .../java/com/example/fraud/MessagingBase.java | 10 ++-- .../java/com/example/fraud/MultipartBase.java | 4 +- .../test/java/com/example/fraud/PactBase.java | 4 +- .../test/java/com/example/fraud/TestBase.java | 4 +- .../java/com/example/fraud/YmlFraudBase.java | 4 +- .../com/example/fraud/YmlFraudnameBase.java | 4 +- .../restdocs/http-client/build.gradle | 5 +- .../standalone/restdocs/http-client/pom.xml | 6 ++ .../loan/LoanApplicationServiceTests.java | 8 +-- ...pplicationServiceusingStubRunnerTests.java | 12 ++-- .../com/example/loan/XmlServiceTests.java | 8 +-- .../loan/XmlServiceUsingStubRunnerTests.java | 8 +-- .../restdocs/http-server/build.gradle | 3 +- .../standalone/restdocs/http-server/pom.xml | 1 + .../fraud/FraudBaseWithWebAppSetup.java | 1 + .../com/example/fraud/StubGeneratorTests.java | 2 + .../example/fraud/XmlStubGeneratorTests.java | 2 + .../webclient/http-client/build.gradle | 5 +- .../standalone/webclient/http-client/pom.xml | 6 ++ .../loan/LoanApplicationServiceTests.java | 8 +-- ...tionServiceusingStubRunnerGradleTests.java | 12 ++-- ...pplicationServiceusingStubRunnerTests.java | 12 ++-- .../webclient/http-server/build.gradle | 5 +- .../standalone/webclient/http-server/pom.xml | 6 ++ .../com/example/fraud/StubGeneratorTests.java | 12 ++-- samples/wiremock-jetty/pom.xml | 6 ++ .../WiremockForDocsClassRuleTests.java | 35 ++++++++---- ...mockForDocsMockServerApplicationTests.java | 8 +-- .../com/example/WiremockForDocsTests.java | 12 ++-- .../WiremockHttpsServerApplicationTests.java | 33 +++++++---- .../WiremockImportApplicationTests.java | 8 +-- .../WiremockMockServerApplicationTests.java | 8 +-- .../WiremockServerApplicationTests.java | 56 +++++++++++-------- samples/wiremock-native/pom.xml | 6 ++ .../WiremockServerApplicationTests.java | 33 +++++++---- samples/wiremock-tomcat/pom.xml | 6 ++ .../WiremockHttpsServerApplicationTests.java | 32 ++++++++--- .../WiremockImportApplicationTests.java | 8 +-- ...mockImportContextPathApplicationTests.java | 8 +-- .../WiremockMockServerApplicationTests.java | 8 +-- .../WiremockServerApplicationTests.java | 56 +++++++++++-------- samples/wiremock-undertow-ssl/pom.xml | 6 ++ .../WiremockHttpsServerApplicationTests.java | 33 +++++++---- samples/wiremock-undertow/pom.xml | 6 ++ .../WiremockImportApplicationTests.java | 8 +-- .../WiremockMockServerApplicationTests.java | 8 +-- .../WiremockServerApplicationTests.java | 32 ++++++++--- samples/wiremock/pom.xml | 6 ++ ...kFilesApplicationWithUrlResourceTests.java | 5 +- .../pom.xml | 6 ++ .../pom.xml | 23 +++++++- .../pom.xml | 6 ++ .../plugin/ContractVerifierExtension.java | 2 +- .../maven/verifier/GenerateTestsMojo.java | 2 +- spring-cloud-contract-verifier/pom.xml | 11 ++++ .../ContractVerifierConfigProperties.java | 2 +- .../builder/GeneratedTestClassTests.java | 2 + spring-cloud-contract-wiremock/pom.xml | 11 ++++ 72 files changed, 487 insertions(+), 252 deletions(-) diff --git a/samples/standalone/dsl/http-client/build.gradle b/samples/standalone/dsl/http-client/build.gradle index 0677aba160..6eb44116d4 100644 --- a/samples/standalone/dsl/http-client/build.gradle +++ b/samples/standalone/dsl/http-client/build.gradle @@ -38,12 +38,16 @@ dependencies { implementation("org.springframework.boot:spring-boot-starter-actuator") implementation("org.springframework.cloud:spring-cloud-starter-stream-rabbit") - testImplementation("org.springframework.cloud:spring-cloud-stream-test-support") + testImplementation(group: 'org.springframework.cloud', name: 'spring-cloud-stream', classifier: 'test-binder') testImplementation "org.springframework.cloud:spring-cloud-starter-contract-stub-runner" testImplementation "org.springframework.cloud:spring-cloud-starter-contract-verifier" + testImplementation('org.springframework.boot:spring-boot-starter-test') { + exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' + } } test { + useJUnitPlatform() systemProperty 'spring.profiles.active', 'gradle' testLogging { exceptionFormat = 'full' diff --git a/samples/standalone/dsl/http-client/src/main/java/com/example/loan/Application.java b/samples/standalone/dsl/http-client/src/main/java/com/example/loan/Application.java index 264481a18e..6e1c77d277 100644 --- a/samples/standalone/dsl/http-client/src/main/java/com/example/loan/Application.java +++ b/samples/standalone/dsl/http-client/src/main/java/com/example/loan/Application.java @@ -18,11 +18,8 @@ package com.example.loan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.cloud.stream.annotation.EnableBinding; -import org.springframework.cloud.stream.messaging.Sink; @SpringBootApplication -@EnableBinding(Sink.class) public class Application { public static void main(String[] args) { diff --git a/samples/standalone/dsl/http-client/src/main/java/com/example/loan/Listener.java b/samples/standalone/dsl/http-client/src/main/java/com/example/loan/Listener.java index 82b9d6e72c..51f6cd3015 100644 --- a/samples/standalone/dsl/http-client/src/main/java/com/example/loan/Listener.java +++ b/samples/standalone/dsl/http-client/src/main/java/com/example/loan/Listener.java @@ -16,16 +16,15 @@ package com.example.loan; -import org.springframework.cloud.stream.annotation.StreamListener; -import org.springframework.cloud.stream.messaging.Sink; +import java.util.function.Consumer; + import org.springframework.stereotype.Component; -@Component -class Listener { +@Component("listener") +class Listener implements Consumer { int count = 0; - @StreamListener(Sink.INPUT) public void logSensorData(SensorData data) { System.out.println(data); this.count = this.count + 1; @@ -35,4 +34,8 @@ class Listener { return this.count; } + @Override + public void accept(SensorData sensorData) { + this.logSensorData(sensorData); + } } diff --git a/samples/standalone/dsl/http-client/src/main/resources/application.yml b/samples/standalone/dsl/http-client/src/main/resources/application.yml index 4b7fe13158..2de2007e6b 100644 --- a/samples/standalone/dsl/http-client/src/main/resources/application.yml +++ b/samples/standalone/dsl/http-client/src/main/resources/application.yml @@ -1 +1,7 @@ -server.port: 8090 \ No newline at end of file +server.port: 8090 +spring: + cloud: + function: + definition: listener + stream: + bindings.listener-in-0.destination: sensor_data \ No newline at end of file diff --git a/samples/standalone/dsl/http-client/src/test/java/com/example/loan/GoodbyeWorldTests.java b/samples/standalone/dsl/http-client/src/test/java/com/example/loan/GoodbyeWorldTests.java index 9fa7519da4..1328eba404 100644 --- a/samples/standalone/dsl/http-client/src/test/java/com/example/loan/GoodbyeWorldTests.java +++ b/samples/standalone/dsl/http-client/src/test/java/com/example/loan/GoodbyeWorldTests.java @@ -16,21 +16,21 @@ package com.example.loan; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; + import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.cloud.contract.stubrunner.spring.AutoConfigureStubRunner; import org.springframework.cloud.contract.stubrunner.spring.StubRunnerPort; import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties; -import org.springframework.test.context.junit4.SpringRunner; + import org.springframework.web.client.RestTemplate; import static org.assertj.core.api.Assertions.assertThat; // tag::autoconfigure_stubrunner[] -@RunWith(SpringRunner.class) + @SpringBootTest(webEnvironment = WebEnvironment.NONE) @AutoConfigureStubRunner(ids = { "com.example:http-server-dsl"}, diff --git a/samples/standalone/dsl/http-client/src/test/java/com/example/loan/LoanApplicationServiceContextPathTests.java b/samples/standalone/dsl/http-client/src/test/java/com/example/loan/LoanApplicationServiceContextPathTests.java index 71b9b63f1b..f30cac7186 100644 --- a/samples/standalone/dsl/http-client/src/test/java/com/example/loan/LoanApplicationServiceContextPathTests.java +++ b/samples/standalone/dsl/http-client/src/test/java/com/example/loan/LoanApplicationServiceContextPathTests.java @@ -20,19 +20,19 @@ import com.example.loan.model.Client; import com.example.loan.model.LoanApplication; import com.example.loan.model.LoanApplicationResult; import com.example.loan.model.LoanApplicationStatus; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; + 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.cloud.contract.stubrunner.spring.AutoConfigureStubRunner; import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties; -import org.springframework.test.context.junit4.SpringRunner; + import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringRunner.class) + @SpringBootTest(webEnvironment = WebEnvironment.NONE, properties = "server.context-path=/app") @AutoConfigureStubRunner(ids = { "com.example:http-server-dsl:0.0.1:stubs:6565" }, stubsMode = StubRunnerProperties.StubsMode.LOCAL) diff --git a/samples/standalone/dsl/http-client/src/test/java/com/example/loan/LoanApplicationServiceTests.java b/samples/standalone/dsl/http-client/src/test/java/com/example/loan/LoanApplicationServiceTests.java index a9e543c987..08e43be336 100644 --- a/samples/standalone/dsl/http-client/src/test/java/com/example/loan/LoanApplicationServiceTests.java +++ b/samples/standalone/dsl/http-client/src/test/java/com/example/loan/LoanApplicationServiceTests.java @@ -30,9 +30,9 @@ import com.jayway.jsonpath.JsonPath; import io.restassured.RestAssured; import io.restassured.response.ResponseOptions; import io.restassured.specification.RequestSpecification; -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.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -42,14 +42,14 @@ import org.springframework.cloud.contract.stubrunner.spring.StubRunnerPort; import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties; import org.springframework.http.RequestEntity; import org.springframework.http.ResponseEntity; -import org.springframework.test.context.junit4.SpringRunner; + import org.springframework.web.client.RestTemplate; import static com.toomuchcoding.jsonassert.JsonAssertion.assertThatJson; import static org.assertj.core.api.Assertions.assertThat; // tag::autoconfigure_stubrunner[] -@RunWith(SpringRunner.class) + @SpringBootTest(webEnvironment = WebEnvironment.NONE) @AutoConfigureStubRunner(ids = { "com.example:http-server-dsl:0.0.1:stubs" }, stubsMode = StubRunnerProperties.StubsMode.LOCAL) @@ -63,7 +63,7 @@ public class LoanApplicationServiceTests { @Autowired private LoanApplicationService service; - @Before + @BeforeEach public void setup() { this.service.setPort(this.stubPort); } diff --git a/samples/standalone/dsl/http-client/src/test/java/com/example/loan/MessageConsumedTests.java b/samples/standalone/dsl/http-client/src/test/java/com/example/loan/MessageConsumedTests.java index 36d63c4245..4c9b6b45eb 100644 --- a/samples/standalone/dsl/http-client/src/test/java/com/example/loan/MessageConsumedTests.java +++ b/samples/standalone/dsl/http-client/src/test/java/com/example/loan/MessageConsumedTests.java @@ -16,9 +16,7 @@ package com.example.loan; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -26,17 +24,14 @@ import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.cloud.contract.stubrunner.StubTrigger; import org.springframework.cloud.contract.stubrunner.spring.AutoConfigureStubRunner; import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import static org.assertj.core.api.Assertions.assertThat; /** * @author Marius Bogoevici */ -@RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.NONE, properties = "spring.cloud.stream.bindings.input.destination=sensor-data") @AutoConfigureStubRunner(ids = "com.example:http-server-dsl:0.0.1", stubsMode = StubRunnerProperties.StubsMode.LOCAL) -@Ignore public class MessageConsumedTests { @Autowired diff --git a/samples/standalone/dsl/http-client/src/test/java/com/example/loan/TestControllerTests.java b/samples/standalone/dsl/http-client/src/test/java/com/example/loan/TestControllerTests.java index 9597ff941d..12e4efa8f9 100644 --- a/samples/standalone/dsl/http-client/src/test/java/com/example/loan/TestControllerTests.java +++ b/samples/standalone/dsl/http-client/src/test/java/com/example/loan/TestControllerTests.java @@ -16,8 +16,8 @@ package com.example.loan; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; + import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; @@ -25,13 +25,13 @@ import org.springframework.cloud.contract.stubrunner.spring.AutoConfigureStubRun import org.springframework.cloud.contract.stubrunner.spring.StubRunnerPort; import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties; import org.springframework.http.ResponseEntity; -import org.springframework.test.context.junit4.SpringRunner; + import org.springframework.web.client.RestTemplate; import static org.assertj.core.api.Assertions.assertThat; // tag::autoconfigure_stubrunner[] -@RunWith(SpringRunner.class) + @SpringBootTest(webEnvironment = WebEnvironment.NONE) @AutoConfigureStubRunner(ids = { "com.example:http-server-dsl:0.0.1:stubs:6565"}, stubsMode = StubRunnerProperties.StubsMode.LOCAL) diff --git a/samples/standalone/dsl/http-server/build.gradle b/samples/standalone/dsl/http-server/build.gradle index e71a92a5ff..e81eaf1341 100644 --- a/samples/standalone/dsl/http-server/build.gradle +++ b/samples/standalone/dsl/http-server/build.gradle @@ -76,9 +76,13 @@ dependencies { testImplementation 'org.springframework.cloud:spring-cloud-starter-contract-verifier' testImplementation(group: 'org.springframework.cloud', name: 'spring-cloud-stream', classifier: 'test-binder') + testImplementation('org.springframework.boot:spring-boot-starter-test') { + exclude(group: 'org.junit.vintage', module: 'junit-vintage-engine') + } } test { + useJUnitPlatform() systemProperty 'spring.profiles.active', 'gradle' testLogging { exceptionFormat = 'full' diff --git a/samples/standalone/dsl/http-server/pom.xml b/samples/standalone/dsl/http-server/pom.xml index 26720e4d96..2315ce742d 100644 --- a/samples/standalone/dsl/http-server/pom.xml +++ b/samples/standalone/dsl/http-server/pom.xml @@ -40,6 +40,12 @@ org.springframework.boot spring-boot-starter-test test + + + org.junit.vintage + junit-vintage-engine + + org.springframework.cloud diff --git a/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/BinaryBase.java b/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/BinaryBase.java index b3761166ca..bfcd40f7c4 100644 --- a/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/BinaryBase.java +++ b/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/BinaryBase.java @@ -17,11 +17,11 @@ package com.example.fraud; import io.restassured.module.mockmvc.RestAssuredMockMvc; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; public class BinaryBase { - @Before + @BeforeEach public void setUp() throws Exception { RestAssuredMockMvc.standaloneSetup(new TestController()); } diff --git a/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/FraudBase.java b/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/FraudBase.java index ccda8f79d9..3e462aa229 100644 --- a/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/FraudBase.java +++ b/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/FraudBase.java @@ -17,11 +17,11 @@ package com.example.fraud; import io.restassured.module.mockmvc.RestAssuredMockMvc; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; public class FraudBase { - @Before + @BeforeEach public void setup() { RestAssuredMockMvc.standaloneSetup(new FraudDetectionController(), new FraudStatsController(stubbedStatsProvider())); diff --git a/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/FraudnameBase.java b/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/FraudnameBase.java index b3ab7447d3..f38066f2bb 100644 --- a/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/FraudnameBase.java +++ b/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/FraudnameBase.java @@ -17,7 +17,7 @@ package com.example.fraud; import io.restassured.module.mockmvc.RestAssuredMockMvc; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; public class FraudnameBase { @@ -25,7 +25,7 @@ public class FraudnameBase { FraudVerifier fraudVerifier = FRAUD_NAME::equals; - @Before + @BeforeEach public void setup() { RestAssuredMockMvc.standaloneSetup(new FraudNameController(this.fraudVerifier)); } diff --git a/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/MessagingBase.java b/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/MessagingBase.java index 7f22bd035c..ec4cae996a 100644 --- a/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/MessagingBase.java +++ b/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/MessagingBase.java @@ -17,8 +17,8 @@ package com.example.fraud; import io.restassured.module.mockmvc.RestAssuredMockMvc; -import org.junit.Before; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; @@ -26,7 +26,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cloud.contract.verifier.messaging.boot.AutoConfigureMessageVerifier; import org.springframework.cloud.stream.binder.test.TestChannelBinderConfiguration; import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.junit4.SpringRunner; + import org.springframework.web.context.WebApplicationContext; /** @@ -36,7 +36,7 @@ import org.springframework.web.context.WebApplicationContext; * * @author Marius Bogoevici */ -@RunWith(SpringRunner.class) + @SpringBootTest(classes = {MessagingBase.Config.class, Application.class}) @AutoConfigureMessageVerifier public abstract class MessagingBase { @@ -47,7 +47,7 @@ public abstract class MessagingBase { @Autowired WebApplicationContext context; - @Before + @BeforeEach public void setup() { RestAssuredMockMvc.webAppContextSetup(this.context); } diff --git a/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/MultipartBase.java b/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/MultipartBase.java index 4282d8e9bc..fa82da0402 100644 --- a/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/MultipartBase.java +++ b/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/MultipartBase.java @@ -17,11 +17,11 @@ package com.example.fraud; import io.restassured.module.mockmvc.RestAssuredMockMvc; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; public class MultipartBase { - @Before + @BeforeEach public void setUp() throws Exception { RestAssuredMockMvc.standaloneSetup(new TestController()); } diff --git a/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/PactBase.java b/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/PactBase.java index 10eb767439..ba6b7f5408 100644 --- a/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/PactBase.java +++ b/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/PactBase.java @@ -17,11 +17,11 @@ package com.example.fraud; import io.restassured.module.mockmvc.RestAssuredMockMvc; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; public class PactBase { - @Before + @BeforeEach public void setup() { RestAssuredMockMvc.standaloneSetup(new FraudDetectionController(), new FraudStatsController(stubbedStatsProvider())); diff --git a/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/TestBase.java b/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/TestBase.java index e2685dd047..6a1c81d89e 100644 --- a/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/TestBase.java +++ b/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/TestBase.java @@ -17,11 +17,11 @@ package com.example.fraud; import io.restassured.module.mockmvc.RestAssuredMockMvc; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; public class TestBase { - @Before + @BeforeEach public void setUp() throws Exception { RestAssuredMockMvc.standaloneSetup(new TestController()); } diff --git a/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/YmlFraudBase.java b/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/YmlFraudBase.java index 2bd4f0e031..4e46c07838 100644 --- a/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/YmlFraudBase.java +++ b/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/YmlFraudBase.java @@ -17,11 +17,11 @@ package com.example.fraud; import io.restassured.module.mockmvc.RestAssuredMockMvc; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; public class YmlFraudBase { - @Before + @BeforeEach public void setup() { RestAssuredMockMvc.standaloneSetup(new FraudDetectionController(), new FraudStatsController(stubbedStatsProvider())); diff --git a/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/YmlFraudnameBase.java b/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/YmlFraudnameBase.java index 5399474db8..abe32e3f04 100644 --- a/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/YmlFraudnameBase.java +++ b/samples/standalone/dsl/http-server/src/test/java/com/example/fraud/YmlFraudnameBase.java @@ -17,7 +17,7 @@ package com.example.fraud; import io.restassured.module.mockmvc.RestAssuredMockMvc; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; public class YmlFraudnameBase { @@ -25,7 +25,7 @@ public class YmlFraudnameBase { FraudVerifier fraudVerifier = FRAUD_NAME::equals; - @Before + @BeforeEach public void setup() { RestAssuredMockMvc.standaloneSetup(new FraudNameController(this.fraudVerifier)); } diff --git a/samples/standalone/restdocs/http-client/build.gradle b/samples/standalone/restdocs/http-client/build.gradle index cc3326c8fc..e64f69d857 100644 --- a/samples/standalone/restdocs/http-client/build.gradle +++ b/samples/standalone/restdocs/http-client/build.gradle @@ -41,11 +41,14 @@ dependencies { testImplementation 'org.springframework.cloud:spring-cloud-contract-wiremock' testImplementation 'org.springframework.cloud:spring-cloud-starter-contract-stub-runner' - testImplementation "org.springframework.boot:spring-boot-starter-test" + testImplementation('org.springframework.boot:spring-boot-starter-test') { + exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' + } testImplementation "com.example:http-server-restdocs:0.0.1:stubs" } test { + useJUnitPlatform() systemProperty 'spring.profiles.active', 'gradle' testLogging { exceptionFormat = 'full' diff --git a/samples/standalone/restdocs/http-client/pom.xml b/samples/standalone/restdocs/http-client/pom.xml index 1f627138e6..ef5a1c35a9 100644 --- a/samples/standalone/restdocs/http-client/pom.xml +++ b/samples/standalone/restdocs/http-client/pom.xml @@ -60,6 +60,12 @@ org.springframework.boot spring-boot-starter-test test + + + org.junit.vintage + junit-vintage-engine + + org.springframework.cloud diff --git a/samples/standalone/restdocs/http-client/src/test/java/com/example/loan/LoanApplicationServiceTests.java b/samples/standalone/restdocs/http-client/src/test/java/com/example/loan/LoanApplicationServiceTests.java index f1b384a891..a8a6b2b6ca 100644 --- a/samples/standalone/restdocs/http-client/src/test/java/com/example/loan/LoanApplicationServiceTests.java +++ b/samples/standalone/restdocs/http-client/src/test/java/com/example/loan/LoanApplicationServiceTests.java @@ -24,20 +24,20 @@ import com.example.loan.model.LoanApplicationResult; import com.example.loan.model.LoanApplicationStatus; import com.github.tomakehurst.wiremock.WireMockServer; import com.github.tomakehurst.wiremock.stubbing.StubMapping; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock; import org.springframework.core.io.Resource; -import org.springframework.test.context.junit4.SpringRunner; + import org.springframework.util.StreamUtils; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringRunner.class) + @SpringBootTest(properties = "service.port=${wiremock.server.port}") @AutoConfigureWireMock(port = 0) public class LoanApplicationServiceTests { diff --git a/samples/standalone/restdocs/http-client/src/test/java/com/example/loan/LoanApplicationServiceusingStubRunnerTests.java b/samples/standalone/restdocs/http-client/src/test/java/com/example/loan/LoanApplicationServiceusingStubRunnerTests.java index e581ec8d0e..4a5a4b41f2 100644 --- a/samples/standalone/restdocs/http-client/src/test/java/com/example/loan/LoanApplicationServiceusingStubRunnerTests.java +++ b/samples/standalone/restdocs/http-client/src/test/java/com/example/loan/LoanApplicationServiceusingStubRunnerTests.java @@ -20,19 +20,19 @@ import com.example.loan.model.Client; import com.example.loan.model.LoanApplication; import com.example.loan.model.LoanApplicationResult; import com.example.loan.model.LoanApplicationStatus; -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.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cloud.contract.stubrunner.spring.AutoConfigureStubRunner; -import org.springframework.test.context.junit4.SpringRunner; + import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringRunner.class) + @SpringBootTest @AutoConfigureStubRunner(ids = "com.example:http-server-restdocs") public class LoanApplicationServiceusingStubRunnerTests { @@ -43,7 +43,7 @@ public class LoanApplicationServiceusingStubRunnerTests { @Value("${stubrunner.runningstubs.http-server-restdocs.port}") int port; - @Before + @BeforeEach public void setup() { this.service.setPort(this.port); } diff --git a/samples/standalone/restdocs/http-client/src/test/java/com/example/loan/XmlServiceTests.java b/samples/standalone/restdocs/http-client/src/test/java/com/example/loan/XmlServiceTests.java index fa3f550a8e..a8d3bb65a7 100644 --- a/samples/standalone/restdocs/http-client/src/test/java/com/example/loan/XmlServiceTests.java +++ b/samples/standalone/restdocs/http-client/src/test/java/com/example/loan/XmlServiceTests.java @@ -22,8 +22,8 @@ import java.nio.charset.Charset; import com.github.tomakehurst.wiremock.WireMockServer; import com.github.tomakehurst.wiremock.stubbing.StubMapping; import org.assertj.core.api.BDDAssertions; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -33,11 +33,11 @@ import org.springframework.core.io.Resource; import org.springframework.http.MediaType; import org.springframework.http.RequestEntity; import org.springframework.http.ResponseEntity; -import org.springframework.test.context.junit4.SpringRunner; + import org.springframework.util.StreamUtils; import org.springframework.web.client.RestTemplate; -@RunWith(SpringRunner.class) + @SpringBootTest(properties = "service.port=${wiremock.server.port}") @AutoConfigureWireMock(port = 0) public class XmlServiceTests { diff --git a/samples/standalone/restdocs/http-client/src/test/java/com/example/loan/XmlServiceUsingStubRunnerTests.java b/samples/standalone/restdocs/http-client/src/test/java/com/example/loan/XmlServiceUsingStubRunnerTests.java index 223d6fca25..035f43ac55 100644 --- a/samples/standalone/restdocs/http-client/src/test/java/com/example/loan/XmlServiceUsingStubRunnerTests.java +++ b/samples/standalone/restdocs/http-client/src/test/java/com/example/loan/XmlServiceUsingStubRunnerTests.java @@ -19,8 +19,8 @@ package com.example.loan; import java.net.URI; import org.assertj.core.api.BDDAssertions; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; + import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest; @@ -28,10 +28,10 @@ import org.springframework.cloud.contract.stubrunner.spring.AutoConfigureStubRun import org.springframework.http.MediaType; import org.springframework.http.RequestEntity; import org.springframework.http.ResponseEntity; -import org.springframework.test.context.junit4.SpringRunner; + import org.springframework.web.client.RestTemplate; -@RunWith(SpringRunner.class) + @SpringBootTest @AutoConfigureStubRunner(ids = "com.example:http-server-restdocs") public class XmlServiceUsingStubRunnerTests { diff --git a/samples/standalone/restdocs/http-server/build.gradle b/samples/standalone/restdocs/http-server/build.gradle index e5a6fb9966..302902f364 100644 --- a/samples/standalone/restdocs/http-server/build.gradle +++ b/samples/standalone/restdocs/http-server/build.gradle @@ -45,7 +45,7 @@ dependencies { implementation("org.springframework.boot:spring-boot-starter-actuator") implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-xml") - testImplementation 'org.springframework.boot:spring-boot-starter-test' + testImplementation('org.springframework.boot:spring-boot-starter-test') testImplementation 'org.springframework.cloud:spring-cloud-starter-contract-stub-runner' // tag::dependencies[] testImplementation 'org.springframework.cloud:spring-cloud-starter-contract-verifier' @@ -73,6 +73,7 @@ contracts { baseClassMapping('.*standalone.*', 'com.example.fraud.FraudBaseWithStandaloneSetup') baseClassMapping('.*webapp.*', 'com.example.fraud.FraudBaseWithWebAppSetup') } + testFramework("JUNIT") } generateClientStubs.enabled = false diff --git a/samples/standalone/restdocs/http-server/pom.xml b/samples/standalone/restdocs/http-server/pom.xml index 02d0be46d7..c488f22484 100644 --- a/samples/standalone/restdocs/http-server/pom.xml +++ b/samples/standalone/restdocs/http-server/pom.xml @@ -148,6 +148,7 @@ + JUNIT diff --git a/samples/standalone/restdocs/http-server/src/test/java/com/example/fraud/FraudBaseWithWebAppSetup.java b/samples/standalone/restdocs/http-server/src/test/java/com/example/fraud/FraudBaseWithWebAppSetup.java index 40452325a0..cb979407c5 100644 --- a/samples/standalone/restdocs/http-server/src/test/java/com/example/fraud/FraudBaseWithWebAppSetup.java +++ b/samples/standalone/restdocs/http-server/src/test/java/com/example/fraud/FraudBaseWithWebAppSetup.java @@ -7,6 +7,7 @@ import org.junit.Rule; import org.junit.rules.TestName; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.restdocs.JUnitRestDocumentation; diff --git a/samples/standalone/restdocs/http-server/src/test/java/com/example/fraud/StubGeneratorTests.java b/samples/standalone/restdocs/http-server/src/test/java/com/example/fraud/StubGeneratorTests.java index af766c41f4..dae991e190 100644 --- a/samples/standalone/restdocs/http-server/src/test/java/com/example/fraud/StubGeneratorTests.java +++ b/samples/standalone/restdocs/http-server/src/test/java/com/example/fraud/StubGeneratorTests.java @@ -24,6 +24,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.json.AutoConfigureJsonTesters; import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs; @@ -31,6 +32,7 @@ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMock import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.json.JacksonTester; import org.springframework.http.MediaType; + import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; diff --git a/samples/standalone/restdocs/http-server/src/test/java/com/example/fraud/XmlStubGeneratorTests.java b/samples/standalone/restdocs/http-server/src/test/java/com/example/fraud/XmlStubGeneratorTests.java index fa622a725e..9085a8feb8 100644 --- a/samples/standalone/restdocs/http-server/src/test/java/com/example/fraud/XmlStubGeneratorTests.java +++ b/samples/standalone/restdocs/http-server/src/test/java/com/example/fraud/XmlStubGeneratorTests.java @@ -16,6 +16,7 @@ package com.example.fraud; + import org.junit.Test; import org.junit.runner.RunWith; @@ -25,6 +26,7 @@ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMock import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.MediaType; import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; + import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; diff --git a/samples/standalone/webclient/http-client/build.gradle b/samples/standalone/webclient/http-client/build.gradle index af27bb35a6..7599fceac6 100644 --- a/samples/standalone/webclient/http-client/build.gradle +++ b/samples/standalone/webclient/http-client/build.gradle @@ -40,11 +40,14 @@ dependencies { testImplementation 'org.springframework.cloud:spring-cloud-contract-wiremock' testImplementation 'org.springframework.cloud:spring-cloud-starter-contract-stub-runner' - testImplementation "org.springframework.boot:spring-boot-starter-test" + testImplementation('org.springframework.boot:spring-boot-starter-test') { + exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' + } testImplementation "com.example:http-server-webclient:0.0.1:stubs" } test { + useJUnitPlatform() include '**/*GradleTests*' systemProperty 'spring.profiles.active', 'gradle' testLogging { diff --git a/samples/standalone/webclient/http-client/pom.xml b/samples/standalone/webclient/http-client/pom.xml index cf4696a86b..abe117bfc1 100644 --- a/samples/standalone/webclient/http-client/pom.xml +++ b/samples/standalone/webclient/http-client/pom.xml @@ -39,6 +39,12 @@ org.springframework.boot spring-boot-starter-test test + + + org.junit.vintage + junit-vintage-engine + + org.springframework.cloud diff --git a/samples/standalone/webclient/http-client/src/test/java/com/example/loan/LoanApplicationServiceTests.java b/samples/standalone/webclient/http-client/src/test/java/com/example/loan/LoanApplicationServiceTests.java index 098f21c577..ebd91253ad 100644 --- a/samples/standalone/webclient/http-client/src/test/java/com/example/loan/LoanApplicationServiceTests.java +++ b/samples/standalone/webclient/http-client/src/test/java/com/example/loan/LoanApplicationServiceTests.java @@ -24,20 +24,20 @@ import com.example.loan.model.LoanApplicationResult; import com.example.loan.model.LoanApplicationStatus; import com.github.tomakehurst.wiremock.WireMockServer; import com.github.tomakehurst.wiremock.stubbing.StubMapping; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock; import org.springframework.core.io.Resource; -import org.springframework.test.context.junit4.SpringRunner; + import org.springframework.util.StreamUtils; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringRunner.class) + @SpringBootTest(properties = "service.port=${wiremock.server.port}") @AutoConfigureWireMock(port = 0) public class LoanApplicationServiceTests { diff --git a/samples/standalone/webclient/http-client/src/test/java/com/example/loan/LoanApplicationServiceusingStubRunnerGradleTests.java b/samples/standalone/webclient/http-client/src/test/java/com/example/loan/LoanApplicationServiceusingStubRunnerGradleTests.java index 85c0746986..e75bbbae92 100644 --- a/samples/standalone/webclient/http-client/src/test/java/com/example/loan/LoanApplicationServiceusingStubRunnerGradleTests.java +++ b/samples/standalone/webclient/http-client/src/test/java/com/example/loan/LoanApplicationServiceusingStubRunnerGradleTests.java @@ -20,19 +20,19 @@ import com.example.loan.model.Client; import com.example.loan.model.LoanApplication; import com.example.loan.model.LoanApplicationResult; import com.example.loan.model.LoanApplicationStatus; -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.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cloud.contract.stubrunner.spring.AutoConfigureStubRunner; -import org.springframework.test.context.junit4.SpringRunner; + import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringRunner.class) + @SpringBootTest @AutoConfigureStubRunner(ids = "com.example:http-server-webclient") public class LoanApplicationServiceusingStubRunnerGradleTests { @@ -43,7 +43,7 @@ public class LoanApplicationServiceusingStubRunnerGradleTests { @Value("${stubrunner.runningstubs.http-server-webclient.port}") int port; - @Before + @BeforeEach public void setup() { this.service.setPort(this.port); } diff --git a/samples/standalone/webclient/http-client/src/test/java/com/example/loan/LoanApplicationServiceusingStubRunnerTests.java b/samples/standalone/webclient/http-client/src/test/java/com/example/loan/LoanApplicationServiceusingStubRunnerTests.java index 35377dd390..e1c1c13ec7 100644 --- a/samples/standalone/webclient/http-client/src/test/java/com/example/loan/LoanApplicationServiceusingStubRunnerTests.java +++ b/samples/standalone/webclient/http-client/src/test/java/com/example/loan/LoanApplicationServiceusingStubRunnerTests.java @@ -20,19 +20,19 @@ import com.example.loan.model.Client; import com.example.loan.model.LoanApplication; import com.example.loan.model.LoanApplicationResult; import com.example.loan.model.LoanApplicationStatus; -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.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cloud.contract.stubrunner.spring.AutoConfigureStubRunner; -import org.springframework.test.context.junit4.SpringRunner; + import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringRunner.class) + @SpringBootTest @AutoConfigureStubRunner(ids = "com.example:http-server-webclient") public class LoanApplicationServiceusingStubRunnerTests { @@ -43,7 +43,7 @@ public class LoanApplicationServiceusingStubRunnerTests { @Value("${stubrunner.runningstubs.http-server-webclient.port}") int port; - @Before + @BeforeEach public void setup() { this.service.setPort(this.port); } diff --git a/samples/standalone/webclient/http-server/build.gradle b/samples/standalone/webclient/http-server/build.gradle index 00198b17d5..639363f42e 100644 --- a/samples/standalone/webclient/http-server/build.gradle +++ b/samples/standalone/webclient/http-server/build.gradle @@ -29,7 +29,9 @@ dependencies { implementation("org.springframework.boot:spring-boot-starter-webflux") implementation("org.springframework.boot:spring-boot-starter-actuator") - testImplementation 'org.springframework.boot:spring-boot-starter-test' + testImplementation('org.springframework.boot:spring-boot-starter-test') { + exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' + } testImplementation 'org.springframework.restdocs:spring-restdocs-webtestclient' testImplementation 'org.springframework.cloud:spring-cloud-contract-wiremock' } @@ -39,6 +41,7 @@ contracts { } test { + useJUnitPlatform() systemProperty 'spring.profiles.active', 'gradle' testLogging { exceptionFormat = 'full' diff --git a/samples/standalone/webclient/http-server/pom.xml b/samples/standalone/webclient/http-server/pom.xml index 0c2e40237b..64433ece5d 100644 --- a/samples/standalone/webclient/http-server/pom.xml +++ b/samples/standalone/webclient/http-server/pom.xml @@ -38,6 +38,12 @@ org.springframework.boot spring-boot-starter-test test + + + org.junit.vintage + junit-vintage-engine + + diff --git a/samples/standalone/webclient/http-server/src/test/java/com/example/fraud/StubGeneratorTests.java b/samples/standalone/webclient/http-server/src/test/java/com/example/fraud/StubGeneratorTests.java index 9305c1aeb1..4d63f0b756 100644 --- a/samples/standalone/webclient/http-server/src/test/java/com/example/fraud/StubGeneratorTests.java +++ b/samples/standalone/webclient/http-server/src/test/java/com/example/fraud/StubGeneratorTests.java @@ -20,9 +20,9 @@ import java.math.BigDecimal; import com.example.fraud.model.FraudCheck; import com.fasterxml.jackson.databind.ObjectMapper; -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.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.json.AutoConfigureJsonTesters; @@ -32,13 +32,13 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.json.JacksonTester; import org.springframework.http.MediaType; import org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation; -import org.springframework.test.context.junit4.SpringRunner; + import org.springframework.test.web.reactive.server.WebTestClient; import org.springframework.web.reactive.function.BodyInserters; import static org.springframework.cloud.contract.wiremock.restdocs.WireMockWebTestClient.verify; -@RunWith(SpringRunner.class) + @SpringBootTest(classes = Application.class) @AutoConfigureRestDocs(outputDir = "target/snippets") @AutoConfigureWebTestClient @@ -50,7 +50,7 @@ public class StubGeneratorTests { private JacksonTester json; - @Before + @BeforeEach public void setup() { ObjectMapper objectMappper = new ObjectMapper(); // Possibly configure the mapper diff --git a/samples/wiremock-jetty/pom.xml b/samples/wiremock-jetty/pom.xml index 24f67d3822..30533c0000 100644 --- a/samples/wiremock-jetty/pom.xml +++ b/samples/wiremock-jetty/pom.xml @@ -53,6 +53,12 @@ org.springframework.boot spring-boot-starter-test test + + + org.junit.vintage + junit-vintage-engine + + diff --git a/samples/wiremock-jetty/src/test/java/com/example/WiremockForDocsClassRuleTests.java b/samples/wiremock-jetty/src/test/java/com/example/WiremockForDocsClassRuleTests.java index ec02b421c8..5423d43346 100644 --- a/samples/wiremock-jetty/src/test/java/com/example/WiremockForDocsClassRuleTests.java +++ b/samples/wiremock-jetty/src/test/java/com/example/WiremockForDocsClassRuleTests.java @@ -16,18 +16,18 @@ package com.example; -import com.github.tomakehurst.wiremock.junit.WireMockClassRule; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import com.github.tomakehurst.wiremock.WireMockServer; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; 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.cloud.contract.wiremock.WireMockSpring; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.get; @@ -36,15 +36,28 @@ import static org.assertj.core.api.Assertions.assertThat; @ActiveProfiles("classrule") // tag::wiremock_test1[] -@RunWith(SpringRunner.class) + @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) public class WiremockForDocsClassRuleTests { // Start WireMock on some dynamic port // for some reason `dynamicPort()` is not working properly - @ClassRule - public static WireMockClassRule wiremock = new WireMockClassRule( - WireMockSpring.options().dynamicPort()); + public static WireMockServer wiremock = new WireMockServer(WireMockSpring.options().dynamicPort()); + + @BeforeAll + static void setupClass() { + wiremock.start(); + } + + @AfterEach + void after() { + wiremock.resetAll(); + } + + @AfterAll + static void clean() { + wiremock.shutdown(); + } // A service that calls out over HTTP to wiremock's port @Autowired @@ -52,7 +65,7 @@ public class WiremockForDocsClassRuleTests { // end::wiremock_test1[] // tag::wiremock_test2[] - @Before + @BeforeEach public void setup() { this.service.setBase("http://localhost:" + wiremock.port()); } diff --git a/samples/wiremock-jetty/src/test/java/com/example/WiremockForDocsMockServerApplicationTests.java b/samples/wiremock-jetty/src/test/java/com/example/WiremockForDocsMockServerApplicationTests.java index f4edf615ff..ef1aac2ff3 100644 --- a/samples/wiremock-jetty/src/test/java/com/example/WiremockForDocsMockServerApplicationTests.java +++ b/samples/wiremock-jetty/src/test/java/com/example/WiremockForDocsMockServerApplicationTests.java @@ -16,21 +16,21 @@ package com.example; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; + 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.cloud.contract.wiremock.WireMockRestServiceServer; -import org.springframework.test.context.junit4.SpringRunner; + import org.springframework.test.web.client.MockRestServiceServer; import org.springframework.web.client.RestTemplate; import static org.assertj.core.api.Assertions.assertThat; // tag::wiremock_test[] -@RunWith(SpringRunner.class) + @SpringBootTest(webEnvironment = WebEnvironment.NONE) public class WiremockForDocsMockServerApplicationTests { diff --git a/samples/wiremock-jetty/src/test/java/com/example/WiremockForDocsTests.java b/samples/wiremock-jetty/src/test/java/com/example/WiremockForDocsTests.java index 2c23e9a894..c8b9a72d18 100644 --- a/samples/wiremock-jetty/src/test/java/com/example/WiremockForDocsTests.java +++ b/samples/wiremock-jetty/src/test/java/com/example/WiremockForDocsTests.java @@ -16,9 +16,9 @@ package com.example; -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.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -26,7 +26,7 @@ import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock; import org.springframework.core.env.Environment; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; + import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.get; @@ -36,7 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat; @ActiveProfiles("docs") // tag::wiremock_test1[] -@RunWith(SpringRunner.class) + @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) @AutoConfigureWireMock(port = 0) public class WiremockForDocsTests { @@ -51,7 +51,7 @@ public class WiremockForDocsTests { @Autowired private Service service; - @Before + @BeforeEach public void setup() { this.service.setBase("http://localhost:" + this.environment.getProperty("wiremock.server.port")); diff --git a/samples/wiremock-jetty/src/test/java/com/example/WiremockHttpsServerApplicationTests.java b/samples/wiremock-jetty/src/test/java/com/example/WiremockHttpsServerApplicationTests.java index 0dd7825240..a797ddd9ae 100644 --- a/samples/wiremock-jetty/src/test/java/com/example/WiremockHttpsServerApplicationTests.java +++ b/samples/wiremock-jetty/src/test/java/com/example/WiremockHttpsServerApplicationTests.java @@ -16,16 +16,16 @@ package com.example; -import com.github.tomakehurst.wiremock.junit.WireMockClassRule; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import com.github.tomakehurst.wiremock.WireMockServer; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cloud.contract.wiremock.AutoConfigureHttpClient; import org.springframework.cloud.contract.wiremock.WireMockSpring; -import org.springframework.test.context.junit4.SpringRunner; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.get; @@ -33,21 +33,34 @@ import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringRunner.class) + @SpringBootTest("app.baseUrl=https://localhost:10443") @AutoConfigureHttpClient public class WiremockHttpsServerApplicationTests { - @ClassRule - public static WireMockClassRule wiremock = new WireMockClassRule( - WireMockSpring.options().httpsPort(10443)); + public static WireMockServer wiremock = new WireMockServer(WireMockSpring.options().httpsPort(10443)); + + @BeforeAll + static void setupClass() { + wiremock.start(); + } + + @AfterEach + void after() { + wiremock.resetAll(); + } + + @AfterAll + static void clean() { + wiremock.shutdown(); + } @Autowired private Service service; @Test public void contextLoads() throws Exception { - stubFor(get(urlEqualTo("/resource")).willReturn(aResponse() + wiremock.stubFor(get(urlEqualTo("/resource")).willReturn(aResponse() .withHeader("Content-Type", "text/plain").withBody("Hello World!"))); assertThat(this.service.go()).isEqualTo("Hello World!"); } diff --git a/samples/wiremock-jetty/src/test/java/com/example/WiremockImportApplicationTests.java b/samples/wiremock-jetty/src/test/java/com/example/WiremockImportApplicationTests.java index 3d8be3494b..cc3374735a 100644 --- a/samples/wiremock-jetty/src/test/java/com/example/WiremockImportApplicationTests.java +++ b/samples/wiremock-jetty/src/test/java/com/example/WiremockImportApplicationTests.java @@ -16,14 +16,14 @@ package com.example; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; + 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.cloud.contract.wiremock.AutoConfigureWireMock; -import org.springframework.test.context.junit4.SpringRunner; + import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.get; @@ -31,7 +31,7 @@ import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringRunner.class) + @SpringBootTest(properties = "app.baseUrl=http://localhost:6060", webEnvironment = WebEnvironment.NONE) @AutoConfigureWireMock(port = 6060) public class WiremockImportApplicationTests { diff --git a/samples/wiremock-jetty/src/test/java/com/example/WiremockMockServerApplicationTests.java b/samples/wiremock-jetty/src/test/java/com/example/WiremockMockServerApplicationTests.java index cd4fd14ee6..dbc177f550 100644 --- a/samples/wiremock-jetty/src/test/java/com/example/WiremockMockServerApplicationTests.java +++ b/samples/wiremock-jetty/src/test/java/com/example/WiremockMockServerApplicationTests.java @@ -16,20 +16,20 @@ package com.example; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; + 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.cloud.contract.wiremock.WireMockRestServiceServer; -import org.springframework.test.context.junit4.SpringRunner; + import org.springframework.test.web.client.MockRestServiceServer; import org.springframework.web.client.RestTemplate; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringRunner.class) + @SpringBootTest(webEnvironment = WebEnvironment.NONE) public class WiremockMockServerApplicationTests { diff --git a/samples/wiremock-jetty/src/test/java/com/example/WiremockServerApplicationTests.java b/samples/wiremock-jetty/src/test/java/com/example/WiremockServerApplicationTests.java index a34269c650..50cc830765 100644 --- a/samples/wiremock-jetty/src/test/java/com/example/WiremockServerApplicationTests.java +++ b/samples/wiremock-jetty/src/test/java/com/example/WiremockServerApplicationTests.java @@ -16,72 +16,80 @@ package com.example; +import com.github.tomakehurst.wiremock.WireMockServer; import com.github.tomakehurst.wiremock.http.Fault; -import com.github.tomakehurst.wiremock.junit.WireMockClassRule; import org.apache.http.NoHttpResponseException; import org.apache.http.client.ClientProtocolException; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; 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.cloud.contract.wiremock.WireMockSpring; -import org.springframework.test.context.junit4.SpringRunner; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static org.assertj.core.api.Assertions.assertThat; -import static org.hamcrest.CoreMatchers.instanceOf; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + -@RunWith(SpringRunner.class) @SpringBootTest(properties = "app.baseUrl=http://localhost:6061", webEnvironment = WebEnvironment.NONE) public class WiremockServerApplicationTests { - @ClassRule - public static WireMockClassRule wiremock = new WireMockClassRule( + public static WireMockServer wiremock = new WireMockServer( WireMockSpring.options().port(6061)); - @Rule - public ExpectedException expected = ExpectedException.none(); + @BeforeAll + static void setup() { + wiremock.start(); + } + + @AfterEach + void after() { + wiremock.resetAll(); + } + + @AfterAll + static void clean() { + wiremock.shutdown(); + } @Autowired private Service service; @Test public void hello() throws Exception { - stubFor(get(urlEqualTo("/resource")).willReturn(aResponse() + wiremock.stubFor(get(urlEqualTo("/resource")).willReturn(aResponse() .withHeader("Content-Type", "text/plain").withBody("Hello World!"))); assertThat(this.service.go()).isEqualTo("Hello World!"); } @Test public void randomData() throws Exception { - stubFor(get(urlEqualTo("/resource")) + wiremock.stubFor(get(urlEqualTo("/resource")) .willReturn(aResponse().withFault(Fault.RANDOM_DATA_THEN_CLOSE))); - this.expected.expectCause(instanceOf(ClientProtocolException.class)); - assertThat(this.service.go()).isEqualTo("Oops!"); + + assertThatThrownBy(() -> this.service.go()).hasCauseInstanceOf(ClientProtocolException.class); } @Test public void emptyResponse() throws Exception { - stubFor(get(urlEqualTo("/resource")) + wiremock.stubFor(get(urlEqualTo("/resource")) .willReturn(aResponse().withFault(Fault.EMPTY_RESPONSE))); - this.expected.expectCause(instanceOf(NoHttpResponseException.class)); - assertThat(this.service.go()).isEqualTo("Oops!"); + + assertThatThrownBy(() -> this.service.go()).hasCauseInstanceOf(NoHttpResponseException.class); } @Test public void malformed() throws Exception { - stubFor(get(urlEqualTo("/resource")) + wiremock.stubFor(get(urlEqualTo("/resource")) .willReturn(aResponse().withFault(Fault.MALFORMED_RESPONSE_CHUNK))); - this.expected.expectCause(instanceOf(ClientProtocolException.class)); - assertThat(this.service.go()).isEqualTo("Oops!"); + + assertThatThrownBy(() -> this.service.go()).hasCauseInstanceOf(ClientProtocolException.class); } } diff --git a/samples/wiremock-native/pom.xml b/samples/wiremock-native/pom.xml index 4ca14f5231..9e66fb47fa 100644 --- a/samples/wiremock-native/pom.xml +++ b/samples/wiremock-native/pom.xml @@ -57,6 +57,12 @@ org.springframework.boot spring-boot-starter-test test + + + org.junit.vintage + junit-vintage-engine + + diff --git a/samples/wiremock-native/src/test/java/com/example/WiremockServerApplicationTests.java b/samples/wiremock-native/src/test/java/com/example/WiremockServerApplicationTests.java index 01ec50a9fe..222eae6a2b 100644 --- a/samples/wiremock-native/src/test/java/com/example/WiremockServerApplicationTests.java +++ b/samples/wiremock-native/src/test/java/com/example/WiremockServerApplicationTests.java @@ -16,35 +16,48 @@ package com.example; -import com.github.tomakehurst.wiremock.junit.WireMockClassRule; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import com.github.tomakehurst.wiremock.WireMockServer; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; 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.test.context.junit4.SpringRunner; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringRunner.class) + @SpringBootTest(properties = "app.baseUrl=http://localhost:6063", webEnvironment = WebEnvironment.NONE) public class WiremockServerApplicationTests { - @ClassRule - public static WireMockClassRule wiremock = new WireMockClassRule(6063); + public static WireMockServer wiremock = new WireMockServer(6063); + + @BeforeAll + static void setup() { + wiremock.start(); + } + + @AfterEach + void after() { + wiremock.resetAll(); + } + + @AfterAll + static void clean() { + wiremock.shutdown(); + } @Autowired private Service service; @Test public void contextLoads() throws Exception { - stubFor(get(urlEqualTo("/resource")).willReturn(aResponse() + wiremock.stubFor(get(urlEqualTo("/resource")).willReturn(aResponse() .withHeader("Content-Type", "text/plain").withBody("Hello World!"))); assertThat(this.service.go()).isEqualTo("Hello World!"); } diff --git a/samples/wiremock-tomcat/pom.xml b/samples/wiremock-tomcat/pom.xml index c6d927ba59..5fe916ec00 100644 --- a/samples/wiremock-tomcat/pom.xml +++ b/samples/wiremock-tomcat/pom.xml @@ -43,6 +43,12 @@ org.springframework.boot spring-boot-starter-test test + + + org.junit.vintage + junit-vintage-engine + + diff --git a/samples/wiremock-tomcat/src/test/java/com/example/WiremockHttpsServerApplicationTests.java b/samples/wiremock-tomcat/src/test/java/com/example/WiremockHttpsServerApplicationTests.java index 5b1bbbc5f8..a216b52274 100644 --- a/samples/wiremock-tomcat/src/test/java/com/example/WiremockHttpsServerApplicationTests.java +++ b/samples/wiremock-tomcat/src/test/java/com/example/WiremockHttpsServerApplicationTests.java @@ -16,16 +16,16 @@ package com.example; -import com.github.tomakehurst.wiremock.junit.WireMockClassRule; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import com.github.tomakehurst.wiremock.WireMockServer; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cloud.contract.wiremock.AutoConfigureHttpClient; import org.springframework.cloud.contract.wiremock.WireMockSpring; -import org.springframework.test.context.junit4.SpringRunner; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.get; @@ -33,21 +33,35 @@ import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringRunner.class) + @SpringBootTest("app.baseUrl=https://localhost:6443") @AutoConfigureHttpClient public class WiremockHttpsServerApplicationTests { - @ClassRule - public static WireMockClassRule wiremock = new WireMockClassRule( + public static WireMockServer wiremock = new WireMockServer( WireMockSpring.options().httpsPort(6443)); + @BeforeAll + static void setup() { + wiremock.start(); + } + + @AfterEach + void after() { + wiremock.resetAll(); + } + + @AfterAll + static void clean() { + wiremock.shutdown(); + } + @Autowired private Service service; @Test public void contextLoads() throws Exception { - stubFor(get(urlEqualTo("/resource")).willReturn(aResponse() + wiremock.stubFor(get(urlEqualTo("/resource")).willReturn(aResponse() .withHeader("Content-Type", "text/plain").withBody("Hello World!"))); assertThat(this.service.go()).isEqualTo("Hello World!"); } diff --git a/samples/wiremock-tomcat/src/test/java/com/example/WiremockImportApplicationTests.java b/samples/wiremock-tomcat/src/test/java/com/example/WiremockImportApplicationTests.java index fceba90b71..4e12f42530 100644 --- a/samples/wiremock-tomcat/src/test/java/com/example/WiremockImportApplicationTests.java +++ b/samples/wiremock-tomcat/src/test/java/com/example/WiremockImportApplicationTests.java @@ -16,14 +16,14 @@ package com.example; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; + 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.cloud.contract.wiremock.AutoConfigureWireMock; -import org.springframework.test.context.junit4.SpringRunner; + import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.get; @@ -31,7 +31,7 @@ import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringRunner.class) + @SpringBootTest(properties = "app.baseUrl=http://localhost:6065", webEnvironment = WebEnvironment.NONE) @AutoConfigureWireMock(port = 6065) public class WiremockImportApplicationTests { diff --git a/samples/wiremock-tomcat/src/test/java/com/example/WiremockImportContextPathApplicationTests.java b/samples/wiremock-tomcat/src/test/java/com/example/WiremockImportContextPathApplicationTests.java index aa6304459e..3efd433afe 100644 --- a/samples/wiremock-tomcat/src/test/java/com/example/WiremockImportContextPathApplicationTests.java +++ b/samples/wiremock-tomcat/src/test/java/com/example/WiremockImportContextPathApplicationTests.java @@ -16,14 +16,14 @@ package com.example; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; + 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.cloud.contract.wiremock.AutoConfigureWireMock; -import org.springframework.test.context.junit4.SpringRunner; + import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.get; @@ -31,7 +31,7 @@ import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringRunner.class) + @SpringBootTest(properties = { "app.baseUrl=http://localhost:6066", "server.context-path=/app" }, webEnvironment = WebEnvironment.NONE) @AutoConfigureWireMock(port = 6066) diff --git a/samples/wiremock-tomcat/src/test/java/com/example/WiremockMockServerApplicationTests.java b/samples/wiremock-tomcat/src/test/java/com/example/WiremockMockServerApplicationTests.java index cf88a68b07..e5e27f1af4 100644 --- a/samples/wiremock-tomcat/src/test/java/com/example/WiremockMockServerApplicationTests.java +++ b/samples/wiremock-tomcat/src/test/java/com/example/WiremockMockServerApplicationTests.java @@ -16,20 +16,20 @@ package com.example; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; + 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.cloud.contract.wiremock.WireMockRestServiceServer; -import org.springframework.test.context.junit4.SpringRunner; + import org.springframework.test.web.client.MockRestServiceServer; import org.springframework.web.client.RestTemplate; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringRunner.class) + @SpringBootTest(webEnvironment = WebEnvironment.NONE) public class WiremockMockServerApplicationTests { diff --git a/samples/wiremock-tomcat/src/test/java/com/example/WiremockServerApplicationTests.java b/samples/wiremock-tomcat/src/test/java/com/example/WiremockServerApplicationTests.java index 7048e583bb..d4a8dcc5f6 100644 --- a/samples/wiremock-tomcat/src/test/java/com/example/WiremockServerApplicationTests.java +++ b/samples/wiremock-tomcat/src/test/java/com/example/WiremockServerApplicationTests.java @@ -18,73 +18,81 @@ package com.example; import java.io.IOException; +import com.github.tomakehurst.wiremock.WireMockServer; import com.github.tomakehurst.wiremock.http.Fault; -import com.github.tomakehurst.wiremock.junit.WireMockClassRule; import org.apache.http.NoHttpResponseException; import org.apache.http.client.ClientProtocolException; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; 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.cloud.contract.wiremock.WireMockSpring; -import org.springframework.test.context.junit4.SpringRunner; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static org.assertj.core.api.Assertions.assertThat; -import static org.hamcrest.CoreMatchers.instanceOf; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + -@RunWith(SpringRunner.class) @SpringBootTest(properties = "app.baseUrl=http://localhost:6067", webEnvironment = WebEnvironment.NONE) public class WiremockServerApplicationTests { - @ClassRule - public static WireMockClassRule wiremock = new WireMockClassRule( + public static WireMockServer wiremock = new WireMockServer( WireMockSpring.options().port(6067)); - @Rule - public ExpectedException expected = ExpectedException.none(); + @BeforeAll + static void setup() { + wiremock.start(); + } + + @AfterEach + void after() { + wiremock.resetAll(); + } + + @AfterAll + static void clean() { + wiremock.shutdown(); + } @Autowired private Service service; @Test public void contextLoads() throws Exception { - stubFor(get(urlEqualTo("/resource")).willReturn(aResponse() + wiremock.stubFor(get(urlEqualTo("/resource")).willReturn(aResponse() .withHeader("Content-Type", "text/plain").withBody("Hello World!"))); assertThat(this.service.go()).isEqualTo("Hello World!"); } @Test public void randomData() throws Exception { - stubFor(get(urlEqualTo("/resource")) + wiremock.stubFor(get(urlEqualTo("/resource")) .willReturn(aResponse().withFault(Fault.RANDOM_DATA_THEN_CLOSE))); - this.expected.expectCause(instanceOf(ClientProtocolException.class)); - assertThat(this.service.go()).isEqualTo("Oops!"); + + assertThatThrownBy(() -> this.service.go()).hasCauseInstanceOf(ClientProtocolException.class); } @Test public void emptyResponse() throws Exception { - stubFor(get(urlEqualTo("/resource")) + wiremock.stubFor(get(urlEqualTo("/resource")) .willReturn(aResponse().withFault(Fault.EMPTY_RESPONSE))); - this.expected.expectCause(instanceOf(NoHttpResponseException.class)); - assertThat(this.service.go()).isEqualTo("Oops!"); + + assertThatThrownBy(() -> this.service.go()).hasCauseInstanceOf(NoHttpResponseException.class); } @Test public void malformed() throws Exception { - stubFor(get(urlEqualTo("/resource")) + wiremock.stubFor(get(urlEqualTo("/resource")) .willReturn(aResponse().withFault(Fault.MALFORMED_RESPONSE_CHUNK))); // It's a different exception type than Jetty, but it's in the right ballpark - this.expected.expectCause(instanceOf(IOException.class)); - assertThat(this.service.go()).isEqualTo("Oops!"); + + assertThatThrownBy(() -> this.service.go()).hasCauseInstanceOf(IOException.class); } } diff --git a/samples/wiremock-undertow-ssl/pom.xml b/samples/wiremock-undertow-ssl/pom.xml index 6304841faf..1bb46b9c54 100644 --- a/samples/wiremock-undertow-ssl/pom.xml +++ b/samples/wiremock-undertow-ssl/pom.xml @@ -53,6 +53,12 @@ org.springframework.boot spring-boot-starter-test test + + + org.junit.vintage + junit-vintage-engine + + diff --git a/samples/wiremock-undertow-ssl/src/test/java/com/example/WiremockHttpsServerApplicationTests.java b/samples/wiremock-undertow-ssl/src/test/java/com/example/WiremockHttpsServerApplicationTests.java index d3c8bc0545..658462eece 100644 --- a/samples/wiremock-undertow-ssl/src/test/java/com/example/WiremockHttpsServerApplicationTests.java +++ b/samples/wiremock-undertow-ssl/src/test/java/com/example/WiremockHttpsServerApplicationTests.java @@ -16,39 +16,52 @@ package com.example; -import com.github.tomakehurst.wiremock.junit.WireMockClassRule; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import com.github.tomakehurst.wiremock.WireMockServer; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cloud.contract.wiremock.WireMockSpring; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.SocketUtils; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringRunner.class) + @SpringBootTest("app.baseUrl=https://localhost:7443") @ActiveProfiles("ssl") public class WiremockHttpsServerApplicationTests { - @ClassRule - public static WireMockClassRule wiremock = new WireMockClassRule(WireMockSpring + public static WireMockServer wiremock = new WireMockServer(WireMockSpring .options().httpsPort(7443).port(SocketUtils.findAvailableTcpPort())); + @BeforeAll + static void setup() { + wiremock.start(); + } + + @AfterEach + void after() { + wiremock.resetAll(); + } + + @AfterAll + static void clean() { + wiremock.shutdown(); + } + @Autowired private Service service; @Test public void contextLoads() throws Exception { - stubFor(get(urlEqualTo("/resource")).willReturn(aResponse() + wiremock.stubFor(get(urlEqualTo("/resource")).willReturn(aResponse() .withHeader("Content-Type", "text/plain").withBody("Hello World!"))); assertThat(this.service.go()).isEqualTo("Hello World!"); } diff --git a/samples/wiremock-undertow/pom.xml b/samples/wiremock-undertow/pom.xml index 46eed1fee9..5e71130a57 100644 --- a/samples/wiremock-undertow/pom.xml +++ b/samples/wiremock-undertow/pom.xml @@ -53,6 +53,12 @@ org.springframework.boot spring-boot-starter-test test + + + org.junit.vintage + junit-vintage-engine + + diff --git a/samples/wiremock-undertow/src/test/java/com/example/WiremockImportApplicationTests.java b/samples/wiremock-undertow/src/test/java/com/example/WiremockImportApplicationTests.java index d26074f234..6ff12e7772 100644 --- a/samples/wiremock-undertow/src/test/java/com/example/WiremockImportApplicationTests.java +++ b/samples/wiremock-undertow/src/test/java/com/example/WiremockImportApplicationTests.java @@ -16,14 +16,14 @@ package com.example; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; + 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.cloud.contract.wiremock.AutoConfigureWireMock; -import org.springframework.test.context.junit4.SpringRunner; + import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.get; @@ -31,7 +31,7 @@ import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringRunner.class) + @SpringBootTest(properties = "app.baseUrl=http://localhost:7070", webEnvironment = WebEnvironment.NONE) @AutoConfigureWireMock(port = 7070) public class WiremockImportApplicationTests { diff --git a/samples/wiremock-undertow/src/test/java/com/example/WiremockMockServerApplicationTests.java b/samples/wiremock-undertow/src/test/java/com/example/WiremockMockServerApplicationTests.java index 544e52c46f..08d2570598 100644 --- a/samples/wiremock-undertow/src/test/java/com/example/WiremockMockServerApplicationTests.java +++ b/samples/wiremock-undertow/src/test/java/com/example/WiremockMockServerApplicationTests.java @@ -16,20 +16,20 @@ package com.example; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; + 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.cloud.contract.wiremock.WireMockRestServiceServer; -import org.springframework.test.context.junit4.SpringRunner; + import org.springframework.test.web.client.MockRestServiceServer; import org.springframework.web.client.RestTemplate; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringRunner.class) + @SpringBootTest(webEnvironment = WebEnvironment.NONE) public class WiremockMockServerApplicationTests { diff --git a/samples/wiremock-undertow/src/test/java/com/example/WiremockServerApplicationTests.java b/samples/wiremock-undertow/src/test/java/com/example/WiremockServerApplicationTests.java index e6363de442..82ed33c99f 100644 --- a/samples/wiremock-undertow/src/test/java/com/example/WiremockServerApplicationTests.java +++ b/samples/wiremock-undertow/src/test/java/com/example/WiremockServerApplicationTests.java @@ -16,16 +16,16 @@ package com.example; -import com.github.tomakehurst.wiremock.junit.WireMockClassRule; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import com.github.tomakehurst.wiremock.WireMockServer; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; 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.cloud.contract.wiremock.WireMockSpring; -import org.springframework.test.context.junit4.SpringRunner; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.get; @@ -33,20 +33,34 @@ import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringRunner.class) + @SpringBootTest(properties = "app.baseUrl=http://localhost:7071", webEnvironment = WebEnvironment.NONE) public class WiremockServerApplicationTests { - @ClassRule - public static WireMockClassRule wiremock = new WireMockClassRule( + public static WireMockServer wiremock = new WireMockServer( WireMockSpring.options().port(7071)); + @BeforeAll + static void setup() { + wiremock.start(); + } + + @AfterEach + void after() { + wiremock.resetAll(); + } + + @AfterAll + static void clean() { + wiremock.shutdown(); + } + @Autowired private Service service; @Test public void contextLoads() throws Exception { - stubFor(get(urlEqualTo("/resource")).willReturn(aResponse() + wiremock.stubFor(get(urlEqualTo("/resource")).willReturn(aResponse() .withHeader("Content-Type", "text/plain").withBody("Hello World!"))); assertThat(this.service.go()).isEqualTo("Hello World!"); } diff --git a/samples/wiremock/pom.xml b/samples/wiremock/pom.xml index 7ee42746a3..93ad01e535 100644 --- a/samples/wiremock/pom.xml +++ b/samples/wiremock/pom.xml @@ -43,6 +43,12 @@ org.springframework.boot spring-boot-starter-test test + + + org.junit.vintage + junit-vintage-engine + + io.spring.initializr diff --git a/samples/wiremock/src/test/java/com/example/AutoConfigureWireMockFilesApplicationWithUrlResourceTests.java b/samples/wiremock/src/test/java/com/example/AutoConfigureWireMockFilesApplicationWithUrlResourceTests.java index 7e7ed7b8de..be764d4d42 100644 --- a/samples/wiremock/src/test/java/com/example/AutoConfigureWireMockFilesApplicationWithUrlResourceTests.java +++ b/samples/wiremock/src/test/java/com/example/AutoConfigureWireMockFilesApplicationWithUrlResourceTests.java @@ -16,16 +16,13 @@ package com.example; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; 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.cloud.contract.wiremock.AutoConfigureWireMock; -import org.springframework.test.context.junit4.SpringRunner; -@RunWith(SpringRunner.class) @SpringBootTest(classes = WiremockTestsApplication.class, properties = "app.baseUrl=http://localhost:${wiremock.server.port}", webEnvironment = WebEnvironment.NONE) // resource from a Initilizr stubs jar @AutoConfigureWireMock(port = 0, files = "classpath*:META-INF/io.spring.initializr/initializr-web/0.4.0.BUILD-SNAPSHOT") diff --git a/spring-cloud-contract-starters/spring-cloud-starter-contract-stub-runner-jetty/pom.xml b/spring-cloud-contract-starters/spring-cloud-starter-contract-stub-runner-jetty/pom.xml index 9effae5fc3..a697b32476 100644 --- a/spring-cloud-contract-starters/spring-cloud-starter-contract-stub-runner-jetty/pom.xml +++ b/spring-cloud-contract-starters/spring-cloud-starter-contract-stub-runner-jetty/pom.xml @@ -47,6 +47,12 @@ org.springframework.boot spring-boot-starter-test + + + org.junit.vintage + junit-vintage-engine + + org.springframework.boot diff --git a/spring-cloud-contract-starters/spring-cloud-starter-contract-stub-runner/pom.xml b/spring-cloud-contract-starters/spring-cloud-starter-contract-stub-runner/pom.xml index 7295e32477..34157b5d6a 100644 --- a/spring-cloud-contract-starters/spring-cloud-starter-contract-stub-runner/pom.xml +++ b/spring-cloud-contract-starters/spring-cloud-starter-contract-stub-runner/pom.xml @@ -34,6 +34,12 @@ org.springframework.cloud spring-cloud-contract-stub-runner + + + org.junit.vintage + junit-vintage-engine + + org.springframework.boot @@ -43,15 +49,30 @@ org.springframework.boot spring-boot-starter-test + + + org.junit.vintage + junit-vintage-engine + + org.springframework.cloud - spring-cloud-stream-test-support + spring-cloud-stream + test-jar + test + test-binder true org.springframework.cloud spring-cloud-contract-wiremock + + + org.junit.vintage + junit-vintage-engine + + diff --git a/spring-cloud-contract-starters/spring-cloud-starter-contract-verifier/pom.xml b/spring-cloud-contract-starters/spring-cloud-starter-contract-verifier/pom.xml index 136bd68bb7..bc6ae95752 100644 --- a/spring-cloud-contract-starters/spring-cloud-starter-contract-verifier/pom.xml +++ b/spring-cloud-contract-starters/spring-cloud-starter-contract-verifier/pom.xml @@ -37,6 +37,12 @@ org.springframework.boot spring-boot-starter-test + + + org.junit.vintage + junit-vintage-engine + + diff --git a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/ContractVerifierExtension.java b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/ContractVerifierExtension.java index 833363bdee..cea91ef61a 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/ContractVerifierExtension.java +++ b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/groovy/org/springframework/cloud/contract/verifier/plugin/ContractVerifierExtension.java @@ -240,7 +240,7 @@ public class ContractVerifierExtension { @Inject public ContractVerifierExtension(ProjectLayout layout, ObjectFactory objects) { - this.testFramework = objects.property(TestFramework.class).convention(TestFramework.JUNIT); + this.testFramework = objects.property(TestFramework.class).convention(TestFramework.JUNIT5); this.testMode = objects.property(TestMode.class).convention(TestMode.MOCKMVC); this.basePackageForTests = objects.property(String.class); this.baseClassForTests = objects.property(String.class); diff --git a/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/main/java/org/springframework/cloud/contract/maven/verifier/GenerateTestsMojo.java b/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/main/java/org/springframework/cloud/contract/maven/verifier/GenerateTestsMojo.java index 61d9029541..61d0b49692 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/main/java/org/springframework/cloud/contract/maven/verifier/GenerateTestsMojo.java +++ b/spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/main/java/org/springframework/cloud/contract/maven/verifier/GenerateTestsMojo.java @@ -74,7 +74,7 @@ public class GenerateTestsMojo extends AbstractMojo { @Parameter(defaultValue = "MOCKMVC") private TestMode testMode; - @Parameter(defaultValue = "JUNIT") + @Parameter(defaultValue = "JUNIT5") private TestFramework testFramework; @Parameter diff --git a/spring-cloud-contract-verifier/pom.xml b/spring-cloud-contract-verifier/pom.xml index cb03683e52..b535ed616e 100644 --- a/spring-cloud-contract-verifier/pom.xml +++ b/spring-cloud-contract-verifier/pom.xml @@ -177,6 +177,12 @@ org.springframework.boot spring-boot-starter-test + + + org.junit.vintage + junit-vintage-engine + + org.mockito @@ -258,6 +264,11 @@ xercesImpl test + + org.junit.vintage + junit-vintage-engine + test + diff --git a/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/config/ContractVerifierConfigProperties.java b/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/config/ContractVerifierConfigProperties.java index 5259a0e2f6..c14e5ae7e7 100644 --- a/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/config/ContractVerifierConfigProperties.java +++ b/spring-cloud-contract-verifier/src/main/groovy/org/springframework/cloud/contract/verifier/config/ContractVerifierConfigProperties.java @@ -45,7 +45,7 @@ public class ContractVerifierConfigProperties { /** * For which unit test library tests should be generated. */ - private TestFramework testFramework = TestFramework.JUNIT; + private TestFramework testFramework = TestFramework.JUNIT5; /** * Which mechanism should be used to invoke REST calls during. tests diff --git a/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/GeneratedTestClassTests.java b/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/GeneratedTestClassTests.java index 2e3d655541..c984a463df 100644 --- a/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/GeneratedTestClassTests.java +++ b/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/builder/GeneratedTestClassTests.java @@ -15,6 +15,7 @@ import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties; +import org.springframework.cloud.contract.verifier.config.TestFramework; import org.springframework.cloud.contract.verifier.file.ContractMetadata; import org.springframework.util.FileSystemUtils; @@ -116,6 +117,7 @@ public class GeneratedTestClassTests { // given JavaTestGenerator generator = new JavaTestGenerator(); ContractVerifierConfigProperties configProperties = new ContractVerifierConfigProperties(); + configProperties.setTestFramework(TestFramework.JUNIT); Collection contracts = Collections .singletonList(new ContractMetadata(this.file.toPath(), true, 1, 2, convertAsCollection(new File("/"), this.file))); diff --git a/spring-cloud-contract-wiremock/pom.xml b/spring-cloud-contract-wiremock/pom.xml index df62155462..ce823e90d1 100644 --- a/spring-cloud-contract-wiremock/pom.xml +++ b/spring-cloud-contract-wiremock/pom.xml @@ -66,6 +66,12 @@ org.springframework.boot spring-boot-starter-test true + + + org.junit.vintage + junit-vintage-engine + + com.github.tomakehurst @@ -126,5 +132,10 @@ + + org.junit.vintage + junit-vintage-engine + test +