Leszek Izdebski
06/30/2023, 10:48 AMpublic void getList() {
int XxxId = 1;
stubPostOperationResponse(XxxId, "YYY");
mockAuthentication();
for (int i = 0; i < 2; i++) {
given()
.contentType(ContentType.JSON)
.body(triggerSomethingRequest)
.port(randomServerPort)
.when()
.post("XYZ")
.then()
.statusCode(201);
}
GetAnalysesResponseDto response = given()
.port(randomServerPort)
.when()
.get("analysis")
.then()
.statusCode(200)
.extract()
.response()
.as(GetAnalysesResponseDto.class);
int responseSize = response.getAnalyses().size();
assertEquals(2, responseSize);
}
private void stubPostOperationResponse(int operationId, String resourceName) {
String expectedOutboundRequestBody = TestUtils.readResourceFile(resourceName);
WireMock.importStubs(
stubImport()
.stub(
post("/xxx/operations")
.withRequestBody(equalToJson(expectedOutboundRequestBody, true, false))
.willReturn(
created()
.withHeader(HttpHeaders.CONNECTION, "close")
.withHeader("Content-Type", "application/json")
.withBody("{\"id\":" + operationId + "}")))
.doNotDeleteExistingStubs());
}