Search in sources :

Example 6 with DMNIncludedModelActiveRecord

use of org.kie.workbench.common.dmn.client.editors.included.DMNIncludedModelActiveRecord 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());
}
Also used : RefreshDecisionComponents(org.kie.workbench.common.dmn.client.docks.navigator.events.RefreshDecisionComponents) BaseIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord) DMNIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.DMNIncludedModelActiveRecord) KieAssetsDropdownItem(org.kie.workbench.common.widgets.client.assets.dropdown.KieAssetsDropdownItem) Test(org.junit.Test)

Example 7 with DMNIncludedModelActiveRecord

use of org.kie.workbench.common.dmn.client.editors.included.DMNIncludedModelActiveRecord in project kie-wb-common by kiegroup.

the class IncludedModelsFactoryTest method testMakeIncludedDMNModels.

@Test
public void testMakeIncludedDMNModels() {
    final ImportDMN import1 = mock(ImportDMN.class);
    final ImportDMN import2 = mock(ImportDMN.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 drgElementsCount1 = 2;
    final Integer drgElementsCount2 = 8;
    final Integer itemDefinitionsCount1 = 4;
    final Integer itemDefinitionsCount2 = 16;
    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.DMN.getDefaultNamespace());
    when(import2.getImportType()).thenReturn(DMNImportTypes.DMN.getDefaultNamespace());
    when(import1.getLocationURI()).thenReturn(new LocationURI(uri1));
    when(import2.getLocationURI()).thenReturn(new LocationURI(uri2));
    when(import1.getDrgElementsCount()).thenReturn(drgElementsCount1);
    when(import2.getDrgElementsCount()).thenReturn(drgElementsCount2);
    when(import1.getItemDefinitionsCount()).thenReturn(itemDefinitionsCount1);
    when(import2.getItemDefinitionsCount()).thenReturn(itemDefinitionsCount2);
    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 DMNIncludedModelActiveRecord);
    assertTrue(includedModel2 instanceof DMNIncludedModelActiveRecord);
    assertEquals(itemDefinitionsCount1, ((DMNIncludedModelActiveRecord) includedModel1).getDataTypesCount());
    assertEquals(itemDefinitionsCount2, ((DMNIncludedModelActiveRecord) includedModel2).getDataTypesCount());
    assertEquals(drgElementsCount1, ((DMNIncludedModelActiveRecord) includedModel1).getDrgElementsCount());
    assertEquals(drgElementsCount2, ((DMNIncludedModelActiveRecord) includedModel2).getDrgElementsCount());
    assertEquals(recordEngine, includedModel1.getRecordEngine());
    assertEquals(recordEngine, includedModel2.getRecordEngine());
}
Also used : LocationURI(org.kie.workbench.common.dmn.api.property.dmn.LocationURI) ImportDMN(org.kie.workbench.common.dmn.api.definition.model.ImportDMN) Import(org.kie.workbench.common.dmn.api.definition.model.Import) BaseIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DMNIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.DMNIncludedModelActiveRecord) Test(org.junit.Test)

Example 8 with DMNIncludedModelActiveRecord

use of org.kie.workbench.common.dmn.client.editors.included.DMNIncludedModelActiveRecord in project kie-wb-common by kiegroup.

the class IncludedModelModalTest method doTestCreateIncludedModel.

@SuppressWarnings("unchecked")
private void doTestCreateIncludedModel(final String name, final String expectedName) {
    final String value = "://namespace";
    final String path = "/src/path/file";
    final String anPackage = "path.file.com";
    final Integer expectedDrgElementsCount = 2;
    final Integer expectedDataTypesCount = 3;
    final Map<String, String> metaData = new Maps.Builder<String, String>().put(PATH_METADATA, path).put(IMPORT_TYPE_METADATA, DMNImportTypes.DMN.getDefaultNamespace()).put(DRG_ELEMENT_COUNT_METADATA, expectedDrgElementsCount.toString()).put(ITEM_DEFINITION_COUNT_METADATA, expectedDataTypesCount.toString()).build();
    when(view.getModelNameInput()).thenReturn(name);
    final BaseIncludedModelActiveRecord includedModel = modal.createIncludedModel(new KieAssetsDropdownItem(name, anPackage, value, metaData));
    assertTrue(includedModel instanceof DMNIncludedModelActiveRecord);
    final DMNIncludedModelActiveRecord dmnIncludedModel = (DMNIncludedModelActiveRecord) includedModel;
    assertEquals(expectedName, dmnIncludedModel.getName());
    assertEquals(value, dmnIncludedModel.getNamespace());
    assertEquals(path, dmnIncludedModel.getPath());
    assertEquals(expectedDrgElementsCount, dmnIncludedModel.getDrgElementsCount());
    assertEquals(expectedDataTypesCount, dmnIncludedModel.getDataTypesCount());
}
Also used : Maps(org.kie.soup.commons.util.Maps) BaseIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord) DMNIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.DMNIncludedModelActiveRecord) KieAssetsDropdownItem(org.kie.workbench.common.widgets.client.assets.dropdown.KieAssetsDropdownItem)

