Search in sources :

Example 21 with Import

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

the class IncludedModelsFactoryTest method testMakeIncludedPMMLModels.

@Test
public void testMakeIncludedPMMLModels() {
    final ImportPMML import1 = mock(ImportPMML.class);
    final ImportPMML import2 = mock(ImportPMML.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 modelCount1 = 2;
    final Integer modelCount2 = 8;
    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.PMML.getDefaultNamespace());
    when(import2.getImportType()).thenReturn(DMNImportTypes.PMML.getDefaultNamespace());
    when(import1.getLocationURI()).thenReturn(new LocationURI(uri1));
    when(import2.getLocationURI()).thenReturn(new LocationURI(uri2));
    when(import1.getModelCount()).thenReturn(modelCount1);
    when(import2.getModelCount()).thenReturn(modelCount2);
    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 PMMLIncludedModelActiveRecord);
    assertTrue(includedModel2 instanceof PMMLIncludedModelActiveRecord);
    assertEquals(modelCount1, ((PMMLIncludedModelActiveRecord) includedModel1).getModelCount());
    assertEquals(modelCount2, ((PMMLIncludedModelActiveRecord) includedModel2).getModelCount());
    assertEquals(recordEngine, includedModel1.getRecordEngine());
    assertEquals(recordEngine, includedModel2.getRecordEngine());
}
Also used : LocationURI(org.kie.workbench.common.dmn.api.property.dmn.LocationURI) Import(org.kie.workbench.common.dmn.api.definition.model.Import) PMMLIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.PMMLIncludedModelActiveRecord) 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) ImportPMML(org.kie.workbench.common.dmn.api.definition.model.ImportPMML) Test(org.junit.Test)

Example 22 with Import

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

the class ImportConverterTest method wbFromDMN_PMMLImportNoModels.

@Test
public void wbFromDMN_PMMLImportNoModels() {
    when(jsitImportMock.getImportType()).thenReturn(PMML_IMPORT_TYPE);
    Import resultImport = ImportConverter.wbFromDMN(jsitImportMock, null, pmmlDocumentMetadata);
    assertTrue(resultImport instanceof ImportPMML);
    assertEquals(LOCATION_URI, resultImport.getLocationURI().getValue());
    assertEquals(NAME, resultImport.getNamespace());
    assertEquals(DESCRIPTION, resultImport.getDescription().getValue());
    assertEquals(NAME, resultImport.getName().getValue());
    assertEquals(PMML_IMPORT_TYPE, resultImport.getImportType());
    assertNotNull(resultImport.getId().getValue());
    assertEquals(0, ((ImportPMML) resultImport).getModelCount());
}
Also used : Import(org.kie.workbench.common.dmn.api.definition.model.Import) JSITImport(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport) ImportPMML(org.kie.workbench.common.dmn.api.definition.model.ImportPMML) Test(org.junit.Test)

Example 23 with Import

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

the class ImportConverterTest method wbFromDMN_DMNImport.

