use of org.kie.workbench.common.dmn.api.definition.model.ImportDMN 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());
}
use of org.kie.workbench.common.dmn.api.definition.model.ImportDMN in project kie-wb-common by kiegroup.
the class DMNMarshallerStandaloneTest method checkImports.
@SuppressWarnings("unchecked")
private void checkImports(final Graph<?, Node<?, ?>> graph) {
assertNotNull(graph);
final DMNDiagramUtils utils = new DMNDiagramUtils();
final Diagram mockDiagram = mock(Diagram.class);
when(mockDiagram.getGraph()).thenReturn(graph);
final org.kie.workbench.common.dmn.api.definition.model.Definitions definitions = utils.getDefinitions(mockDiagram);
final List<org.kie.workbench.common.dmn.api.definition.model.Import> imports = definitions.getImport();
assertTrue(imports.get(0) instanceof ImportDMN);
assertTrue(imports.get(1) instanceof ImportPMML);
final ImportDMN dmnImport = (ImportDMN) imports.get(0);
assertEquals("dmn-import", dmnImport.getName().getValue());
assertEquals("https://kiegroup.org/dmn/_46EB0D0D-7241-4629-A38E-0377AA5B32D1", dmnImport.getNamespace());
assertEquals(DMNImportTypes.DMN.getDefaultNamespace(), dmnImport.getImportType());
final ImportPMML pmmlImport = (ImportPMML) imports.get(1);
assertEquals("pmml-import", pmmlImport.getName().getValue());
assertEquals("pmml-import", pmmlImport.getNamespace());
assertEquals(DMNImportTypes.PMML.getDefaultNamespace(), pmmlImport.getImportType());
}
use of org.kie.workbench.common.dmn.api.definition.model.ImportDMN in project kie-wb-common by kiegroup.
the class IncludedModelsFactory method makeIncludedModel.
private BaseIncludedModelActiveRecord makeIncludedModel(final Import anImport) {
BaseIncludedModelActiveRecord includedModel;
if (anImport instanceof ImportDMN) {
final DMNIncludedModelActiveRecord dmnIncludedModel = new DMNIncludedModelActiveRecord(getRecordEngine());
dmnIncludedModel.setDataTypesCount(getDataTypesCount((ImportDMN) anImport));
dmnIncludedModel.setDrgElementsCount(getDrgElementsCount((ImportDMN) anImport));
includedModel = dmnIncludedModel;
} else if (anImport instanceof ImportPMML) {
final PMMLIncludedModelActiveRecord pmmlIncludedModel = new PMMLIncludedModelActiveRecord(getRecordEngine());
pmmlIncludedModel.setModelCount(getPMMLModelCount((ImportPMML) anImport));
includedModel = pmmlIncludedModel;
} else {
includedModel = new DefaultIncludedModelActiveRecord(getRecordEngine());
}
includedModel.setUuid(uuidWrapper());
includedModel.setName(getName(anImport));
includedModel.setNamespace(getNamespace(anImport));
includedModel.setImportType(getImportType(anImport));
includedModel.setPath(getPath(anImport));
getIncludedModelsIndex().index(includedModel, anImport);
return includedModel;
}
use of org.kie.workbench.common.dmn.api.definition.model.ImportDMN in project kie-wb-common by kiegroup.
the class ImportFactory method makeImport.
public Import makeImport(final BaseIncludedModelActiveRecord record) {
Import anImport;
if (record instanceof DMNIncludedModelActiveRecord) {
final ImportDMN dmn = new ImportDMN();
final DMNIncludedModelActiveRecord dmnRecord = (DMNIncludedModelActiveRecord) record;
dmn.setName(name(record));
dmn.setNamespace(record.getNamespace());
dmn.setLocationURI(location(record));
dmn.setImportType(record.getImportType());
dmn.setDrgElementsCount(dmnRecord.getDrgElementsCount());
dmn.setItemDefinitionsCount(dmnRecord.getDataTypesCount());
anImport = dmn;
} else if (record instanceof PMMLIncludedModelActiveRecord) {
final ImportPMML pmml = new ImportPMML();
final PMMLIncludedModelActiveRecord pmmlRecord = (PMMLIncludedModelActiveRecord) record;
pmml.setName(name(record));
pmml.setNamespace(name(record).getValue());
pmml.setLocationURI(location(record));
pmml.setImportType(record.getImportType());
pmml.setModelCount(pmmlRecord.getModelCount());
anImport = pmml;
} else {
anImport = new Import();
}
anImport.setLocationURI(location(record));
anImport.setImportType(record.getImportType());
return anImport;
}
use of org.kie.workbench.common.dmn.api.definition.model.ImportDMN in project kie-wb-common by kiegroup.
the class DefinitionsConverterTest method wbFromDMN.
@Test
public void wbFromDMN() {
final Import anImport = new TImport();
anImport.setImportType(DMNImportTypes.DMN.getDefaultNamespace());
final org.kie.dmn.model.api.Definitions definitions = mock(org.kie.dmn.model.api.Definitions.class);
final Map<Import, org.kie.dmn.model.api.Definitions> importDefinitions = new Maps.Builder<Import, org.kie.dmn.model.api.Definitions>().put(anImport, definitions).build();
final Map<Import, PMMLDocumentMetadata> pmmlDocuments = new Maps.Builder<Import, PMMLDocumentMetadata>().build();
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)));
when(apiDefinitions.getImport()).thenReturn(singletonList(anImport));
final Definitions wb = DefinitionsConverter.wbFromDMN(apiDefinitions, importDefinitions, pmmlDocuments);
final String defaultNs = wb.getNsContext().get(DMNModelInstrumentedBase.Namespace.DEFAULT.getPrefix());
final String namespace = wb.getNamespace().getValue();
final List<org.kie.workbench.common.dmn.api.definition.model.Import> imports = wb.getImport();
assertEquals(defaultNs, namespace);
assertEquals(1, imports.size());
assertTrue(imports.get(0) instanceof ImportDMN);
final ImportDMN importDMN = (ImportDMN) imports.get(0);
assertEquals(2, importDMN.getDrgElementsCount());
assertEquals(3, importDMN.getItemDefinitionsCount());
}
Aggregations