From 074468849777643ef0d9075ac7b17f3ea50dd0f6 Mon Sep 17 00:00:00 2001 From: Alessandro Costa Date: Thu, 15 Oct 2020 09:22:02 +0200 Subject: [PATCH] KOGITO-3208: test with multiple executions in AbstractTrustyExplainabilityEnd2EndIT --- ...AbstractTrustyExplainabilityEnd2EndIT.java | 52 +++++++++++-------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/integration-tests/integration-tests-trusty-service/integration-tests-trusty-service-common/src/main/java/org/kie/kogito/it/trusty/AbstractTrustyExplainabilityEnd2EndIT.java b/integration-tests/integration-tests-trusty-service/integration-tests-trusty-service-common/src/main/java/org/kie/kogito/it/trusty/AbstractTrustyExplainabilityEnd2EndIT.java index 7e214522be..8af8d9f110 100644 --- a/integration-tests/integration-tests-trusty-service/integration-tests-trusty-service-common/src/main/java/org/kie/kogito/it/trusty/AbstractTrustyExplainabilityEnd2EndIT.java +++ b/integration-tests/integration-tests-trusty-service/integration-tests-trusty-service-common/src/main/java/org/kie/kogito/it/trusty/AbstractTrustyExplainabilityEnd2EndIT.java @@ -16,6 +16,7 @@ package org.kie.kogito.it.trusty; +import java.util.List; import java.util.function.BiFunction; import org.junit.jupiter.api.Test; @@ -23,7 +24,6 @@ import org.kie.kogito.testcontainers.InfinispanContainer; import org.kie.kogito.testcontainers.KogitoServiceContainer; import org.kie.kogito.testcontainers.TrustyServiceContainer; -import org.kie.kogito.trusty.service.responses.ExecutionHeaderResponse; import org.kie.kogito.trusty.service.responses.ExecutionsResponse; import org.kie.kogito.trusty.service.responses.SalienciesResponse; import org.slf4j.Logger; @@ -107,14 +107,23 @@ public void doTest() throws Exception { kogitoService.start(); assertTrue(kogitoService.isRunning()); - String json = "{\"Driver\":{\"Age\":25,\"Points\":13},\"Violation\":{\"Type\":\"speed\",\"Actual Speed\":115,\"Speed Limit\":100}}"; - - given() - .port(kogitoService.getFirstMappedPort()) - .contentType("application/json") - .body(json) - .when().post("/Traffic Violation") - .then().statusCode(200); + final List jsonList = List.of( + "{\"Driver\":{\"Age\":25,\"Points\":13},\"Violation\":{\"Type\":\"speed\",\"Actual Speed\":105,\"Speed Limit\":100}}", + "{\"Driver\":{\"Age\":37,\"Points\":20},\"Violation\":{\"Type\":\"speed\",\"Actual Speed\":135,\"Speed Limit\":100}}", + "{\"Driver\":{\"Age\":18,\"Points\": 0},\"Violation\":{\"Type\":\"speed\",\"Actual Speed\": 85,\"Speed Limit\": 70}}", + "{\"Driver\":{\"Age\":56,\"Points\":13},\"Violation\":{\"Type\":\"speed\",\"Actual Speed\": 35,\"Speed Limit\": 25}}", + "{\"Driver\":{\"Age\":40,\"Points\":13},\"Violation\":{\"Type\":\"speed\",\"Actual Speed\":215,\"Speed Limit\":120}}" + ); + final int expectedExecutions = jsonList.size(); + + jsonList.forEach(json -> + given() + .port(kogitoService.getFirstMappedPort()) + .contentType("application/json") + .body(json) + .when().post("/Traffic Violation") + .then().statusCode(200) + ); await() .atLeast(5, SECONDS) @@ -123,26 +132,25 @@ public void doTest() throws Exception { .untilAsserted(() -> { ExecutionsResponse executionsResponse = given() .port(trustyService.getFirstMappedPort()) - .when().get("/executions?limit=1") + .when().get(String.format("/executions?limit=%d", expectedExecutions)) .then().statusCode(200) .extract().as(ExecutionsResponse.class); - assertSame(1, executionsResponse.getHeaders().size()); + assertSame(expectedExecutions, executionsResponse.getHeaders().size()); - String executionId = executionsResponse.getHeaders().stream() - .findFirst() - .map(ExecutionHeaderResponse::getExecutionId) - .orElseThrow(IllegalStateException::new); + executionsResponse.getHeaders().forEach(execution -> { + String executionId = execution.getExecutionId(); - assertNotNull(executionId); + assertNotNull(executionId); - SalienciesResponse salienciesResponse = given() - .port(trustyService.getFirstMappedPort()) - .when().get("/executions/decisions/" + executionId + "/explanations/saliencies") - .then().statusCode(200) - .extract().as(SalienciesResponse.class); + SalienciesResponse salienciesResponse = given() + .port(trustyService.getFirstMappedPort()) + .when().get("/executions/decisions/" + executionId + "/explanations/saliencies") + .then().statusCode(200) + .extract().as(SalienciesResponse.class); - assertEquals("SUCCEEDED", salienciesResponse.getStatus()); + assertEquals("SUCCEEDED", salienciesResponse.getStatus()); + }); }); } }