Search in sources :

Example 1 with DMNModelMetadata

use of org.kie.kogito.trusty.storage.api.model.decision.DMNModelMetadata in project kogito-apps by kiegroup.

the class DMNModelMetadataIdentifierTest method isBlank_ShouldReturnTrueForNullOrBlankStrings.

@ParameterizedTest
@MethodSource("provideParametersForModelIdCreator")
void isBlank_ShouldReturnTrueForNullOrBlankStrings(final String groupId, final String artifactId, final String version, final String name, final String namespace, final String expected) {
    DMNModelMetadata modelIdentifier = new DMNModelMetadata(groupId, artifactId, version, "dmnVersion", name, namespace);
    assertEquals(expected, modelIdentifier.getIdentifier());
}
Also used : DMNModelMetadata(org.kie.kogito.trusty.storage.api.model.decision.DMNModelMetadata) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 2 with DMNModelMetadata

use of org.kie.kogito.trusty.storage.api.model.decision.DMNModelMetadata 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 3 with DMNModelMetadata

use of org.kie.kogito.trusty.storage.api.model.decision.DMNModelMetadata 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 4 with DMNModelMetadata

use of org.kie.kogito.trusty.storage.api.model.decision.DMNModelMetadata in project kogito-apps by kiegroup.

the class TrustyServiceTest method givenAModelWhenStoreModelIsCalledMoreThanOnceForSameModelThenExceptionIsThrown.

@Test
@SuppressWarnings("unchecked")
void givenAModelWhenStoreModelIsCalledMoreThanOnceForSameModelThenExceptionIsThrown() {
    String model = TEST_MODEL;
    Storage storageMock = mock(Storage.class);
    DMNModelWithMetadata dmnModelWithMetadata = buildDmnModel(model);
    DMNModelMetadata modelIdentifier = dmnModelWithMetadata.getModelMetaData();
    when(storageMock.containsKey(modelIdentifier.getIdentifier())).thenReturn(true);
    when(storageMock.put(any(Object.class), any(Object.class))).thenReturn(model);
    when(trustyStorageServiceMock.getModelStorage(DMNModelWithMetadata.class)).thenReturn(storageMock);
    assertThrows(IllegalArgumentException.class, () -> trustyService.storeModel(dmnModelWithMetadata));
}
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) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 5 with DMNModelMetadata

use of org.kie.kogito.trusty.storage.api.model.decision.DMNModelMetadata in project kogito-apps by kiegroup.

the class ModelEventConsumer method internalHandleDecisionModelEvent.

private void internalHandleDecisionModelEvent(DecisionModelEvent decisionModelEvent) {
    DMNModelMetadata identifier = new DMNModelMetadata(decisionModelEvent.getGav().getGroupId(), decisionModelEvent.getGav().getArtifactId(), decisionModelEvent.getGav().getVersion(), decisionModelEvent.getModelMetadata().getSpecVersion(), decisionModelEvent.getName(), decisionModelEvent.getNamespace());
    DMNModelWithMetadata dmnModelWithMetadata = new DMNModelWithMetadata(identifier, decisionModelEvent.getDefinition());
    service.storeModel(dmnModelWithMetadata);
}
Also used : DMNModelWithMetadata(org.kie.kogito.trusty.storage.api.model.decision.DMNModelWithMetadata) DMNModelMetadata(org.kie.kogito.trusty.storage.api.model.decision.DMNModelMetadata)

Aggregations

DMNModelMetadata (org.kie.kogito.trusty.storage.api.model.decision.DMNModelMetadata)5 DMNModelWithMetadata (org.kie.kogito.trusty.storage.api.model.decision.DMNModelWithMetadata)4 Test (org.junit.jupiter.api.Test)3 Storage (org.kie.kogito.persistence.api.Storage)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1 StorageImplMock (org.kie.kogito.trusty.service.common.mocks.StorageImplMock)1