use of org.kie.kogito.persistence.api.Storage 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());
}
use of org.kie.kogito.persistence.api.Storage 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());
}
use of org.kie.kogito.persistence.api.Storage in project kogito-apps by kiegroup.
the class TrustyServiceTest method givenManyExecutionsThenPaginationWorksProperly.
@Test
@SuppressWarnings("unchecked")
void givenManyExecutionsThenPaginationWorksProperly() {
List<Decision> decisions = new ArrayList<>();
IntStream.range(0, 10).forEach(x -> {
Decision d = new Decision();
d.setExecutionId(String.valueOf(x));
decisions.add(d);
});
Query queryMock = mock(Query.class);
when(queryMock.filter(any(List.class))).thenReturn(queryMock);
when(queryMock.sort(any(List.class))).thenReturn(queryMock);
when(queryMock.execute()).thenReturn(decisions);
Storage storageMock = mock(Storage.class);
decisions.forEach(x -> {
when(storageMock.put(eq(x.getExecutionId()), any(Object.class))).thenReturn(x);
when(storageMock.containsKey(eq(x.getExecutionId()))).thenReturn(false);
});
when(storageMock.query()).thenReturn(queryMock);
when(trustyStorageServiceMock.getDecisionsStorage()).thenReturn(storageMock);
decisions.forEach(x -> trustyService.storeDecision(x.getExecutionId(), x));
MatchedExecutionHeaders result = trustyService.getExecutionHeaders(OffsetDateTime.now().minusDays(1), OffsetDateTime.now(), 3, 5, "");
assertEquals(3, result.getExecutions().size());
assertEquals(decisions.size(), result.getAvailableResults());
result = trustyService.getExecutionHeaders(OffsetDateTime.now().minusDays(1), OffsetDateTime.now(), 100, 5, "");
assertEquals(5, result.getExecutions().size());
assertEquals(decisions.size(), result.getAvailableResults());
}
use of org.kie.kogito.persistence.api.Storage in project kogito-apps by kiegroup.
the class TrustyServiceTest method whenAModelIsNotStoredAndRetrievedByIdThenExceptionIsThrown.
@Test
@SuppressWarnings("unchecked")
void whenAModelIsNotStoredAndRetrievedByIdThenExceptionIsThrown() {
DMNModelMetadata modelIdentifier = buildDmnModelIdentifier();
Storage storageMock = mock(Storage.class);
when(storageMock.containsKey(modelIdentifier.getIdentifier())).thenReturn(false);
when(trustyStorageServiceMock.getModelStorage(DMNModelWithMetadata.class)).thenReturn(storageMock);
assertThrows(IllegalArgumentException.class, () -> trustyService.getModelById(modelIdentifier, DMNModelWithMetadata.class));
}
use of org.kie.kogito.persistence.api.Storage 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));
}
Aggregations