@Test
public void wbFromDMN_DMNImport() {
    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, jsitDefinitionsMock, 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(2, ((ImportDMN) resultImport).getDrgElementsCount());
    assertEquals(1, ((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 24 with Import

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

the class WrapperUtilsTest method testGetDmnElementRefWithNamespace.

@Test
public void testGetDmnElementRefWithNamespace() {
    final Decision drgElement = mock(Decision.class);
    final View<? extends DMNElement> view = new ViewImpl<>(drgElement, null);
    final Name drgElementName = mock(Name.class);
    final Name importName = mock(Name.class);
    final Id id = mock(Id.class);
    final org.kie.workbench.common.dmn.api.definition.model.Definitions definitions = mock(org.kie.workbench.common.dmn.api.definition.model.Definitions.class);
    final Import anImport = mock(Import.class);
    final List<Import> imports = singletonList(anImport);
    final String includedModelName = "includedModel";
    final String defaultNamespace = "://default";
    final String namespaceName = "include1";
    final String importNamespace = "://namespace";
    final Map<String, String> nsContext = new HashMap<>();
    when(importName.getValue()).thenReturn(includedModelName);
    when(anImport.getName()).thenReturn(importName);
    when(anImport.getNamespace()).thenReturn(importNamespace);
    when(id.getValue()).thenReturn("0000-1111-2222");
    when(drgElementName.getValue()).thenReturn(includedModelName + ".Decision");
    when(drgElement.getId()).thenReturn(id);
    when(drgElement.getName()).thenReturn(drgElementName);
    when(drgElement.getParent()).thenReturn(definitions);
    nsContext.put(namespaceName, importNamespace);
    when(definitions.getImport()).thenReturn(imports);
    when(definitions.getNsContext()).thenReturn(nsContext);
    final QName actual = getDmnElementRef(definitions, view, defaultNamespace);
    assertEquals(defaultNamespace, actual.getNamespaceURI());
    assertEquals("include1:0000-1111-2222", actual.getLocalPart());
    assertEquals("", actual.getPrefix());
}
Also used : Import(org.kie.workbench.common.dmn.api.definition.model.Import) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) QName(javax.xml.namespace.QName) ViewImpl(org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) Test(org.junit.Test)

Example 25 with Import

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

the class HrefBuilderTest method testGetHrefForImportedDRGElement.

@Test
public void testGetHrefForImportedDRGElement() {
    final DRGElement drgElement = mock(DRGElement.class);
    final Name drgElementName = mock(Name.class);
    final Name importName = mock(Name.class);
    final Id id = mock(Id.class);
    final Definitions definitions = mock(Definitions.class);
    final Import anImport = mock(Import.class);
    final List<Import> imports = singletonList(anImport);
    final String includedModelName = "includedModel";
    when(importName.getValue()).thenReturn(includedModelName);
    when(anImport.getName()).thenReturn(importName);
    when(anImport.getNamespace()).thenReturn("https://github.com/kiegroup/dmn/something");
    when(id.getValue()).thenReturn("0000-1111-2222");
    when(drgElementName.getValue()).thenReturn(includedModelName + ".Decision");
    when(drgElement.getId()).thenReturn(id);
    when(drgElement.getName()).thenReturn(drgElementName);
    when(drgElement.getParent()).thenReturn(definitions);
    when(definitions.getImport()).thenReturn(imports);
    final String actual = HrefBuilder.getHref(drgElement);
    final String expected = "https://github.com/kiegroup/dmn/something#0000-1111-2222";
    assertEquals(expected, actual);
}
Also used : Import(org.kie.workbench.common.dmn.api.definition.model.Import) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Test(org.junit.Test)

Aggregations

Import (org.kie.workbench.common.dmn.api.definition.model.Import)51 Test (org.junit.Test)37 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)26 Definitions (org.kie.workbench.common.dmn.api.definition.model.Definitions)14 ArrayList (java.util.ArrayList)11 BaseIncludedModelActiveRecord (org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord)11 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)10 LocationURI (org.kie.workbench.common.dmn.api.property.dmn.LocationURI)10 ImportPMML (org.kie.workbench.common.dmn.api.definition.model.ImportPMML)9 JSITImport (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport)9 HashMap (java.util.HashMap)8 DRGElement (org.kie.workbench.common.dmn.api.definition.model.DRGElement)8 ImportDMN (org.kie.workbench.common.dmn.api.definition.model.ImportDMN)8 JSITDefinitions (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions)7 JSITDRGElement (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDRGElement)6 DMNIncludedModelActiveRecord (org.kie.workbench.common.dmn.client.editors.included.DMNIncludedModelActiveRecord)5 PMMLDocumentMetadata (org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata)4 List (java.util.List)3 Map (java.util.Map)3 QName (javax.xml.namespace.QName)3