Search in sources :

Example 11 with ImportDMN

use of org.kie.workbench.common.dmn.api.definition.model.ImportDMN in project kie-wb-common by kiegroup.

the class DecisionComponentsTest method testGetDMNIncludedModelsOnlyIncludesDMN.

@Test
public void testGetDMNIncludedModelsOnlyIncludesDMN() {
    final ImportDMN dmnImport = new ImportDMN();
    final ImportPMML pmmlImport = new ImportPMML();
    dmnImport.getName().setValue("dmn");
    dmnImport.setImportType(DMNImportTypes.DMN.getDefaultNamespace());
    pmmlImport.setImportType(DMNImportTypes.PMML.getDefaultNamespace());
    when(dmnDiagramsSession.getModelImports()).thenReturn(asList(dmnImport, pmmlImport));
    final List<DMNIncludedModel> includedModels = decisionComponents.getDMNIncludedModels();
    assertThat(includedModels).hasSize(1);
    assertThat(includedModels.get(0).getModelName()).isEqualTo("dmn");
    assertThat(includedModels.get(0).getImportType()).isEqualTo(DMNImportTypes.DMN.getDefaultNamespace());
}
Also used : ImportDMN(org.kie.workbench.common.dmn.api.definition.model.ImportDMN) ImportPMML(org.kie.workbench.common.dmn.api.definition.model.ImportPMML) DMNIncludedModel(org.kie.workbench.common.dmn.api.editors.included.DMNIncludedModel) Test(org.junit.Test)

Example 12 with ImportDMN

use of org.kie.workbench.common.dmn.api.definition.model.ImportDMN in project kie-wb-common by kiegroup.

the class ImportConverterTest method wbFromDMN_DMNImportNoDefinition.

@Test
public void wbFromDMN_DMNImportNoDefinition() {
    when(jsitImportMock.getImportType()).thenReturn(DMN_IMPORT_TYPE);
    when(jsitDefinitionsMock.getDrgElement()).thenReturn(new ArrayList<>(Arrays.asList(mock(JSITDRGElement.class), mock(JSITDRGElement.class))));
    when(jsitDefinitionsMock.getItemDefinition()).thenReturn(new ArrayList<>(Arrays.asList(mock(JSITItemDefinition.class))));
    Import resultImport = ImportConverter.wbFromDMN(jsitImportMock, null, null);
    assertTrue(resultImport instanceof ImportDMN);
    assertEquals(NAMESPACE, resultImport.getNamespace());
    assertEquals(LOCATION_URI, resultImport.getLocationURI().getValue());
    assertEquals(DESCRIPTION, resultImport.getDescription().getValue());
    assertEquals(NAME, resultImport.getName().getValue());
    assertEquals(DMN_IMPORT_TYPE, resultImport.getImportType());
    assertEquals(0, ((ImportDMN) resultImport).getDrgElementsCount());
    assertEquals(0, ((ImportDMN) resultImport).getItemDefinitionsCount());
}
Also used : JSITDRGElement(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDRGElement) Import(org.kie.workbench.common.dmn.api.definition.model.Import) JSITImport(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport) ImportDMN(org.kie.workbench.common.dmn.api.definition.model.ImportDMN) JSITItemDefinition(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITItemDefinition) Test(org.junit.Test)

Example 13 with ImportDMN

use of org.kie.workbench.common.dmn.api.definition.model.ImportDMN in project kie-wb-common by kiegroup.

the class IncludedModelsFactoryTest method testMakeIncludedDMNModels.

