Search in sources :

Example 6 with Definitions

use of org.kie.dmn.model.api.Definitions in project kie-wb-common by kiegroup.

the class DMNMarshallerImportsHelperStandaloneImplTest method testGetItemDefinitionsWithNamespace.

@Test
public void testGetItemDefinitionsWithNamespace() {
    final Definitions definitions = mock(Definitions.class);
    final Import anImport = mock(Import.class);
    final ItemDefinition itemDefinition1 = new TItemDefinition();
    final ItemDefinition itemDefinition2 = new TItemDefinition();
    final ItemDefinition itemDefinition3 = new TItemDefinition();
    final ItemDefinition itemDefinition4 = new TItemDefinition();
    final ItemDefinition itemDefinition5 = new TItemDefinition();
    final List<ItemDefinition> itemDefinitions = asList(itemDefinition1, itemDefinition2, itemDefinition3, itemDefinition4, itemDefinition5);
    itemDefinition1.setName("tUUID");
    itemDefinition2.setName("tPerson");
    itemDefinition3.setName("id");
    itemDefinition4.setName("name");
    itemDefinition5.setName("age");
    itemDefinition1.setTypeRef(new QName("string"));
    itemDefinition2.setTypeRef(null);
    itemDefinition3.setTypeRef(new QName("tUUID"));
    itemDefinition4.setTypeRef(new QName("string"));
    itemDefinition5.setTypeRef(new QName("number"));
    when(anImport.getName()).thenReturn("model");
    when(definitions.getItemDefinition()).thenReturn(itemDefinitions);
    final List<ItemDefinition> actualItemDefinitions = helper.getItemDefinitionsWithNamespace(definitions, anImport);
    assertEquals(5, actualItemDefinitions.size());
    final ItemDefinition actualItemDefinition1 = actualItemDefinitions.get(0);
    assertEquals("model.tUUID", actualItemDefinition1.getName());
    assertEquals("string", actualItemDefinition1.getTypeRef().getLocalPart());
    final ItemDefinition actualItemDefinition2 = actualItemDefinitions.get(1);
    assertEquals("model.tPerson", actualItemDefinition2.getName());
    assertNull(actualItemDefinition2.getTypeRef());
    final ItemDefinition actualItemDefinition3 = actualItemDefinitions.get(2);
    assertEquals("model.id", actualItemDefinition3.getName());
    assertEquals("model.tUUID", actualItemDefinition3.getTypeRef().getLocalPart());
    final ItemDefinition actualItemDefinition4 = actualItemDefinitions.get(3);
    assertEquals("model.name", actualItemDefinition4.getName());
    assertEquals("string", actualItemDefinition4.getTypeRef().getLocalPart());
    final ItemDefinition actualItemDefinition5 = actualItemDefinitions.get(4);
    assertEquals("model.age", actualItemDefinition5.getName());
    assertEquals("number", actualItemDefinition5.getTypeRef().getLocalPart());
}
Also used : Import(org.kie.dmn.model.api.Import) QName(javax.xml.namespace.QName) Definitions(org.kie.dmn.model.api.Definitions) TItemDefinition(org.kie.dmn.model.v1_2.TItemDefinition) TItemDefinition(org.kie.dmn.model.v1_2.TItemDefinition) ItemDefinition(org.kie.dmn.model.api.ItemDefinition) Test(org.junit.Test)

Example 7 with Definitions

use of org.kie.dmn.model.api.Definitions in project kie-wb-common by kiegroup.

the class DMNMarshallerImportsHelperStandaloneImplTest method testGetImportXML.

@Test
public void testGetImportXML() throws java.io.IOException {
    final String xml1 = "<some xml/>";
    final String xml2 = "<some other xml/>";
    final Metadata metadata = mock(Metadata.class);
    final Import import1 = mock(Import.class);
    final Path path1 = makePath("../file1.dmn");
    final Path path2 = makePath("../file2.dmn");
    // Mock loading of XML files in Project
    final InputStream inputStream1 = mock(InputStream.class);
    final InputStream inputStream2 = mock(InputStream.class);
    final InputStreamReader inputStreamReader1 = mock(InputStreamReader.class);
    final InputStreamReader inputStreamReader2 = mock(InputStreamReader.class);
    final List<Path> paths = asList(path1, path2);
    when(pathsHelper.getDMNModelsPaths(any())).thenReturn(paths);
    when(dmnIOHelper.isAsString(inputStream1)).thenReturn(xml1);
    when(dmnIOHelper.isAsString(inputStream2)).thenReturn(xml2);
    doReturn(Optional.of(inputStream1)).when(helper).loadPath(path1);
    doReturn(Optional.of(inputStream2)).when(helper).loadPath(path2);
    doReturn(inputStreamReader1).when(helper).toInputStreamReader(inputStream1);
    doReturn(inputStreamReader2).when(helper).toInputStreamReader(inputStream2);
    // Mock retrieval of Definitions from XML files in Project
    final StringReader stringReader1 = mock(StringReader.class);
    final StringReader stringReader2 = mock(StringReader.class);
    final Definitions definitions1 = mock(Definitions.class);
    final Definitions definitions2 = mock(Definitions.class);
    doReturn(stringReader1).when(helper).toStringReader(xml1);
    doReturn(stringReader2).when(helper).toStringReader(xml2);
    when(marshaller.unmarshal(stringReader1)).thenReturn(definitions1);
    when(marshaller.unmarshal(stringReader2)).thenReturn(definitions2);
    when(import1.getNamespace()).thenReturn("://namespace1");
    when(definitions1.getNamespace()).thenReturn("://namespace1");
    when(definitions2.getNamespace()).thenReturn("://namespace2-not-imported");
    final List<Import> imports = Collections.singletonList(import1);
    final Map<Import, String> importXML = helper.getImportXML(metadata, imports);
    assertEquals(1, importXML.size());
    assertEquals(xml1, importXML.get(import1));
}
Also used : Path(org.uberfire.backend.vfs.Path) Import(org.kie.dmn.model.api.Import) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Definitions(org.kie.dmn.model.api.Definitions) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 8 with Definitions

