Search in sources :

Example 6 with IncludedModel

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());
}
Also used : Package(org.guvnor.common.services.project.model.Package) PMMLIncludedModel(org.kie.workbench.common.dmn.api.editors.included.PMMLIncludedModel) DMNIncludedModel(org.kie.workbench.common.dmn.api.editors.included.DMNIncludedModel) IncludedModel(org.kie.workbench.common.dmn.api.editors.included.IncludedModel) DMNIncludedModel(org.kie.workbench.common.dmn.api.editors.included.DMNIncludedModel) Test(org.junit.Test)

Example 7 with IncludedModel

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());
}
Also used : DMNIncludedNode(org.kie.workbench.common.dmn.api.editors.included.DMNIncludedNode) IncludedModel(org.kie.workbench.common.dmn.api.editors.included.IncludedModel) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) Test(org.junit.Test)

Example 8 with IncludedModel

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);
}
Also used : HasVariable(org.kie.workbench.common.dmn.api.definition.HasVariable) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) IsInformationItem(org.kie.workbench.common.dmn.api.definition.model.IsInformationItem) IncludedModel(org.kie.workbench.common.dmn.api.editors.included.IncludedModel) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Test(org.junit.Test)

Example 9 with IncludedModel

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);
}
Also used : GwtMockitoTestRunner(com.google.gwtmockito.GwtMockitoTestRunner) Mock(org.mockito.Mock) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) IncludedModelsIndex(org.kie.workbench.common.dmn.client.editors.included.imports.IncludedModelsIndex) RunWith(org.junit.runner.RunWith) Mockito.spy(org.mockito.Mockito.spy) PMML(org.kie.workbench.common.dmn.api.editors.included.DMNImportTypes.PMML) Import(org.kie.workbench.common.dmn.api.definition.model.Import) ITEM_DEFINITION_COUNT_METADATA(org.kie.workbench.common.dmn.client.editors.included.modal.dropdown.DMNAssetsDropdownItemsProvider.ITEM_DEFINITION_COUNT_METADATA) IMPORT_TYPE_METADATA(org.kie.workbench.common.dmn.client.editors.included.modal.dropdown.DMNAssetsDropdownItemsProvider.IMPORT_TYPE_METADATA) Arrays.asList(java.util.Arrays.asList) PATH_METADATA(org.kie.workbench.common.dmn.client.editors.included.modal.dropdown.DMNAssetsDropdownItemsProvider.PATH_METADATA) DMN(org.kie.workbench.common.dmn.api.editors.included.DMNImportTypes.DMN) SessionManager(org.kie.workbench.common.stunner.core.client.api.SessionManager) Mockito.doReturn(org.mockito.Mockito.doReturn) Path(org.uberfire.backend.vfs.Path) Before(org.junit.Before) PMMLIncludedModel(org.kie.workbench.common.dmn.api.editors.included.PMMLIncludedModel) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) LocationURI(org.kie.workbench.common.dmn.api.property.dmn.LocationURI) DMNIncludeModelsClient(org.kie.workbench.common.dmn.client.api.included.legacy.DMNIncludeModelsClient) KieAssetsDropdownItem(org.kie.workbench.common.widgets.client.assets.dropdown.KieAssetsDropdownItem) DRG_ELEMENT_COUNT_METADATA(org.kie.workbench.common.dmn.client.editors.included.modal.dropdown.DMNAssetsDropdownItemsProvider.DRG_ELEMENT_COUNT_METADATA) Mockito.verify(org.mockito.Mockito.verify) Consumer(java.util.function.Consumer) PMML_MODEL_COUNT_METADATA(org.kie.workbench.common.dmn.client.editors.included.modal.dropdown.DMNAssetsDropdownItemsProvider.PMML_MODEL_COUNT_METADATA) List(java.util.List) IncludedModelsPageState(org.kie.workbench.common.dmn.client.editors.included.IncludedModelsPageState) DMNIncludedModel(org.kie.workbench.common.dmn.api.editors.included.DMNIncludedModel) IncludedModel(org.kie.workbench.common.dmn.api.editors.included.IncludedModel) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) Import(org.kie.workbench.common.dmn.api.definition.model.Import) Arrays.asList(java.util.Arrays.asList) List(java.util.List) PMMLIncludedModel(org.kie.workbench.common.dmn.api.editors.included.PMMLIncludedModel) DMNIncludedModel(org.kie.workbench.common.dmn.api.editors.included.DMNIncludedModel) IncludedModel(org.kie.workbench.common.dmn.api.editors.included.IncludedModel) KieAssetsDropdownItem(org.kie.workbench.common.widgets.client.assets.dropdown.KieAssetsDropdownItem) Test(org.junit.Test)