Example 9 with DMNIncludedModelActiveRecord

use of org.kie.workbench.common.dmn.client.editors.included.DMNIncludedModelActiveRecord in project kie-wb-common by kiegroup.

the class DMNCardComponentTest method testRefreshView.

@Test
public void testRefreshView() {
    final DMNIncludedModelActiveRecord includedModel = mock(DMNIncludedModelActiveRecord.class);
    final String path = "/bla/bla/bla/111111111111111222222222222222333333333333333444444444444444/file.dmn";
    final int dataTypesCount = 12;
    final int drgElementsCount = 34;
    when(includedModel.getNamespace()).thenReturn(path);
    when(includedModel.getDataTypesCount()).thenReturn(dataTypesCount);
    when(includedModel.getDrgElementsCount()).thenReturn(drgElementsCount);
    doReturn(includedModel).when(card).getIncludedModel();
    card.refreshView();
    verify(cardView).setPath("...111111222222222222222333333333333333444444444444444/file.dmn");
    verify(cardView).setDataTypesCount(dataTypesCount);
    verify(cardView).setDrgElementsCount(drgElementsCount);
}
Also used : DMNIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.DMNIncludedModelActiveRecord) Test(org.junit.Test)

Example 10 with DMNIncludedModelActiveRecord

use of org.kie.workbench.common.dmn.client.editors.included.DMNIncludedModelActiveRecord in project kie-wb-common by kiegroup.

the class DMNCardsGridComponentTest method testRefresh.

@Test
public void testRefresh() {
    final DefaultIncludedModelActiveRecord includedModel1 = mock(DefaultIncludedModelActiveRecord.class);
    final DMNIncludedModelActiveRecord includedModel2 = mock(DMNIncludedModelActiveRecord.class);
    final PMMLIncludedModelActiveRecord includedModel3 = mock(PMMLIncludedModelActiveRecord.class);
    final DefaultCardComponent card1 = mock(DefaultCardComponent.class);
    final DMNCardComponent card2 = mock(DMNCardComponent.class);
    final PMMLCardComponent card3 = mock(PMMLCardComponent.class);
    final List<BaseIncludedModelActiveRecord> includedModels = asList(includedModel1, includedModel2, includedModel3);
    when(pageState.generateIncludedModels()).thenReturn(includedModels);
    when(defaultCardComponent.get()).thenReturn(card1);
    when(dmnCardComponent.get()).thenReturn(card2);
    when(pmmlCardComponent.get()).thenReturn(card3);
    grid.refresh();
    verify(card1).setup(grid, includedModel1);
    verify(card2).setup(grid, includedModel2);
    verify(card3).setup(grid, includedModel3);
    verify(cardsGridComponent).setupCards(asList(card1, card2, card3));
}
Also used : DefaultIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.DefaultIncludedModelActiveRecord) PMMLIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.PMMLIncludedModelActiveRecord) BaseIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord) DMNIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.DMNIncludedModelActiveRecord) Test(org.junit.Test)

Aggregations

DMNIncludedModelActiveRecord (org.kie.workbench.common.dmn.client.editors.included.DMNIncludedModelActiveRecord)11 Test (org.junit.Test)7 Import (org.kie.workbench.common.dmn.api.definition.model.Import)5 BaseIncludedModelActiveRecord (org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord)5 ImportDMN (org.kie.workbench.common.dmn.api.definition.model.ImportDMN)4 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)4 PMMLIncludedModelActiveRecord (org.kie.workbench.common.dmn.client.editors.included.PMMLIncludedModelActiveRecord)4 DefaultIncludedModelActiveRecord (org.kie.workbench.common.dmn.client.editors.included.DefaultIncludedModelActiveRecord)3 ImportPMML (org.kie.workbench.common.dmn.api.definition.model.ImportPMML)2 LocationURI (org.kie.workbench.common.dmn.api.property.dmn.LocationURI)2 KieAssetsDropdownItem (org.kie.workbench.common.widgets.client.assets.dropdown.KieAssetsDropdownItem)2 Maps (org.kie.soup.commons.util.Maps)1 RefreshDecisionComponents (org.kie.workbench.common.dmn.client.docks.navigator.events.RefreshDecisionComponents)1 Mockito.doAnswer (org.mockito.Mockito.doAnswer)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1