use of org.kie.dmn.model.api.Definitions in project kie-wb-common by kiegroup.

the class ImportConverterTest method testWbFromDMNWhenGeneric.

@Test
public void testWbFromDMNWhenGeneric() {
    final org.kie.dmn.model.api.Import dmn = new TImport();
    dmn.setImportType("cheese");
    final Definitions definitions = mock(Definitions.class);
    final PMMLDocumentMetadata pmmlDocument = mock(PMMLDocumentMetadata.class);
    final org.kie.workbench.common.dmn.api.definition.model.Import anImport = ImportConverter.wbFromDMN(dmn, definitions, pmmlDocument);
    assertNotNull(anImport);
}
Also used : PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) Definitions(org.kie.dmn.model.api.Definitions) TImport(org.kie.dmn.model.v1_2.TImport) Test(org.junit.Test)

Example 9 with Definitions

use of org.kie.dmn.model.api.Definitions in project kie-wb-common by kiegroup.

the class ImportConverterTest method testWbFromDMNWhenDMNImport.

@Test
public void testWbFromDMNWhenDMNImport() {
    final org.kie.dmn.model.api.Import dmn = new TImport();
    dmn.setImportType(DMNImportTypes.DMN.getDefaultNamespace());
    final Definitions definitions = mock(Definitions.class);
    final PMMLDocumentMetadata pmmlDocument = mock(PMMLDocumentMetadata.class);
    final String key = "drools";
    final String value = "http://www.drools.org/kie/dmn/1.1";
    dmn.getNsContext().put(key, value);
    when(definitions.getDrgElement()).thenReturn(asList(mock(DRGElement.class), mock(DRGElement.class)));
    when(definitions.getItemDefinition()).thenReturn(asList(mock(ItemDefinition.class), mock(ItemDefinition.class), mock(ItemDefinition.class)));
    final org.kie.workbench.common.dmn.api.definition.model.Import anImport = ImportConverter.wbFromDMN(dmn, definitions, pmmlDocument);
    final Map<String, String> nsContext = anImport.getNsContext();
    assertEquals(1, nsContext.size());
    assertEquals(value, nsContext.get(key));
    assertTrue(anImport instanceof ImportDMN);
    final ImportDMN dmnImport = (ImportDMN) anImport;
    assertEquals(2, dmnImport.getDrgElementsCount());
    assertEquals(3, dmnImport.getItemDefinitionsCount());
}
Also used : ImportDMN(org.kie.workbench.common.dmn.api.definition.model.ImportDMN) PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) Definitions(org.kie.dmn.model.api.Definitions) TImport(org.kie.dmn.model.v1_2.TImport) Test(org.junit.Test)

Example 10 with Definitions

use of org.kie.dmn.model.api.Definitions in project kie-wb-common by kiegroup.

the class ImportConverterTest method testWbFromDMNWhenPMMLImport.

@Test
public void testWbFromDMNWhenPMMLImport() {
    final org.kie.dmn.model.api.Import dmn = new TImport();
    dmn.setImportType(DMNImportTypes.PMML.getDefaultNamespace());
    final Definitions definitions = mock(Definitions.class);
    final PMMLDocumentMetadata pmmlDocument = mock(PMMLDocumentMetadata.class);
    when(pmmlDocument.getModels()).thenReturn(asList(mock(PMMLModelMetadata.class), mock(PMMLModelMetadata.class)));
    final org.kie.workbench.common.dmn.api.definition.model.Import anImport = ImportConverter.wbFromDMN(dmn, definitions, pmmlDocument);
    assertTrue(anImport instanceof ImportPMML);
    final ImportPMML pmmlImport = (ImportPMML) anImport;
    assertEquals(2, pmmlImport.getModelCount());
}
Also used : PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) Definitions(org.kie.dmn.model.api.Definitions) TImport(org.kie.dmn.model.v1_2.TImport) ImportPMML(org.kie.workbench.common.dmn.api.definition.model.ImportPMML) Test(org.junit.Test)

Aggregations

Definitions (org.kie.dmn.model.api.Definitions)114 Test (org.junit.Test)71 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)39 DMNMessage (org.kie.dmn.api.core.DMNMessage)37 DMNModel (org.kie.dmn.api.core.DMNModel)34 DMNResult (org.kie.dmn.api.core.DMNResult)32 TDefinitions (org.kie.dmn.model.v1_1.TDefinitions)31 Arrays (java.util.Arrays)28 Assert.assertTrue (org.junit.Assert.assertTrue)28 List (java.util.List)26 ItemDefinition (org.kie.dmn.model.api.ItemDefinition)26 Logger (org.slf4j.Logger)26 LoggerFactory (org.slf4j.LoggerFactory)26 HashMap (java.util.HashMap)25 Decision (org.kie.dmn.model.api.Decision)25 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)24 Assert.assertFalse (org.junit.Assert.assertFalse)24 DecisionNodeImpl (org.kie.dmn.core.ast.DecisionNodeImpl)24 DMNModelImpl (org.kie.dmn.core.impl.DMNModelImpl)24 ArrayList (java.util.ArrayList)23