Example 10 with IncludedModel

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);
}
Also used : GwtMockitoTestRunner(com.google.gwtmockito.GwtMockitoTestRunner) Mock(org.mockito.Mock) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) IncludedModelsIndex(org.kie.workbench.common.dmn.client.editors.included.imports.IncludedModelsIndex) RunWith(org.junit.runner.RunWith) Mockito.spy(org.mockito.Mockito.spy) PMML(org.kie.workbench.common.dmn.api.editors.included.DMNImportTypes.PMML) Import(org.kie.workbench.common.dmn.api.definition.model.Import) ITEM_DEFINITION_COUNT_METADATA(org.kie.workbench.common.dmn.client.editors.included.modal.dropdown.DMNAssetsDropdownItemsProvider.ITEM_DEFINITION_COUNT_METADATA) IMPORT_TYPE_METADATA(org.kie.workbench.common.dmn.client.editors.included.modal.dropdown.DMNAssetsDropdownItemsProvider.IMPORT_TYPE_METADATA) Arrays.asList(java.util.Arrays.asList) PATH_METADATA(org.kie.workbench.common.dmn.client.editors.included.modal.dropdown.DMNAssetsDropdownItemsProvider.PATH_METADATA) DMN(org.kie.workbench.common.dmn.api.editors.included.DMNImportTypes.DMN) SessionManager(org.kie.workbench.common.stunner.core.client.api.SessionManager) Mockito.doReturn(org.mockito.Mockito.doReturn) Path(org.uberfire.backend.vfs.Path) Before(org.junit.Before) PMMLIncludedModel(org.kie.workbench.common.dmn.api.editors.included.PMMLIncludedModel) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) LocationURI(org.kie.workbench.common.dmn.api.property.dmn.LocationURI) DMNIncludeModelsClient(org.kie.workbench.common.dmn.client.api.included.legacy.DMNIncludeModelsClient) KieAssetsDropdownItem(org.kie.workbench.common.widgets.client.assets.dropdown.KieAssetsDropdownItem) DRG_ELEMENT_COUNT_METADATA(org.kie.workbench.common.dmn.client.editors.included.modal.dropdown.DMNAssetsDropdownItemsProvider.DRG_ELEMENT_COUNT_METADATA) Mockito.verify(org.mockito.Mockito.verify) Consumer(java.util.function.Consumer) PMML_MODEL_COUNT_METADATA(org.kie.workbench.common.dmn.client.editors.included.modal.dropdown.DMNAssetsDropdownItemsProvider.PMML_MODEL_COUNT_METADATA) List(java.util.List) IncludedModelsPageState(org.kie.workbench.common.dmn.client.editors.included.IncludedModelsPageState) DMNIncludedModel(org.kie.workbench.common.dmn.api.editors.included.DMNIncludedModel) IncludedModel(org.kie.workbench.common.dmn.api.editors.included.IncludedModel) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) LocationURI(org.kie.workbench.common.dmn.api.property.dmn.LocationURI) Import(org.kie.workbench.common.dmn.api.definition.model.Import) Arrays.asList(java.util.Arrays.asList) List(java.util.List) PMMLIncludedModel(org.kie.workbench.common.dmn.api.editors.included.PMMLIncludedModel) DMNIncludedModel(org.kie.workbench.common.dmn.api.editors.included.DMNIncludedModel) IncludedModel(org.kie.workbench.common.dmn.api.editors.included.IncludedModel) KieAssetsDropdownItem(org.kie.workbench.common.widgets.client.assets.dropdown.KieAssetsDropdownItem) Test(org.junit.Test)

Aggregations

IncludedModel (org.kie.workbench.common.dmn.api.editors.included.IncludedModel)10 Test (org.junit.Test)9 DMNIncludedModel (org.kie.workbench.common.dmn.api.editors.included.DMNIncludedModel)7 PMMLIncludedModel (org.kie.workbench.common.dmn.api.editors.included.PMMLIncludedModel)7 Path (org.uberfire.backend.vfs.Path)5 DRGElement (org.kie.workbench.common.dmn.api.definition.model.DRGElement)4 List (java.util.List)3 DMNIncludedNode (org.kie.workbench.common.dmn.api.editors.included.DMNIncludedNode)3 GwtMockitoTestRunner (com.google.gwtmockito.GwtMockitoTestRunner)2 Arrays.asList (java.util.Arrays.asList)2 Consumer (java.util.function.Consumer)2 Package (org.guvnor.common.services.project.model.Package)2 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Before (org.junit.Before)2 RunWith (org.junit.runner.RunWith)2 Import (org.kie.workbench.common.dmn.api.definition.model.Import)2 DMN (org.kie.workbench.common.dmn.api.editors.included.DMNImportTypes.DMN)2 PMML (org.kie.workbench.common.dmn.api.editors.included.DMNImportTypes.PMML)2 PMMLDocumentMetadata (org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata)2