JAVA-22296 | Upgrade spring-cloud-modules to JDK 17: Chunk 4 (#15020)

This commit is contained in:
Gaetano Piazzolla 2023-11-03 13:21:09 +01:00 committed by GitHub
parent b11ba77937
commit 26a57c08ee
2 changed files with 19 additions and 40 deletions

View File

@ -16,10 +16,12 @@
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
@ -30,16 +32,25 @@
<artifactId>spring-cloud-contract-wiremock</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-contract-stub-runner</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.baeldung.spring.cloud</groupId>
<artifactId>spring-cloud-contract-producer</artifactId>
<version>${project.parent.version}</version>
<classifier>stubs</classifier>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>

View File

@ -1,24 +1,18 @@
package com.baeldung.spring.cloud.springcloudcontractconsumer.controller;
import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
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.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.contract.stubrunner.spring.AutoConfigureStubRunner;
import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties;
import org.springframework.cloud.contract.stubrunner.junit.StubRunnerRule;
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;
import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@ -26,42 +20,16 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK)
@AutoConfigureMockMvc
@AutoConfigureJsonTesters
@AutoConfigureStubRunner(stubsMode = StubRunnerProperties.StubsMode.LOCAL,
ids = "com.baeldung.spring.cloud:spring-cloud-contract-producer:+:stubs:8090")
public class BasicMathControllerIntegrationTest {
@Rule
public StubRunnerRule rule = new StubRunnerRule().downloadStub(
"com.baeldung.spring.cloud",
"spring-cloud-contract-producer")
.withPort(8090).failOnNoStubs(true);
@Autowired
private MockMvc mockMvc;
private static WireMockServer wireMockServer;
@BeforeClass
public static void setupClass() {
WireMockConfiguration wireMockConfiguration = WireMockConfiguration.options().port(8090); // Use the same port as in your code
wireMockServer = new WireMockServer(wireMockConfiguration);
wireMockServer.start();
}
@AfterClass
public static void teardownClass() {
wireMockServer.stop();
}
@Before
public void setup() {
wireMockServer.stubFor(get(urlEqualTo("/validate/prime-number?number=1"))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "application/json")
.withBody("Odd")));
wireMockServer.stubFor(get(urlEqualTo("/validate/prime-number?number=2"))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "application/json")
.withBody("Even")));
}
@Test
public void given_WhenPassEvenNumberInQueryParam_ThenReturnEven() throws Exception {