Search in sources :

Example 1 with StorageImplMock

use of org.kie.kogito.trusty.service.common.mocks.StorageImplMock in project kogito-apps by kiegroup.

the class TrustyServiceTest method givenAModelWhenAModelIsStoredAndRetrievedByIdThenTheOriginalObjectIsReturned.

@Test
@SuppressWarnings("unchecked")
void givenAModelWhenAModelIsStoredAndRetrievedByIdThenTheOriginalObjectIsReturned() {
    String model = TEST_MODEL;
    Storage storageMock = new StorageImplMock(String.class);
    when(trustyStorageServiceMock.getModelStorage(DMNModelWithMetadata.class)).thenReturn(storageMock);
    DMNModelWithMetadata dmnModelWithMetadata = buildDmnModel(model);
    DMNModelMetadata modelIdentifier = dmnModelWithMetadata.getModelMetaData();
    trustyService.storeModel(buildDmnModel(model));
    DMNModelWithMetadata result = trustyService.getModelById(modelIdentifier, DMNModelWithMetadata.class);
    assertEquals(model, result.getModel());
}
Also used : StorageImplMock(org.kie.kogito.trusty.service.common.mocks.StorageImplMock) DMNModelWithMetadata(org.kie.kogito.trusty.storage.api.model.decision.DMNModelWithMetadata) Storage(org.kie.kogito.persistence.api.Storage) DMNModelMetadata(org.kie.kogito.trusty.storage.api.model.decision.DMNModelMetadata) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 2 with StorageImplMock

use of org.kie.kogito.trusty.service.common.mocks.StorageImplMock in project kogito-apps by kiegroup.

the class TrustyServiceTest method givenADecisionWhenADecisionIsStoredAndRetrievedByIdThenTheOriginalObjectIsReturned.

@Test
@SuppressWarnings("unchecked")
void givenADecisionWhenADecisionIsStoredAndRetrievedByIdThenTheOriginalObjectIsReturned() {
    Decision decision = new Decision();
    decision.setExecutionId(TEST_EXECUTION_ID);
    @SuppressWarnings("unchecked") Storage storageMock = new StorageImplMock(Decision.class);
    when(trustyStorageServiceMock.getDecisionsStorage()).thenReturn(storageMock);
    trustyService.storeDecision(TEST_EXECUTION_ID, decision);
    Decision result = trustyService.getDecisionById(TEST_EXECUTION_ID);
    assertEquals(TEST_EXECUTION_ID, result.getExecutionId());
}
Also used : StorageImplMock(org.kie.kogito.trusty.service.common.mocks.StorageImplMock) Storage(org.kie.kogito.persistence.api.Storage) Decision(org.kie.kogito.trusty.storage.api.model.decision.Decision) Test(org.junit.jupiter.api.Test)

Example 3 with StorageImplMock

use of org.kie.kogito.trusty.service.common.mocks.StorageImplMock in project kogito-apps by kiegroup.

the class TrustyServiceTest method givenAnExplainabilityResultWhenAnExplainabilityResultIsStoredAndRetrievedByIdThenTheOriginalObjectIsReturned.

@Test
void givenAnExplainabilityResultWhenAnExplainabilityResultIsStoredAndRetrievedByIdThenTheOriginalObjectIsReturned() {
    LIMEExplainabilityResult result = new LIMEExplainabilityResult(TEST_EXECUTION_ID, ExplainabilityStatus.SUCCEEDED, null, Collections.emptyList());
    Storage<String, LIMEExplainabilityResult> storageMock = new StorageImplMock<>(String.class);
    when(trustyStorageServiceMock.getLIMEResultStorage()).thenReturn(storageMock);
    trustyService.storeExplainabilityResult(TEST_EXECUTION_ID, result);
    // The mocked stream needs to be recreated for subsequent invocations
    when(explanationHandlers.stream()).thenReturn(Stream.of(limeExplainerServiceHandler, counterfactualExplainerServiceHandler));
    assertEquals(result, trustyService.getExplainabilityResultById(TEST_EXECUTION_ID, LIMEExplainabilityResult.class));
}
Also used : StorageImplMock(org.kie.kogito.trusty.service.common.mocks.StorageImplMock) LIMEExplainabilityResult(org.kie.kogito.explainability.api.LIMEExplainabilityResult) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)3 StorageImplMock (org.kie.kogito.trusty.service.common.mocks.StorageImplMock)3 Storage (org.kie.kogito.persistence.api.Storage)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 LIMEExplainabilityResult (org.kie.kogito.explainability.api.LIMEExplainabilityResult)1 DMNModelMetadata (org.kie.kogito.trusty.storage.api.model.decision.DMNModelMetadata)1 DMNModelWithMetadata (org.kie.kogito.trusty.storage.api.model.decision.DMNModelWithMetadata)1 Decision (org.kie.kogito.trusty.storage.api.model.decision.Decision)1