use of org.kie.kogito.trusty.storage.api.model.decision.Decision in project kogito-apps by kiegroup.
the class TrustyServiceTest method givenADecisionToProcessThatAlreadyExistsWhenExplainabilityIsEnabledThenExceptionIsThrown.
@Test
@SuppressWarnings("unchecked")
void givenADecisionToProcessThatAlreadyExistsWhenExplainabilityIsEnabledThenExceptionIsThrown() {
trustyService.enableExplainability();
Decision decision = new Decision();
decision.setExecutionId(TEST_EXECUTION_ID);
Storage<String, Decision> decisionStorageMock = mock(Storage.class);
when(decisionStorageMock.containsKey(eq(TEST_EXECUTION_ID))).thenReturn(true);
when(trustyStorageServiceMock.getDecisionsStorage()).thenReturn(decisionStorageMock);
assertThrows(IllegalArgumentException.class, () -> trustyService.processDecision(TEST_EXECUTION_ID, decision));
verify(explainabilityRequestProducerMock, never()).sendEvent(any());
}
use of org.kie.kogito.trusty.storage.api.model.decision.Decision in project kogito-apps by kiegroup.
the class TrustyServiceTest method givenADecisionToProcessWhenExplainabilityIsEnabledThenRequestIsSent.
@Test
@SuppressWarnings("unchecked")
void givenADecisionToProcessWhenExplainabilityIsEnabledThenRequestIsSent() throws JsonProcessingException {
trustyService.enableExplainability();
Decision decision = new Decision(TEST_EXECUTION_ID, TEST_SOURCE_URL, TEST_SERVICE_URL, 1591692950000L, true, null, "model", "modelNamespace", List.of(new DecisionInput("1", "Input1", new CollectionValue("string", List.of(new UnitValue("string", "string", toJsonNode("\"ONE\"")), new UnitValue("string", "string", toJsonNode("\"TWO\""))))), new DecisionInput("2", "Input2", new StructureValue("Person", Map.of("Name", new UnitValue("string", "string", toJsonNode("\"George Orwell\"")), "Age", new UnitValue("number", "number", toJsonNode("45")))))), List.of(new DecisionOutcome("OUT1", "Result", "SUCCEEDED", new UnitValue("string", "string", toJsonNode("\"YES\"")), Collections.emptyList(), Collections.emptyList())));
Storage<String, Decision> decisionStorageMock = mock(Storage.class);
when(decisionStorageMock.containsKey(eq(TEST_EXECUTION_ID))).thenReturn(false);
when(trustyStorageServiceMock.getDecisionsStorage()).thenReturn(decisionStorageMock);
trustyService.processDecision(TEST_EXECUTION_ID, decision);
verify(explainabilityRequestProducerMock).sendEvent(any());
}
use of org.kie.kogito.trusty.storage.api.model.decision.Decision in project kogito-apps by kiegroup.
the class TrustyServiceTest method givenADecisionWhenStoreDecisionIsCalledThenNoExceptionsAreThrown.
@Test
@SuppressWarnings("unchecked")
void givenADecisionWhenStoreDecisionIsCalledThenNoExceptionsAreThrown() {
Decision decision = new Decision();
Storage storageMock = mock(Storage.class);
when(storageMock.put(any(Object.class), any(Object.class))).thenReturn(decision);
when(trustyStorageServiceMock.getDecisionsStorage()).thenReturn(storageMock);
Assertions.assertDoesNotThrow(() -> trustyService.storeDecision("test", decision));
}
use of org.kie.kogito.trusty.storage.api.model.decision.Decision in project kogito-apps by kiegroup.
the class TrustyServiceTest method doGivenStoredExecutionWhenCounterfactualRequestIsMadeThenRequestIsStoredTest.
@SuppressWarnings("unchecked")
void doGivenStoredExecutionWhenCounterfactualRequestIsMadeThenRequestIsStoredTest(CounterfactualDomain domain) {
Storage<String, Decision> decisionStorage = mock(Storage.class);
Storage<String, CounterfactualExplainabilityRequest> counterfactualStorage = mock(Storage.class);
ArgumentCaptor<CounterfactualExplainabilityRequest> counterfactualArgumentCaptor = ArgumentCaptor.forClass(CounterfactualExplainabilityRequest.class);
when(decisionStorage.containsKey(eq(TEST_EXECUTION_ID))).thenReturn(true);
when(trustyStorageServiceMock.getDecisionsStorage()).thenReturn(decisionStorage);
when(trustyStorageServiceMock.getCounterfactualRequestStorage()).thenReturn(counterfactualStorage);
when(decisionStorage.get(eq(TEST_EXECUTION_ID))).thenReturn(TrustyServiceTestUtils.buildCorrectDecision(TEST_EXECUTION_ID));
// The Goals structures must be comparable to the original decisions outcomes.
// The Search Domain structures must be identical those of the original decision inputs.
trustyService.requestCounterfactuals(TEST_EXECUTION_ID, List.of(new NamedTypedValue("Fine", new StructureValue("tFine", Map.of("Amount", new UnitValue("number", "number", new IntNode(0)), "Points", new UnitValue("number", "number", new IntNode(0))))), new NamedTypedValue("Should the driver be suspended?", new UnitValue("string", "string", new TextNode("No")))), List.of(new CounterfactualSearchDomain("Violation", new CounterfactualSearchDomainStructureValue("tViolation", Map.of("Type", new CounterfactualSearchDomainUnitValue("string", "string", true, domain), "Actual Speed", new CounterfactualSearchDomainUnitValue("number", "number", true, domain), "Speed Limit", new CounterfactualSearchDomainUnitValue("number", "number", true, domain)))), new CounterfactualSearchDomain("Driver", new CounterfactualSearchDomainStructureValue("tDriver", Map.of("Age", new CounterfactualSearchDomainUnitValue("number", "number", true, domain), "Points", new CounterfactualSearchDomainUnitValue("number", "number", true, domain))))));
verify(counterfactualStorage).put(anyString(), counterfactualArgumentCaptor.capture());
CounterfactualExplainabilityRequest counterfactual = counterfactualArgumentCaptor.getValue();
assertNotNull(counterfactual);
assertEquals(TEST_EXECUTION_ID, counterfactual.getExecutionId());
}
use of org.kie.kogito.trusty.storage.api.model.decision.Decision in project kogito-apps by kiegroup.
the class TrustyServiceTestUtils method buildCorrectDecision.
public static Decision buildCorrectDecision(String cloudEventId) {
Decision decision = readResource("/events/correctDecision.json", Decision.class);
decision.setExecutionId(cloudEventId);
return decision;
}
Aggregations