use of org.kie.workbench.common.dmn.api.editors.included.IncludedModel in project kie-wb-common by kiegroup.
the class IncludedModelFactoryTest method testCreateDMN.
@Test
public void testCreateDMN() throws Exception {
final Package aPackage = mock(Package.class);
final String packageName = "com.kie.dmn";
final String fileName = "file.dmn";
final String uri = "/src/main/java/com/kie/dmn/file.dmn";
final Integer expectedDrgElementsCount = 2;
final Integer expectedItemDefinitionsCount = 3;
when(aPackage.getPackageName()).thenReturn(packageName);
when(includedModelPath.getFileName()).thenReturn(fileName);
when(moduleService.resolvePackage(includedModelPath)).thenReturn(aPackage);
when(importTypesHelper.isDMN(includedModelPath)).thenReturn(true);
when(dmnDiagramHelper.getDiagramByPath(includedModelPath)).thenReturn(diagram);
when(dmnDiagramHelper.getNamespace(diagram)).thenReturn(NAMESPACE);
when(dmnDiagramHelper.getNodes(diagram)).thenReturn(asList(mock(DRGElement.class), mock(DRGElement.class)));
when(dmnDiagramHelper.getItemDefinitions(diagram)).thenReturn(asList(mock(ItemDefinition.class), mock(ItemDefinition.class), mock(ItemDefinition.class)));
when(pathsHelper.getRelativeURI(dmnModelPath, includedModelPath)).thenReturn(uri);
final IncludedModel includedModel = factory.create(dmnModelPath, includedModelPath);
assertTrue(includedModel instanceof DMNIncludedModel);
final DMNIncludedModel dmnIncludedModel = (DMNIncludedModel) includedModel;
assertEquals(packageName, includedModel.getModelPackage());
assertEquals(fileName, includedModel.getModelName());
assertEquals(uri, includedModel.getPath());
assertEquals(NAMESPACE, dmnIncludedModel.getNamespace());
assertEquals(expectedDrgElementsCount, dmnIncludedModel.getDrgElementsCount());
assertEquals(expectedItemDefinitionsCount, dmnIncludedModel.getItemDefinitionsCount());
}
use of org.kie.workbench.common.dmn.api.editors.included.IncludedModel in project kie-wb-common by kiegroup.
the class DMNIncludedNodeFactoryTest method testMakeDMNIncludedModel.
@Test
public void testMakeDMNIncludedModel() {
final DMNIncludedNodeFactory factory = mock(DMNIncludedNodeFactory.class);
final String path = "path";
final IncludedModel includedModel = mock(IncludedModel.class);
final DRGElement drgElement = mock(DRGElement.class);
final DRGElement elementWithNamespace = mock(DRGElement.class);
doCallRealMethod().when(factory).makeDMNIncludeNode(path, includedModel, drgElement);
when(factory.drgElementWithNamespace(drgElement, includedModel)).thenReturn(elementWithNamespace);
final DMNIncludedNode includedNode = factory.makeDMNIncludeNode(path, includedModel, drgElement);
verify(factory).drgElementWithNamespace(drgElement, includedModel);
assertEquals(path, includedNode.getFileName());
assertEquals(elementWithNamespace, includedNode.getDrgElement());
}
use of org.kie.workbench.common.dmn.api.editors.included.IncludedModel in project kie-wb-common by kiegroup.
the class DMNIncludedNodeFactoryTest method testDrgElementWithNamespace.
@Test
public void testDrgElementWithNamespace() {
final DRGElement drgElement = mock(DRGElement.class, withSettings().extraInterfaces(HasVariable.class));
final IncludedModel includedModel = mock(IncludedModel.class);
final DMNIncludedNodeFactory factory = mock(DMNIncludedNodeFactory.class);
final Id elementId = mock(Id.class);
final String theId = "theId";
final String theName = "theName";
final String tType = "tType";
final String namespaceUri = "namespaceUri";
final String prefix = "prefix";
final String modelName = "Model Name";
final Name elementName = mock(Name.class);
final IsInformationItem informationItem = mock(IsInformationItem.class);
final QName qName = mock(QName.class);
final Name createdName = mock(Name.class);
final QName typeRef = mock(QName.class);
when(includedModel.getModelName()).thenReturn(modelName);
when(elementId.getValue()).thenReturn(theId);
when(elementName.getValue()).thenReturn(theName);
when(drgElement.getName()).thenReturn(elementName);
when(drgElement.getId()).thenReturn(elementId);
when(((HasVariable) drgElement).getVariable()).thenReturn(informationItem);
when(qName.getLocalPart()).thenReturn(tType);
when(informationItem.getTypeRef()).thenReturn(qName);
when(qName.getPrefix()).thenReturn(prefix);
when(qName.getNamespaceURI()).thenReturn(namespaceUri);
when(factory.createName(drgElement, modelName)).thenReturn(createdName);
when(factory.createTypeRef(modelName, qName)).thenReturn(typeRef);
doCallRealMethod().when(factory).drgElementWithNamespace(drgElement, includedModel);
factory.drgElementWithNamespace(drgElement, includedModel);
verify(drgElement).setName(createdName);
verify(drgElement).setAllowOnlyVisualChange(true);
verify(factory).setVariable((HasVariable) drgElement, informationItem, typeRef);
}
use of org.kie.workbench.common.dmn.api.editors.included.IncludedModel in project kie-wb-common by kiegroup.
the class DMNAssetsDropdownItemsProviderTest method testWrapDMNItems.
@Test
public void testWrapDMNItems() {
final IncludedModel includedModel1 = makeDMNIncludedModel(1);
final IncludedModel includedModel2 = makeDMNIncludedModel(2);
final IncludedModel includedModel3 = makeDMNIncludedModel(3);
final IncludedModel includedModel4 = makeDMNIncludedModel(4);
final IncludedModel includedModel5 = makeDMNIncludedModel(5);
final Import import1 = mock(Import.class);
final Import import2 = mock(Import.class);
final KieAssetsDropdownItem dropdownItem1 = mock(KieAssetsDropdownItem.class);
final KieAssetsDropdownItem dropdownItem5 = mock(KieAssetsDropdownItem.class);
final List<IncludedModel> t = asList(includedModel1, includedModel2, includedModel3, includedModel4, includedModel5);
when(import1.getNamespace()).thenReturn("://namespace3");
when(import2.getNamespace()).thenReturn("://namespace4");
when(modelsIndex.getIndexedImports()).thenReturn(asList(import1, import2));
when(pageState.getCurrentDiagramNamespace()).thenReturn("://namespace2");
doReturn(dropdownItem1).when(itemsProvider).asKieAsset(includedModel1);
doReturn(dropdownItem5).when(itemsProvider).asKieAsset(includedModel5);
itemsProvider.wrap(actualList -> {
// IncludedModel3 and IncludedModel4 are already imported. IncludedModel2 is the current diagram so only expect 1 and 5.
final List<KieAssetsDropdownItem> expectedList = asList(dropdownItem1, dropdownItem5);
assertEquals(expectedList, actualList);
}).accept(t);
}
use of org.kie.workbench.common.dmn.api.editors.included.IncludedModel in project kie-wb-common by kiegroup.
the class DMNAssetsDropdownItemsProviderTest method testWrapPMMLItems.
@Test
public void testWrapPMMLItems() {
final IncludedModel includedModel1 = makePMMLIncludedModel(1);
final IncludedModel includedModel2 = makePMMLIncludedModel(2);
final IncludedModel includedModel3 = makePMMLIncludedModel(3);
final IncludedModel includedModel4 = makePMMLIncludedModel(4);
final IncludedModel includedModel5 = makePMMLIncludedModel(5);
final Import import1 = mock(Import.class);
final Import import2 = mock(Import.class);
final LocationURI import1URI = new LocationURI("/src/main/kie3");
final LocationURI import2URI = new LocationURI("/src/main/kie4");
final KieAssetsDropdownItem dropdownItem1 = mock(KieAssetsDropdownItem.class);
final KieAssetsDropdownItem dropdownItem2 = mock(KieAssetsDropdownItem.class);
final KieAssetsDropdownItem dropdownItem5 = mock(KieAssetsDropdownItem.class);
final List<IncludedModel> t = asList(includedModel1, includedModel2, includedModel3, includedModel4, includedModel5);
when(import1.getLocationURI()).thenReturn(import1URI);
when(import2.getLocationURI()).thenReturn(import2URI);
when(modelsIndex.getIndexedImports()).thenReturn(asList(import1, import2));
doReturn(dropdownItem1).when(itemsProvider).asKieAsset(includedModel1);
doReturn(dropdownItem2).when(itemsProvider).asKieAsset(includedModel2);
doReturn(dropdownItem5).when(itemsProvider).asKieAsset(includedModel5);
itemsProvider.wrap(actualList -> {
// IncludedModel3 and IncludedModel4 are already imported so only expect 1, 2 and 5.
final List<KieAssetsDropdownItem> expectedList = asList(dropdownItem1, dropdownItem2, dropdownItem5);
assertEquals(expectedList, actualList);
}).accept(t);
}
Aggregations