I'm trying to implement some contract testing across some microservices.
On the producer side, I have this contract:
Contract.make {
name("ContractUpdate")
description "update a payload resource"
request{
method POST()
url("/payload/1")
headers {
contentType('application/json')
}
body(
absoluteFilePath: $(anyNonEmptyString()),
fileName: "1",
ftpFolder: "ftp_folder",
lastModifiedTS: 2343243,
fileSize: 12345,
state: "INVALID",
errors:[
[
code: "9019",
description: "NOT_UTF8_COMPLIANT"
],
[
code: "9011",
description: "NOT_CONFORM_TO_CSV_STANDARD"
]
]
)
}
response {
status OK()
headers {
contentType('application/json')
}
body(payloadId : "1", state : "INVALID", fileName: "1")
}
}
I have a few other contracts for creating new resources, fetching resources that don't exist etc. And after installing the stubs, I have this on the consumer side:
@SpringBootTest
@AutoConfigureMockMvc
@ActiveProfiles("test")
@AutoConfigureStubRunner(
stubsMode = StubRunnerProperties.StubsMode.LOCAL,
ids = "com.mapt.shared:intf" + "-payload-orchestrator:+:stubs:8090")
class OrchestratorContractTest {
@Autowired
private FileProcessorProperties fileProcessorProperties;
@Autowired
private MockMvc mockMvc;
@Test
void given_valid_payload_id_orchestrator_should_return_ok()
throws Exception {
List<PayloadError> errors = new ArrayList<>();
errors.add(new PayloadError("9019","NOT_UTF8_COMPLIANT"));
errors.add(new PayloadError("9011","NOT_CONFORM_TO_CSV_STANDARD"));
PayloadRequest request = PayloadRequest.builder()
.state(PayloadState.INVALID.toString())
.fileName("1")
.fileSize(12345)
.absoluteFilePath("testPath")
.ftpFolder("ftp_folder")
.lastModifiedTS(2343243)
.errors(errors)
.build();
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
this.mockMvc.perform(MockMvcRequestBuilders
.post("/payload/1")
.headers(httpHeaders)
.content(new Gson().toJson(request, PayloadRequest.class)))
.andDo(print())
.andExpect(status().isOk());
}
I keep getting failed assertion - a 404 error code is returned and I cant figure out why. I just started working on spring cloud contracts so I'm not sure if I'm doing a very basic error. Thanks for any help!