Search in sources :

Example 6 with KieAssetsDropdownItem

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

the class DMNAssetsDropdownItemsProviderTest method testAsKieAssetForPMMLIncludedModel.

@Test
public void testAsKieAssetForPMMLIncludedModel() {
    final PMMLIncludedModel model = makePMMLIncludedModel(1, 2);
    final KieAssetsDropdownItem dropdownItem = itemsProvider.asKieAsset(model);
    assertEquals(model.getModelName(), dropdownItem.getText());
    assertEquals(model.getModelPackage(), dropdownItem.getSubText());
    assertEquals(model.getPath(), dropdownItem.getMetaData().get(PATH_METADATA));
    assertEquals(model.getImportType(), dropdownItem.getMetaData().get(IMPORT_TYPE_METADATA));
    assertEquals(model.getModelCount().toString(), dropdownItem.getMetaData().get(PMML_MODEL_COUNT_METADATA));
}
Also used : PMMLIncludedModel(org.kie.workbench.common.dmn.api.editors.included.PMMLIncludedModel) KieAssetsDropdownItem(org.kie.workbench.common.widgets.client.assets.dropdown.KieAssetsDropdownItem) Test(org.junit.Test)

Example 7 with KieAssetsDropdownItem

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

Example 8 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 9 with KieAssetsDropdownItem

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

the class SettingsPresenterTest method validateDmnPath_Invalid.

@Test
public void validateDmnPath_Invalid() {
    KieAssetsDropdownItem item = new KieAssetsDropdownItem("DMNFile", "", "", null);
    when(settingsScenarioSimulationDropdownMock.getValue()).thenReturn(Optional.of(item));
    settingsPresenterSpy.validateSimulation();
    verify(settingsScenarioSimulationDropdownMock, times(1)).getValue();
    verify(dmnFilePathErrorLabelStyleMock, times(1)).setDisplay(eq(Style.Display.INLINE));
    verify(dmnFilePathErrorLabelMock, times(1)).setInnerText(eq(ScenarioSimulationEditorConstants.INSTANCE.chooseValidDMNAsset()));
    verify(settingsPresenterSpy, never()).syncDmnFilePath();
    verify(eventBusMock, never()).fireEvent(isA(ValidateSimulationEvent.class));
}
Also used : ValidateSimulationEvent(org.drools.workbench.screens.scenariosimulation.client.events.ValidateSimulationEvent) KieAssetsDropdownItem(org.kie.workbench.common.widgets.client.assets.dropdown.KieAssetsDropdownItem) Test(org.junit.Test)

Example 10 with KieAssetsDropdownItem

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

the class SettingsPresenterTest method syncDmnFilePathChangedValue.

@Test
public void syncDmnFilePathChangedValue() {
    KieAssetsDropdownItem item = new KieAssetsDropdownItem("DMNFile", "", DMN_FILE_PATH + "2", null);
    when(settingsScenarioSimulationDropdownMock.getValue()).thenReturn(Optional.of(item));
    settingsPresenterSpy.syncDmnFilePath();
    verify(eventBusMock, times(1)).fireEvent(updateSettingsDataEventArgumentCaptor.capture());
    assertTrue(updateSettingsDataEventArgumentCaptor.getValue().getSettingsValueChanged().test(settingsSpy));
    updateSettingsDataEventArgumentCaptor.getValue().getSettingsChangeToApply().accept(settingsSpy);
    verify(settingsSpy, times(1)).setDmnFilePath(eq(DMN_FILE_PATH + "2"));
    assertEquals(DMN_FILE_PATH + "2", settingsSpy.getDmnFilePath());
}
Also used : 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