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());
}
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));
}
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);
}
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());
}
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());
}
Aggregations