Expose WireMockServer for @Autowired in test class
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
</fileSet>
|
||||
<fileSet>
|
||||
<directory>${project.build.directory}/snippets/stubs</directory>
|
||||
<outputDirectory>META-INF/wiremock/mappings/${project.artifactId}</outputDirectory>
|
||||
<outputDirectory>META-INF/${project.groupId}/${project.artifactId}/${project.version}/mappings</outputDirectory>
|
||||
<includes>
|
||||
<include>**/*</include>
|
||||
</includes>
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.example.fraud;
|
||||
|
||||
import static org.springframework.cloud.contract.wiremock.RestDocsContracts.verify;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -10,14 +13,11 @@ import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDoc
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.json.JacksonTester;
|
||||
import org.springframework.cloud.contract.wiremock.RestDocsContracts;
|
||||
import org.springframework.cloud.contract.wiremock.WireMockSnippet;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
||||
|
||||
import com.example.fraud.model.FraudCheck;
|
||||
|
||||
@@ -32,9 +32,6 @@ public class StubGeneratorTests {
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@Autowired
|
||||
private WireMockSnippet snippet;
|
||||
|
||||
private JacksonTester<FraudCheck> json;
|
||||
|
||||
@Test
|
||||
@@ -45,11 +42,9 @@ public class StubGeneratorTests {
|
||||
mockMvc.perform(MockMvcRequestBuilders.put("/fraudcheck")
|
||||
.contentType(MediaType.valueOf("application/vnd.fraud.v1+json"))
|
||||
.content(json.write(fraudCheck).getJson()))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.fraudCheckStatus")
|
||||
.value("FRAUD"))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.rejectionReason")
|
||||
.value("Amount too high"))
|
||||
.andDo(RestDocsContracts.content(snippet).jsonPath("$.clientId")
|
||||
.andExpect(jsonPath("$.fraudCheckStatus").value("FRAUD"))
|
||||
.andExpect(jsonPath("$.rejectionReason").value("Amount too high"))
|
||||
.andDo(verify().jsonPath("$.clientId")
|
||||
.jsonPath("$[?(@.loanAmount > 1000)]")
|
||||
.contentType(MediaType.valueOf("application/vnd.fraud.v1+json"))
|
||||
.contract("markClientAsFraud"));
|
||||
@@ -59,15 +54,13 @@ public class StubGeneratorTests {
|
||||
public void shouldMarkClientAsNotFraud() throws Exception {
|
||||
FraudCheck fraudCheck = new FraudCheck();
|
||||
fraudCheck.setClientId("1234567890");
|
||||
fraudCheck.setLoanAmount(BigDecimal.valueOf(1));
|
||||
fraudCheck.setLoanAmount(BigDecimal.valueOf(123.123));
|
||||
mockMvc.perform(MockMvcRequestBuilders.put("/fraudcheck")
|
||||
.contentType(MediaType.valueOf("application/vnd.fraud.v1+json"))
|
||||
.content(json.write(fraudCheck).getJson()))
|
||||
.andExpect(
|
||||
MockMvcResultMatchers.jsonPath("$.fraudCheckStatus").value("OK"))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.rejectionReason")
|
||||
.doesNotExist())
|
||||
.andDo(RestDocsContracts.content(snippet).jsonPath("$.clientId")
|
||||
.andExpect(jsonPath("$.fraudCheckStatus").value("OK"))
|
||||
.andExpect(jsonPath("$.rejectionReason").doesNotExist())
|
||||
.andDo(verify().jsonPath("$.clientId")
|
||||
.jsonPath("$[?(@.loanAmount <= 1000)]")
|
||||
.contentType(MediaType.valueOf("application/vnd.fraud.v1+json"))
|
||||
.contract("markClientAsNotFraud"));
|
||||
|
||||
Reference in New Issue
Block a user