Search in sources :

Example 1 with Storage

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());
}
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 Storage

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());
}
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 Storage

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());
}
Also used : Storage(org.kie.kogito.persistence.api.Storage) MatchedExecutionHeaders(org.kie.kogito.trusty.service.common.models.MatchedExecutionHeaders) Query(org.kie.kogito.persistence.api.query.Query) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Decision(org.kie.kogito.trusty.storage.api.model.decision.Decision) Test(org.junit.jupiter.api.Test)

Example 4 with Storage

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));
}
Also used : 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) Test(org.junit.jupiter.api.Test)

Example 5 with Storage

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));
}
Also used : Storage(org.kie.kogito.persistence.api.Storage) Decision(org.kie.kogito.trusty.storage.api.model.decision.Decision) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)10 Storage (org.kie.kogito.persistence.api.Storage)10 Decision (org.kie.kogito.trusty.storage.api.model.decision.Decision)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Query (org.kie.kogito.persistence.api.query.Query)4 MatchedExecutionHeaders (org.kie.kogito.trusty.service.common.models.MatchedExecutionHeaders)4 DMNModelMetadata (org.kie.kogito.trusty.storage.api.model.decision.DMNModelMetadata)4 DMNModelWithMetadata (org.kie.kogito.trusty.storage.api.model.decision.DMNModelWithMetadata)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 StorageImplMock (org.kie.kogito.trusty.service.common.mocks.StorageImplMock)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IntNode (com.fasterxml.jackson.databind.node.IntNode)1 TextNode (com.fasterxml.jackson.databind.node.TextNode)1 OffsetDateTime (java.time.OffsetDateTime)1 Collections (java.util.Collections)1 Map (java.util.Map)1 UUID (java.util.UUID)1