use of org.kie.workbench.common.dmn.api.definition.model.ImportPMML 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());
}
use of org.kie.workbench.common.dmn.api.definition.model.ImportPMML 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());
}
use of org.kie.workbench.common.dmn.api.definition.model.ImportPMML 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.ImportPMML 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.ImportPMML 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;
}
Aggregations