Re-organize contract generation into a new helper

This commit is contained in:
Dave Syer
2016-07-26 08:27:35 +01:00
parent 1a8c1214c4
commit 44eebcab0f
4 changed files with 51 additions and 15 deletions

View File

@@ -1,7 +1,5 @@
package com.example.fraud;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import java.math.BigDecimal;
import org.junit.Test;
@@ -12,6 +10,7 @@ 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;
@@ -32,7 +31,7 @@ public class StubGeneratorTests {
@Autowired
private MockMvc mockMvc;
@Autowired
private WireMockSnippet snippet;
@@ -50,9 +49,10 @@ public class StubGeneratorTests {
.value("FRAUD"))
.andExpect(MockMvcResultMatchers.jsonPath("$.rejectionReason")
.value("Amount too high"))
.andDo(snippet.content().jsonPath("$.clientId").jsonPath("$[?(@.loanAmount > 1000)]")
.contentType(MediaType.valueOf("application/vnd.fraud.v1+json")))
.andDo(document("markClientAsFraud"));
.andDo(RestDocsContracts.content(snippet).jsonPath("$.clientId")
.jsonPath("$[?(@.loanAmount > 1000)]")
.contentType(MediaType.valueOf("application/vnd.fraud.v1+json"))
.contract("markClientAsFraud"));
}
@Test
@@ -63,13 +63,14 @@ 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("OK"))
.andExpect(
MockMvcResultMatchers.jsonPath("$.fraudCheckStatus").value("OK"))
.andExpect(MockMvcResultMatchers.jsonPath("$.rejectionReason")
.doesNotExist())
.andDo(snippet.content().jsonPath("$.clientId").jsonPath("$[?(@.loanAmount <= 1000)]")
.contentType(MediaType.valueOf("application/vnd.fraud.v1+json")))
.andDo(document("markClientAsNotFraud"));
.andDo(RestDocsContracts.content(snippet).jsonPath("$.clientId")
.jsonPath("$[?(@.loanAmount <= 1000)]")
.contentType(MediaType.valueOf("application/vnd.fraud.v1+json"))
.contract("markClientAsNotFraud"));
}
}