Search in sources :

Example 16 with BaseIncludedModelActiveRecord

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());
}
Also used : LocationURI(org.kie.workbench.common.dmn.api.property.dmn.LocationURI) Import(org.kie.workbench.common.dmn.api.definition.model.Import) PMMLIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.PMMLIncludedModelActiveRecord) 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) ImportPMML(org.kie.workbench.common.dmn.api.definition.model.ImportPMML) Test(org.junit.Test)

Example 17 with BaseIncludedModelActiveRecord

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;
}
Also used : BaseIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord)

Example 18 with BaseIncludedModelActiveRecord

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();
    });
}
Also used : BaseIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord)

Example 19 with BaseIncludedModelActiveRecord

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;
}
Also used : DefaultIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.DefaultIncludedModelActiveRecord) ImportDMN(org.kie.workbench.common.dmn.api.definition.model.ImportDMN) 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) ImportPMML(org.kie.workbench.common.dmn.api.definition.model.ImportPMML)

Example 20 with BaseIncludedModelActiveRecord

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());
}
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)

Aggregations

BaseIncludedModelActiveRecord (org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord)32 Test (org.junit.Test)27 Import (org.kie.workbench.common.dmn.api.definition.model.Import)11 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)7 ArrayList (java.util.ArrayList)6 FlashMessage (org.kie.workbench.common.dmn.client.editors.common.messages.FlashMessage)6 DMNIncludedModelActiveRecord (org.kie.workbench.common.dmn.client.editors.included.DMNIncludedModelActiveRecord)6 PMMLIncludedModelActiveRecord (org.kie.workbench.common.dmn.client.editors.included.PMMLIncludedModelActiveRecord)5 KieAssetsDropdownItem (org.kie.workbench.common.widgets.client.assets.dropdown.KieAssetsDropdownItem)4 Maps (org.kie.soup.commons.util.Maps)3 RefreshDecisionComponents (org.kie.workbench.common.dmn.client.docks.navigator.events.RefreshDecisionComponents)3 ImportDMN (org.kie.workbench.common.dmn.api.definition.model.ImportDMN)2 ImportPMML (org.kie.workbench.common.dmn.api.definition.model.ImportPMML)2 LocationURI (org.kie.workbench.common.dmn.api.property.dmn.LocationURI)2 Type (org.kie.workbench.common.dmn.client.editors.common.messages.FlashMessage.Type)2 DefaultIncludedModelActiveRecord (org.kie.workbench.common.dmn.client.editors.included.DefaultIncludedModelActiveRecord)2 GwtMockitoTestRunner (com.google.gwtmockito.GwtMockitoTestRunner)1 HTMLElement (elemental2.dom.HTMLElement)1 Arrays.asList (java.util.Arrays.asList)1 List (java.util.List)1