Search in sources :

Example 1 with PMMLIncludedModelActiveRecord

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

the class IncludedModelModal method createIncludedModel.

BaseIncludedModelActiveRecord createIncludedModel(final Map<String, String> metaData) {
    final String importType = metaData.get(IMPORT_TYPE_METADATA);
    if (Objects.equals(DMNImportTypes.DMN, determineImportType(importType))) {
        final DMNIncludedModelActiveRecord dmnIncludedModel = new DMNIncludedModelActiveRecord(recordEngine);
        dmnIncludedModel.setDrgElementsCount(Integer.valueOf(metaData.get(DRG_ELEMENT_COUNT_METADATA)));
        dmnIncludedModel.setDataTypesCount(Integer.valueOf(metaData.get(ITEM_DEFINITION_COUNT_METADATA)));
        return dmnIncludedModel;
    } else if (Objects.equals(DMNImportTypes.PMML, determineImportType(importType))) {
        final PMMLIncludedModelActiveRecord pmmlIncludedModel = new PMMLIncludedModelActiveRecord(recordEngine);
        pmmlIncludedModel.setModelCount(Integer.valueOf(metaData.get(PMML_MODEL_COUNT_METADATA)));
        return pmmlIncludedModel;
    }
    return new DefaultIncludedModelActiveRecord(recordEngine);
}
Also used : DefaultIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.DefaultIncludedModelActiveRecord) PMMLIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.PMMLIncludedModelActiveRecord) DMNIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.DMNIncludedModelActiveRecord)

Example 2 with PMMLIncludedModelActiveRecord

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

the class PMMLCardComponentTest method testRefreshView.

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

Example 3 with PMMLIncludedModelActiveRecord

use of org.kie.workbench.common.dmn.client.editors.included.PMMLIncludedModelActiveRecord 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 4 with PMMLIncludedModelActiveRecord

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

the class ImportFactoryTest method testMakePMMLImport.

@Test
public void testMakePMMLImport() {
    final PMMLIncludedModelActiveRecord record = new PMMLIncludedModelActiveRecord(null);
    final String expectedImportType = DMNImportTypes.PMML.getDefaultNamespace();
    final String expectedNameValue = "name";
    final String path = "/src/main/kie/pmml";
    final Name expectedName = new Name(expectedNameValue);
    final LocationURI expectedLocationURI = new LocationURI(path);
    final int expectedModelCount = 2;
    record.setPath(path);
    record.setName(expectedNameValue);
    record.setNamespace(expectedNameValue);
    record.setImportType(DMNImportTypes.PMML.getDefaultNamespace());
    record.setModelCount(expectedModelCount);
    final Import actualImport = factory.makeImport(record);
    assertTrue(actualImport instanceof ImportPMML);
    final ImportPMML pmmlImport = (ImportPMML) actualImport;
    assertEquals(expectedImportType, actualImport.getImportType());
    assertEquals(expectedName, actualImport.getName());
    assertEquals(expectedLocationURI, actualImport.getLocationURI());
    assertEquals(expectedNameValue, actualImport.getNamespace());
    assertEquals(expectedImportType, actualImport.getImportType());
    assertEquals(expectedModelCount, pmmlImport.getModelCount());
}
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) ImportPMML(org.kie.workbench.common.dmn.api.definition.model.ImportPMML) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Test(org.junit.Test)

Example 5 with PMMLIncludedModelActiveRecord

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

the class IncludedModelModalTest method testIncludePMML.

@Test
public void testIncludePMML() {
    final String path = "path";
    final String name = "name";
    final String namespace = "namespace";
    final int modelCount = 2;
    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.PMML.getDefaultNamespace()).put(PMML_MODEL_COUNT_METADATA, Integer.toString(modelCount)).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 PMMLIncludedModelActiveRecord);
    final PMMLIncludedModelActiveRecord pmmlActiveRecord = (PMMLIncludedModelActiveRecord) baseActiveRecord;
    assertEquals(path, pmmlActiveRecord.getPath());
    assertEquals(name, pmmlActiveRecord.getName());
    assertEquals(namespace, pmmlActiveRecord.getNamespace());
    assertEquals(modelCount, (int) pmmlActiveRecord.getModelCount());
}
Also used : Maps(org.kie.soup.commons.util.Maps) PMMLIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.PMMLIncludedModelActiveRecord) RefreshDecisionComponents(org.kie.workbench.common.dmn.client.docks.navigator.events.RefreshDecisionComponents) BaseIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord) KieAssetsDropdownItem(org.kie.workbench.common.widgets.client.assets.dropdown.KieAssetsDropdownItem) Test(org.junit.Test)

Aggregations

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