Search in sources :

Example 1 with KieAssetsDropdownItem

use of org.kie.workbench.common.widgets.client.assets.dropdown.KieAssetsDropdownItem 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)

Example 2 with KieAssetsDropdownItem

use of org.kie.workbench.common.widgets.client.assets.dropdown.KieAssetsDropdownItem in project drools-wb by kiegroup.

the class SettingsPresenterTest method setup.

@Before
public void setup() {
    super.setup();
    Settings settings = new Settings();
    settings.setRuleFlowGroup(RULE_FLOW_GROUP);
    settings.setDmoSession(DMO_SESSION);
    settings.setDmnFilePath(DMN_FILE_PATH);
    settings.setDmnNamespace(DMN_NAMESPACE);
    settings.setDmnName(DMN_NAME);
    settings.setStateless(STATELESS);
    settings.setSkipFromBuild(SKIP_FROM_BUILD);
    // spy after initialization to avoid double counting
    settingsSpy = spy(settings);
    KieAssetsDropdownItem item = new KieAssetsDropdownItem("DMNFile", "", DMN_FILE_PATH, null);
    when(settingsScenarioSimulationDropdownMock.getValue()).thenReturn(Optional.of(item));
    this.settingsPresenterSpy = spy(new SettingsPresenter(settingsScenarioSimulationDropdownMock, settingsViewMock) {

        {
            this.settingsScenarioSimulationDropdown = settingsScenarioSimulationDropdownMock;
            this.saveCommand = saveCommandMock;
            this.eventBus = eventBusMock;
        }
    });
}
Also used : Settings(org.drools.scenariosimulation.api.model.Settings) KieAssetsDropdownItem(org.kie.workbench.common.widgets.client.assets.dropdown.KieAssetsDropdownItem) Before(org.junit.Before)

Example 3 with KieAssetsDropdownItem

use of org.kie.workbench.common.widgets.client.assets.dropdown.KieAssetsDropdownItem 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 4 with KieAssetsDropdownItem

use of org.kie.workbench.common.widgets.client.assets.dropdown.KieAssetsDropdownItem 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 5 with KieAssetsDropdownItem

use of org.kie.workbench.common.widgets.client.assets.dropdown.KieAssetsDropdownItem 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)

Aggregations

KieAssetsDropdownItem (org.kie.workbench.common.widgets.client.assets.dropdown.KieAssetsDropdownItem)12 Test (org.junit.Test)8 ValidateSimulationEvent (org.drools.workbench.screens.scenariosimulation.client.events.ValidateSimulationEvent)3 Before (org.junit.Before)3 DMNIncludedModel (org.kie.workbench.common.dmn.api.editors.included.DMNIncludedModel)3 PMMLIncludedModel (org.kie.workbench.common.dmn.api.editors.included.PMMLIncludedModel)3 BaseIncludedModelActiveRecord (org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord)3 GwtMockitoTestRunner (com.google.gwtmockito.GwtMockitoTestRunner)2 Arrays.asList (java.util.Arrays.asList)2 List (java.util.List)2 Consumer (java.util.function.Consumer)2 Assert.assertEquals (org.junit.Assert.assertEquals)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 IncludedModel (org.kie.workbench.common.dmn.api.editors.included.IncludedModel)2 LocationURI (org.kie.workbench.common.dmn.api.property.dmn.LocationURI)2 DMNIncludeModelsClient (org.kie.workbench.common.dmn.client.api.included.legacy.DMNIncludeModelsClient)2 DMNIncludedModelActiveRecord (org.kie.workbench.common.dmn.client.editors.included.DMNIncludedModelActiveRecord)2