use of org.kie.kogito.testcontainers.KogitoServiceContainer in project kogito-apps by kiegroup.
the class AbstractTrustyExplainabilityEnd2EndIT method doTest.
@Test
public void doTest() {
try (final Network network = Network.newNetwork();
final KogitoInfinispanContainer infinispan = new KogitoInfinispanContainer().withNetwork(network).withNetworkAliases(INFINISPAN_ALIAS);
final KogitoKafkaContainer kafka = new KogitoKafkaContainer().withNetwork(network).withNetworkAliases(KAFKA_ALIAS);
final KogitoKeycloakContainer keycloak = new KogitoKeycloakContainer().withEnv(KEYCLOAK_DB_VENDOR_VARIABLE, KEYCLOAK_DB_VENDOR_VALUE).withNetwork(network).withNetworkAliases(KEYCLOAK_ALIAS);
final ExplainabilityServiceMessagingContainer explService = new ExplainabilityServiceMessagingContainer(KAFKA_BOOTSTRAP_SERVERS, EXPL_SERVICE_SAMPLES).withLogConsumer(new Slf4jLogConsumer(LOGGER)).withNetwork(network).withNetworkAliases(EXPL_SERVICE_ALIAS);
final InfinispanTrustyServiceContainer trustyService = new InfinispanTrustyServiceContainer(INFINISPAN_SERVER_LIST, KAFKA_BOOTSTRAP_SERVERS, true).withEnv(TRUSTY_SERVICE_OIDC_AUTH_SERVER_URL_VARIABLE, TRUSTY_SERVICE_OIDC_AUTH_SERVER_URL_VALUE).withEnv(TRUSTY_SERVICE_OIDC_CLIENT_ID_VARIABLE, TRUSTY_SERVICE_OIDC_CLIENT_ID_VALUE).withEnv("INFINISPAN_USE_AUTH", "FALSE").withLogConsumer(new Slf4jLogConsumer(LOGGER)).withNetwork(network).withNetworkAliases(TRUSTY_SERVICE_ALIAS);
final KogitoServiceContainer kogitoService = kogitoServiceContainerProducer.apply(KAFKA_BOOTSTRAP_SERVERS, KOGITO_SERVICE_URL).withLogConsumer(new Slf4jLogConsumer(LOGGER)).withNetwork(network).withNetworkAliases(KOGITO_SERVICE_ALIAS)) {
infinispan.start();
assertTrue(infinispan.isRunning());
kafka.start();
assertTrue(kafka.isRunning());
keycloak.start();
assertTrue(keycloak.isRunning());
explService.start();
assertTrue(explService.isRunning());
trustyService.start();
assertTrue(trustyService.isRunning());
kogitoService.start();
assertTrue(kogitoService.isRunning());
final String accessToken = given().port(keycloak.getFirstMappedPort()).param(KEYCLOAK_GRANT_TYPE_PARAM_NAME, KEYCLOAK_GRANT_TYPE_PARAM_VALUE).param(KEYCLOAK_USERNAME_PARAM_NAME, KEYCLOAK_USERNAME_PARAM_VALUE).param(KEYCLOAK_PASSWORD_PARAM_NAME, KEYCLOAK_PASSWORD_PARAM_VALUE).param(KEYCLOAK_CLIENT_ID_PARAM_NAME, KEYCLOAK_CLIENT_ID_PARAM_VALUE).param(KEYCLOAK_CLIENT_SECRET_PARAM_NAME, KEYCLOAK_CLIENT_SECRET_PARAM_VALUE).when().post(KEYCLOAK_ACCESS_TOKEN_PATH).as(AccessTokenResponse.class).getToken();
assertNotNull(accessToken);
final List<String> executionIds = new ArrayList<>();
final int expectedExecutions = KOGITO_SERVICE_PAYLOADS.size();
LOGGER.info("Invoke Decision endpoint to generate LIME explanations...");
KOGITO_SERVICE_PAYLOADS.forEach(json -> given().port(kogitoService.getFirstMappedPort()).contentType("application/json").body(json).when().post("/Traffic Violation").then().statusCode(200));
LOGGER.info("Check Decisions executed...");
await().atLeast(5, SECONDS).atMost(30, SECONDS).with().pollInterval(5, SECONDS).untilAsserted(() -> {
ExecutionsResponse executionsResponse = given().port(trustyService.getFirstMappedPort()).auth().oauth2(accessToken).when().get(String.format("/executions?limit=%d", expectedExecutions)).then().statusCode(200).extract().as(ExecutionsResponse.class);
assertSame(expectedExecutions, executionsResponse.getHeaders().size());
executionsResponse.getHeaders().forEach(h -> executionIds.add(h.getExecutionId()));
});
LOGGER.info("Check LIME explanations generated...");
await().atLeast(5, SECONDS).atMost(60, SECONDS).with().pollInterval(5, SECONDS).untilAsserted(() -> {
executionIds.forEach(executionId -> {
SalienciesResponse salienciesResponse = given().port(trustyService.getFirstMappedPort()).auth().oauth2(accessToken).when().get("/executions/decisions/" + executionId + "/explanations/saliencies").then().statusCode(200).extract().as(SalienciesResponse.class);
assertEquals("SUCCEEDED", salienciesResponse.getStatus());
});
});
LOGGER.info("Request Counterfactuals for each execution and check responses generated...");
executionIds.forEach(executionId -> {
await().atLeast(500, MILLISECONDS).atMost(60, SECONDS).with().pollInterval(500, MILLISECONDS).until(doCounterfactualRequests(trustyService, accessToken, executionId));
await().atLeast(500, MILLISECONDS).atMost(60, SECONDS).with().pollInterval(500, MILLISECONDS).until(doCounterfactualResponses(trustyService, accessToken, executionId));
});
}
}
Aggregations