use of org.kie.kogito.trusty.service.common.responses.decision.DecisionOutcomesResponse in project kogito-apps by kiegroup.
the class AbstractTrustyExplainabilityEnd2EndIT method doCounterfactualRequests.
private Callable<Boolean> doCounterfactualRequests(final InfinispanTrustyServiceContainer trustyService, final String accessToken, final String executionId) {
LOGGER.info(String.format("Reading Decision [%s]'s Inputs...", executionId));
DecisionStructuredInputsResponse inputs = given().port(trustyService.getFirstMappedPort()).auth().oauth2(accessToken).when().get("/executions/decisions/" + executionId + "/structuredInputs").then().statusCode(200).extract().as(DecisionStructuredInputsResponse.class);
LOGGER.info(String.format("Reading Decision [%s]'s Outputs...", executionId));
DecisionOutcomesResponse outcomes = given().port(trustyService.getFirstMappedPort()).auth().oauth2(accessToken).when().get("/executions/decisions/" + executionId + "/outcomes").then().statusCode(200).extract().as(DecisionOutcomesResponse.class);
// Debugging output (handy to keep).
ObjectMapper mapper = new ObjectMapper();
ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
StringBuilder sb = new StringBuilder();
sb.append("== INPUTS ==>\n");
inputs.getInputs().forEach(i -> {
try {
sb.append(writer.writeValueAsString(i)).append("\n");
} catch (JsonProcessingException jpe) {
// Swallow
}
});
sb.append("== OUTPUTS ==>\n");
outcomes.getOutcomes().forEach(o -> {
try {
sb.append(writer.writeValueAsString(o.getOutcomeResult())).append("\n");
} catch (JsonProcessingException jpe) {
// Swallow
}
});
LOGGER.debug(sb.toString());
return () -> {
LOGGER.info(String.format("Checking Decision [%s]'s Counterfactual request was successful...", executionId));
// The Goals and Search Domain structures must match those of the original decision
// See https://issues.redhat.com/browse/FAI-486
CounterfactualRequestResponse counterfactualRequestResponse = given().port(trustyService.getFirstMappedPort()).auth().oauth2(accessToken).when().contentType(ContentType.JSON).body(new CounterfactualRequest(outcomes.getOutcomes().stream().map(AbstractTrustyExplainabilityEnd2EndIT::toCounterfactualGoal).collect(Collectors.toList()), inputs.getInputs().stream().map(AbstractTrustyExplainabilityEnd2EndIT::toCounterfactualSearchDomain).collect(Collectors.toList()))).post("/executions/decisions/" + executionId + "/explanations/counterfactuals").then().statusCode(200).extract().as(CounterfactualRequestResponse.class);
return Objects.nonNull(counterfactualRequestResponse) && Objects.equals(executionId, counterfactualRequestResponse.getExecutionId()) && Objects.nonNull(counterfactualRequestResponse.getCounterfactualId());
};
}
use of org.kie.kogito.trusty.service.common.responses.decision.DecisionOutcomesResponse in project kogito-apps by kiegroup.
the class DecisionsApiV1IT method assertGetOutcomesCorrectEmptyResponse.
private void assertGetOutcomesCorrectEmptyResponse(ListStatus inputsStatus) throws Exception {
mockServiceWithDecision(inputsStatus, ListStatus.EMPTY);
DecisionOutcomesResponse response = get("/outcomes").as(DecisionOutcomesResponse.class);
assertDecisionOutcomesResponse(buildDecisionOutcomesResponse(ListStatus.EMPTY), response);
}
use of org.kie.kogito.trusty.service.common.responses.decision.DecisionOutcomesResponse in project kogito-apps by kiegroup.
the class DecisionsApiV1IT method assertGetOutcomesCorrectFullResponse.
private void assertGetOutcomesCorrectFullResponse(ListStatus inputsStatus) throws Exception {
mockServiceWithDecision(inputsStatus, ListStatus.FULL);
DecisionOutcomesResponse response = get("/outcomes").as(DecisionOutcomesResponse.class);
assertDecisionOutcomesResponse(buildDecisionOutcomesResponse(ListStatus.FULL), response);
}
use of org.kie.kogito.trusty.service.common.responses.decision.DecisionOutcomesResponse in project kogito-apps by kiegroup.
the class DecisionsApiV1IT method assertGetOutcomesCorrectNullResponse.
private void assertGetOutcomesCorrectNullResponse(ListStatus inputsStatus) throws Exception {
mockServiceWithDecision(inputsStatus, ListStatus.NULL);
DecisionOutcomesResponse response = get("/outcomes").as(DecisionOutcomesResponse.class);
assertDecisionOutcomesResponse(buildDecisionOutcomesResponse(ListStatus.NULL), response);
}
Aggregations