use of org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord 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.client.editors.included.BaseIncludedModelActiveRecord in project kie-wb-common by kiegroup.
the class IncludedModelModal method createIncludedModel.
BaseIncludedModelActiveRecord createIncludedModel(final KieAssetsDropdownItem value) {
final Map<String, String> metaData = value.getMetaData();
final BaseIncludedModelActiveRecord includedModel = createIncludedModel(metaData);
includedModel.setName(NameUtils.normaliseName(getView().getModelNameInput()));
includedModel.setNamespace(value.getValue());
includedModel.setImportType(metaData.get(IMPORT_TYPE_METADATA));
includedModel.setPath(metaData.get(PATH_METADATA));
includedModel.create();
return includedModel;
}
use of org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord in project kie-wb-common by kiegroup.
the class IncludedModelModal method include.
public void include() {
getDropdown().getValue().ifPresent(value -> {
final BaseIncludedModelActiveRecord includedModel = createIncludedModel(value);
refreshGrid();
refreshDecisionComponents();
refreshDataTypesList(includedModel);
hide();
});
}
use of org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord 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.client.editors.included.BaseIncludedModelActiveRecord in project kie-wb-common by kiegroup.
the class IncludedModelModalTest method testIncludeDMN.
@Test
public void testIncludeDMN() {
final String path = "path";
final String name = "name";
final String namespace = "namespace";
final int drgElementCount = 2;
final int itemDefinitionCount = 3;
final KieAssetsDropdownItem dropdownItem = mock(KieAssetsDropdownItem.class);
when(view.getModelNameInput()).thenReturn(name);
when(dropdown.getValue()).thenReturn(Optional.of(dropdownItem));
when(dropdownItem.getValue()).thenReturn(namespace);
when(dropdownItem.getMetaData()).thenReturn(new Maps.Builder<String, String>().put(PATH_METADATA, path).put(IMPORT_TYPE_METADATA, DMNImportTypes.DMN.getDefaultNamespace()).put(DRG_ELEMENT_COUNT_METADATA, Integer.toString(drgElementCount)).put(ITEM_DEFINITION_COUNT_METADATA, Integer.toString(itemDefinitionCount)).build());
doNothing().when(modal).hide();
modal.include();
verify(modal).createIncludedModel(dropdownItem);
verify(grid).refresh();
verify(modal).hide();
verify(refreshDecisionComponentsEvent).fire(any(RefreshDecisionComponents.class));
verify(modal).refreshDataTypesList(includedModelActiveRecordArgumentCaptor.capture());
final BaseIncludedModelActiveRecord baseActiveRecord = includedModelActiveRecordArgumentCaptor.getValue();
assertTrue(baseActiveRecord instanceof DMNIncludedModelActiveRecord);
final DMNIncludedModelActiveRecord dmnActiveRecord = (DMNIncludedModelActiveRecord) baseActiveRecord;
assertEquals(path, dmnActiveRecord.getPath());
assertEquals(name, dmnActiveRecord.getName());
assertEquals(namespace, dmnActiveRecord.getNamespace());
assertEquals(drgElementCount, (int) dmnActiveRecord.getDrgElementsCount());
assertEquals(itemDefinitionCount, (int) dmnActiveRecord.getDataTypesCount());
}
Aggregations