use of org.kie.kogito.trusty.storage.api.model.decision.Decision in project kogito-apps by kiegroup.
the class ExecutionsApiV1IT method givenARequestWhenExecutionEndpointIsCalledThenTheExecutionHeaderIsReturned.
@Test
void givenARequestWhenExecutionEndpointIsCalledThenTheExecutionHeaderIsReturned() throws ParseException {
Execution execution = new Decision("test1", "http://localhost:8081/model/service", "http://localhost:8081", OffsetDateTime.parse("2020-01-01T00:00:00Z", DateTimeFormatter.ISO_OFFSET_DATE_TIME).toInstant().toEpochMilli(), true, "name", "model", "namespace", Collections.emptyList(), Collections.emptyList());
Mockito.when(executionService.getExecutionHeaders(any(OffsetDateTime.class), any(OffsetDateTime.class), any(Integer.class), any(Integer.class), any(String.class))).thenReturn(new MatchedExecutionHeaders(List.of(execution), 1));
ExecutionsResponse response = given().contentType(ContentType.JSON).when().get("/executions?from=2000-01" + "-01T00:00:00Z&to=2021" + "-01-01T00:00:00Z").as(ExecutionsResponse.class);
Assertions.assertEquals(1, response.getHeaders().size());
}
use of org.kie.kogito.trusty.storage.api.model.decision.Decision in project kogito-apps by kiegroup.
the class ExecutionsApiV1IT method givenARequestWithExistingModelWhenModelEndpointIsCalledThenTheModelIsReturned.
@Test
void givenARequestWithExistingModelWhenModelEndpointIsCalledThenTheModelIsReturned() {
DMNModelWithMetadata dmnModelWithMetadata = new DMNModelWithMetadata("groupId", "artifactId", "modelVersion", "dmnVersion", "name", "namespace", "definition");
final Decision decision = mock(Decision.class);
when(decision.getExecutedModelName()).thenReturn("name");
when(decision.getExecutedModelNamespace()).thenReturn("namespace");
when(executionService.getDecisionById(anyString())).thenReturn(decision);
when(executionService.getModelById(any(DMNModelMetadata.class), eq(DMNModelWithMetadata.class))).thenReturn(dmnModelWithMetadata);
DMNModelWithMetadata response = given().contentType(ContentType.TEXT).when().get("/executions/123/model").as(DMNModelWithMetadata.class);
assertEquals(dmnModelWithMetadata.getModel(), response.getModel());
assertEquals(dmnModelWithMetadata.getGroupId(), response.getGroupId());
assertEquals(dmnModelWithMetadata.getNamespace(), response.getNamespace());
assertEquals(dmnModelWithMetadata.getName(), response.getName());
assertEquals(dmnModelWithMetadata.getArtifactId(), response.getArtifactId());
}
use of org.kie.kogito.trusty.storage.api.model.decision.Decision in project kogito-apps by kiegroup.
the class ExplainabilityApiV1IT method testSalienciesWithExplainabilityResult.
@Test
void testSalienciesWithExplainabilityResult() {
mockServiceWithExplainabilityResult();
Decision decision = new Decision(TEST_EXECUTION_ID, "sourceUrl", "serviceUrl", 0L, true, "executorName", "executorModelName", "executorModelNamespace", new ArrayList<>(), new ArrayList<>());
decision.getOutcomes().add(new DecisionOutcome("outcomeId1", "Output1", ExplainabilityStatus.SUCCEEDED.name(), new UnitValue("type", new IntNode(1)), Collections.emptyList(), Collections.emptyList()));
decision.getOutcomes().add(new DecisionOutcome("outcomeId2", "Output2", ExplainabilityStatus.SUCCEEDED.name(), new UnitValue("type2", new IntNode(2)), Collections.emptyList(), Collections.emptyList()));
when(executionService.getDecisionById(eq(TEST_EXECUTION_ID))).thenReturn(decision);
SalienciesResponse response = given().filter(new ResponseLoggingFilter()).when().get("/executions/decisions/" + TEST_EXECUTION_ID + "/explanations/saliencies").as(SalienciesResponse.class);
assertNotNull(response);
assertNotNull(response.getSaliencies());
assertSame(2, response.getSaliencies().size());
List<SaliencyModel> sortedSaliencies = response.getSaliencies().stream().sorted((s1, s2) -> new CompareToBuilder().append(s1.getOutcomeName(), s2.getOutcomeName()).toComparison()).collect(Collectors.toList());
assertNotNull(sortedSaliencies.get(0));
assertEquals("Output1", sortedSaliencies.get(0).getOutcomeName());
assertNotNull(sortedSaliencies.get(0).getFeatureImportance());
assertSame(2, sortedSaliencies.get(0).getFeatureImportance().size());
assertEquals("Feature1", sortedSaliencies.get(0).getFeatureImportance().get(0).getFeatureName());
assertEquals(0.49384, sortedSaliencies.get(0).getFeatureImportance().get(0).getFeatureScore());
assertEquals("Feature2", sortedSaliencies.get(0).getFeatureImportance().get(1).getFeatureName());
assertEquals(-0.1084, sortedSaliencies.get(0).getFeatureImportance().get(1).getFeatureScore());
assertNotNull(sortedSaliencies.get(1));
assertEquals("Output2", sortedSaliencies.get(1).getOutcomeName());
assertNotNull(sortedSaliencies.get(1).getFeatureImportance());
assertSame(2, sortedSaliencies.get(1).getFeatureImportance().size());
assertEquals("Feature1", sortedSaliencies.get(1).getFeatureImportance().get(0).getFeatureName());
assertEquals(0.0, sortedSaliencies.get(1).getFeatureImportance().get(0).getFeatureScore());
assertEquals("Feature2", sortedSaliencies.get(1).getFeatureImportance().get(1).getFeatureName());
assertEquals(0.70293, sortedSaliencies.get(1).getFeatureImportance().get(1).getFeatureScore());
}
use of org.kie.kogito.trusty.storage.api.model.decision.Decision in project kogito-apps by kiegroup.
the class LIMESaliencyConverterTest method testFromResult_DecisionExists.
@Test
public void testFromResult_DecisionExists() {
LIMEExplainabilityResult result = LIMEExplainabilityResult.buildSucceeded(EXECUTION_ID, List.of(new SaliencyModel("outcomeName1", List.of(new FeatureImportanceModel("feature1a", 1.0), new FeatureImportanceModel("feature1b", 2.0))), new SaliencyModel("outcomeName2", List.of(new FeatureImportanceModel("feature2", 3.0)))));
Decision decision = new Decision(EXECUTION_ID, "sourceUrl", "serviceUrl", 0L, true, "executorName", "executorModelName", "executorModelNamespace", new ArrayList<>(), new ArrayList<>());
decision.getOutcomes().add(new DecisionOutcome("outcomeId1", "outcomeName1", ExplainabilityStatus.SUCCEEDED.name(), new UnitValue("type", new IntNode(1)), Collections.emptyList(), Collections.emptyList()));
decision.getOutcomes().add(new DecisionOutcome("outcomeId2", "outcomeName2", ExplainabilityStatus.SUCCEEDED.name(), new UnitValue("type2", new IntNode(2)), Collections.emptyList(), Collections.emptyList()));
when(trustyService.getDecisionById(eq(EXECUTION_ID))).thenReturn(decision);
SalienciesResponse response = converter.fromResult(EXECUTION_ID, result);
assertNotNull(response);
assertEquals(ExplainabilityStatus.SUCCEEDED.name(), response.getStatus());
assertEquals(2, response.getSaliencies().size());
List<SaliencyResponse> saliencyResponses = new ArrayList<>(response.getSaliencies());
SaliencyResponse saliencyResponse1 = saliencyResponses.get(0);
assertEquals("outcomeId1", saliencyResponse1.getOutcomeId());
assertEquals("outcomeName1", saliencyResponse1.getOutcomeName());
assertEquals(2, saliencyResponse1.getFeatureImportance().size());
Optional<FeatureImportanceModel> oFeatureImportance1Model1 = saliencyResponse1.getFeatureImportance().stream().filter(fim -> fim.getFeatureName().equals("feature1a")).findFirst();
assertTrue(oFeatureImportance1Model1.isPresent());
assertEquals(1.0, oFeatureImportance1Model1.get().getFeatureScore());
Optional<FeatureImportanceModel> oFeatureImportance2Model1 = saliencyResponse1.getFeatureImportance().stream().filter(fim -> fim.getFeatureName().equals("feature1b")).findFirst();
assertTrue(oFeatureImportance2Model1.isPresent());
assertEquals(2.0, oFeatureImportance2Model1.get().getFeatureScore());
SaliencyResponse saliencyResponse2 = saliencyResponses.get(1);
assertEquals("outcomeId2", saliencyResponse2.getOutcomeId());
assertEquals("outcomeName2", saliencyResponse2.getOutcomeName());
assertEquals(1, saliencyResponse2.getFeatureImportance().size());
Optional<FeatureImportanceModel> oFeatureImportance1Model2 = saliencyResponse2.getFeatureImportance().stream().filter(fim -> fim.getFeatureName().equals("feature2")).findFirst();
assertTrue(oFeatureImportance1Model2.isPresent());
assertEquals(3.0, oFeatureImportance1Model2.get().getFeatureScore());
}
use of org.kie.kogito.trusty.storage.api.model.decision.Decision in project kogito-apps by kiegroup.
the class AbstractTraceEventConsumerIT method testCorrectCloudEvent.
@Test
@Disabled("https://issues.redhat.com/browse/KOGITO-4318")
void testCorrectCloudEvent() throws JsonProcessingException, JSONException {
kafkaClient.produce(TrustyServiceTestUtils.buildCloudEventJsonString(TrustyServiceTestUtils.buildCorrectTraceEvent(TrustyServiceTestUtils.CORRECT_CLOUDEVENT_ID)), KafkaConstants.KOGITO_TRACING_TOPIC);
await().atMost(5, SECONDS).untilAsserted(() -> assertDoesNotThrow(() -> trustyService.getDecisionById(TrustyServiceTestUtils.CORRECT_CLOUDEVENT_ID)));
Decision storedDecision = trustyService.getDecisionById(TrustyServiceTestUtils.CORRECT_CLOUDEVENT_ID);
assertNotNull(storedDecision);
JSONAssert.assertEquals(MAPPER.writeValueAsString(TrustyServiceTestUtils.buildCorrectDecision(TrustyServiceTestUtils.CORRECT_CLOUDEVENT_ID)), MAPPER.writeValueAsString(storedDecision), true);
}
Aggregations