@Test
public void testMakeIncludedDMNModels() {
    final ImportDMN import1 = mock(ImportDMN.class);
    final ImportDMN import2 = mock(ImportDMN.class);
    final Name nameMock1 = mock(Name.class);
    final Name nameMock2 = mock(Name.class);
    final List<Import> imports = asList(import1, import2);
    final String name1 = "name1";
    final String name2 = "name2";
    final String path1 = "path1";
    final String path2 = "path2";
    final String uuid1 = "123";
    final String uuid2 = "456";
    final String[] uuids = { uuid1, uuid2 };
    final String uri1 = "/src/main/kie/dmn/1";
    final String uri2 = "/src/main/kie/dmn/2";
    final Integer drgElementsCount1 = 2;
    final Integer drgElementsCount2 = 8;
    final Integer itemDefinitionsCount1 = 4;
    final Integer itemDefinitionsCount2 = 16;
    when(nameMock1.getValue()).thenReturn(name1);
    when(nameMock2.getValue()).thenReturn(name2);
    when(import1.getName()).thenReturn(nameMock1);
    when(import2.getName()).thenReturn(nameMock2);
    when(import1.getNamespace()).thenReturn(path1);
    when(import2.getNamespace()).thenReturn(path2);
    when(import1.getImportType()).thenReturn(DMNImportTypes.DMN.getDefaultNamespace());
    when(import2.getImportType()).thenReturn(DMNImportTypes.DMN.getDefaultNamespace());
    when(import1.getLocationURI()).thenReturn(new LocationURI(uri1));
    when(import2.getLocationURI()).thenReturn(new LocationURI(uri2));
    when(import1.getDrgElementsCount()).thenReturn(drgElementsCount1);
    when(import2.getDrgElementsCount()).thenReturn(drgElementsCount2);
    when(import1.getItemDefinitionsCount()).thenReturn(itemDefinitionsCount1);
    when(import2.getItemDefinitionsCount()).thenReturn(itemDefinitionsCount2);
    doAnswer(new Answer() {

        private int count = 0;

        public Object answer(InvocationOnMock invocation) {
            return uuids[count++];
        }
    }).when(factory).uuidWrapper();
    final List<BaseIncludedModelActiveRecord> includedModels = factory.makeIncludedModels(imports);
    final BaseIncludedModelActiveRecord includedModel1 = includedModels.get(0);
    final BaseIncludedModelActiveRecord includedModel2 = includedModels.get(1);
    verify(includedModelsIndex).clear();
    verify(includedModelsIndex).index(includedModel1, import1);
    verify(includedModelsIndex).index(includedModel2, import2);
    assertEquals(2, includedModels.size());
    assertEquals(uuid1, includedModel1.getUUID());
    assertEquals(uuid2, includedModel2.getUUID());
    assertEquals(name1, includedModel1.getName());
    assertEquals(name2, includedModel2.getName());
    assertEquals(path1, includedModel1.getNamespace());
    assertEquals(path2, includedModel2.getNamespace());
    assertEquals(uri1, includedModel1.getPath());
    assertEquals(uri2, includedModel2.getPath());
    assertTrue(includedModel1 instanceof DMNIncludedModelActiveRecord);
    assertTrue(includedModel2 instanceof DMNIncludedModelActiveRecord);
    assertEquals(itemDefinitionsCount1, ((DMNIncludedModelActiveRecord) includedModel1).getDataTypesCount());
    assertEquals(itemDefinitionsCount2, ((DMNIncludedModelActiveRecord) includedModel2).getDataTypesCount());
    assertEquals(drgElementsCount1, ((DMNIncludedModelActiveRecord) includedModel1).getDrgElementsCount());
    assertEquals(drgElementsCount2, ((DMNIncludedModelActiveRecord) includedModel2).getDrgElementsCount());
    assertEquals(recordEngine, includedModel1.getRecordEngine());
    assertEquals(recordEngine, includedModel2.getRecordEngine());
}
Also used : LocationURI(org.kie.workbench.common.dmn.api.property.dmn.LocationURI) ImportDMN(org.kie.workbench.common.dmn.api.definition.model.ImportDMN) Import(org.kie.workbench.common.dmn.api.definition.model.Import) BaseIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DMNIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.DMNIncludedModelActiveRecord) Test(org.junit.Test)

Aggregations

ImportDMN (org.kie.workbench.common.dmn.api.definition.model.ImportDMN)13 Test (org.junit.Test)8 Import (org.kie.workbench.common.dmn.api.definition.model.Import)8 ImportPMML (org.kie.workbench.common.dmn.api.definition.model.ImportPMML)7 LocationURI (org.kie.workbench.common.dmn.api.property.dmn.LocationURI)5 PMMLDocumentMetadata (org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata)4 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)4 DMNIncludedModelActiveRecord (org.kie.workbench.common.dmn.client.editors.included.DMNIncludedModelActiveRecord)4 JSITImport (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 Function (java.util.function.Function)2 Definitions (org.kie.dmn.model.api.Definitions)2 Import (org.kie.dmn.model.api.Import)2 TImport (org.kie.dmn.model.v1_2.TImport)2 DMNImportTypes (org.kie.workbench.common.dmn.api.editors.included.DMNImportTypes)2 DMNImportTypes.determineImportType (org.kie.workbench.common.dmn.api.editors.included.DMNImportTypes.determineImportType)2 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)2