Search in sources :

Example 1 with DMNModelWithMetadata

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

the class ExecutionsApiV1IT method givenARequestWithExistingModelWhenModelEndpointIsCalledThenTheModelIsReturned.

@Test
void givenARequestWithExistingModelWhenModelEndpointIsCalledThenTheModelIsReturned() {
    DMNModelWithMetadata dmnModelWithMetadata = new DMNModelWithMetadata("groupId", "artifactId", "modelVersion", "dmnVersion", "name", "namespace", "definition");
    final Decision decision = mock(Decision.class);
    when(decision.getExecutedModelName()).thenReturn("name");
    when(decision.getExecutedModelNamespace()).thenReturn("namespace");
    when(executionService.getDecisionById(anyString())).thenReturn(decision);
    when(executionService.getModelById(any(DMNModelMetadata.class), eq(DMNModelWithMetadata.class))).thenReturn(dmnModelWithMetadata);
    DMNModelWithMetadata response = given().contentType(ContentType.TEXT).when().get("/executions/123/model").as(DMNModelWithMetadata.class);
    assertEquals(dmnModelWithMetadata.getModel(), response.getModel());
    assertEquals(dmnModelWithMetadata.getGroupId(), response.getGroupId());
    assertEquals(dmnModelWithMetadata.getNamespace(), response.getNamespace());
    assertEquals(dmnModelWithMetadata.getName(), response.getName());
    assertEquals(dmnModelWithMetadata.getArtifactId(), response.getArtifactId());
}
Also used : DMNModelWithMetadata(org.kie.kogito.trusty.storage.api.model.decision.DMNModelWithMetadata) DMNModelMetadata(org.kie.kogito.trusty.storage.api.model.decision.DMNModelMetadata) Decision(org.kie.kogito.trusty.storage.api.model.decision.Decision) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 2 with DMNModelWithMetadata

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

the class AbstractModelEventConsumerIT method testCorrectCloudEvent.

@Test
void testCorrectCloudEvent() {
    kafkaClient.produce(TrustyServiceTestUtils.buildCloudEventJsonString(TrustyServiceTestUtils.buildCorrectModelEvent()), KafkaConstants.KOGITO_TRACING_MODEL_TOPIC);
    await().atMost(5, SECONDS).untilAsserted(() -> assertDoesNotThrow(() -> trustyService.getModelById(TrustyServiceTestUtils.getModelIdentifier(), DMNModelWithMetadata.class)));
    DMNModelWithMetadata storedDefinition = trustyService.getModelById(TrustyServiceTestUtils.getModelIdentifier(), DMNModelWithMetadata.class);
    assertNotNull(storedDefinition);
    assertEquals("definition", storedDefinition.getModel());
    assertEquals("name", storedDefinition.getName());
    assertEquals("namespace", storedDefinition.getNamespace());
}
Also used : DMNModelWithMetadata(org.kie.kogito.trusty.storage.api.model.decision.DMNModelWithMetadata) Test(org.junit.jupiter.api.Test)

Example 3 with DMNModelWithMetadata

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

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

the class AbstractTrustyServiceIT method givenAModelWhenGetModelByIdIsCalledThenTheModelIsReturned.

@Test
public void givenAModelWhenGetModelByIdIsCalledThenTheModelIsReturned() {
    String model = "definition";
    storeModel(model);
    DMNModelWithMetadata result = getModel();
    Assertions.assertEquals(model, result.getModel());
}
Also used : DMNModelWithMetadata(org.kie.kogito.trusty.storage.api.model.decision.DMNModelWithMetadata) Test(org.junit.jupiter.api.Test)

Example 5 with DMNModelWithMetadata

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

the class DMNModelWithMetadataMarshallerTest method testWriteAndRead.

@Test
public void testWriteAndRead() throws IOException {
    DMNModelWithMetadata dmnModelWithMetadata = new DMNModelWithMetadata("groupId", "artifactId", "version", "dmnVersion", "name", "namespace", "XML_MODEL");
    DMNModelWithMetadataMarshaller marshaller = new DMNModelWithMetadataMarshaller(new ObjectMapper());
    marshaller.writeTo(writer, dmnModelWithMetadata);
    DMNModelWithMetadata retrieved = marshaller.readFrom(reader);
    Assertions.assertEquals(dmnModelWithMetadata.getGroupId(), retrieved.getGroupId());
    Assertions.assertEquals(dmnModelWithMetadata.getArtifactId(), retrieved.getArtifactId());
    Assertions.assertEquals(dmnModelWithMetadata.getModelVersion(), retrieved.getModelVersion());
    Assertions.assertEquals(dmnModelWithMetadata.getDmnVersion(), retrieved.getDmnVersion());
    Assertions.assertEquals(dmnModelWithMetadata.getModelMetaData().getName(), retrieved.getName());
    Assertions.assertEquals(dmnModelWithMetadata.getModelMetaData().getNamespace(), retrieved.getNamespace());
    Assertions.assertEquals(dmnModelWithMetadata.getModel(), retrieved.getModel());
}
Also used : DMNModelWithMetadata(org.kie.kogito.trusty.storage.api.model.decision.DMNModelWithMetadata) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Aggregations

DMNModelWithMetadata (org.kie.kogito.trusty.storage.api.model.decision.DMNModelWithMetadata)8 Test (org.junit.jupiter.api.Test)6 DMNModelMetadata (org.kie.kogito.trusty.storage.api.model.decision.DMNModelMetadata)4 Storage (org.kie.kogito.persistence.api.Storage)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 QuarkusTest (io.quarkus.test.junit.QuarkusTest)1 StorageImplMock (org.kie.kogito.trusty.service.common.mocks.StorageImplMock)1 Decision (org.kie.kogito.trusty.storage.api.model.decision.Decision)1