Search in sources :

Example 11 with BaseIncludedModelActiveRecord

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

the class ImportRecordEngineTest method testIsValidWhenNameIsUnique.

@Test
public void testIsValidWhenNameIsUnique() {
    final BaseIncludedModelActiveRecord record = mock(BaseIncludedModelActiveRecord.class);
    final Import import1 = mock(Import.class);
    final Import import2 = mock(Import.class);
    final Name name1 = mock(Name.class);
    final Name name2 = mock(Name.class);
    final FlashMessage flashMessage = mock(FlashMessage.class);
    final List<Import> imports = new ArrayList<>(asList(import1, import2));
    when(name1.getValue()).thenReturn("file1");
    when(name2.getValue()).thenReturn("file2");
    when(record.getName()).thenReturn("file-new");
    when(import1.getName()).thenReturn(name1);
    when(import2.getName()).thenReturn(name2);
    when(includedModelsIndex.getImport(record)).thenReturn(import2);
    when(stateProvider.getImports()).thenReturn(imports);
    when(messageFactory.getNameIsNotUniqueFlashMessage(record)).thenReturn(flashMessage);
    final boolean valid = recordEngine.isValid(record);
    assertTrue(valid);
    verifyZeroInteractions(flashMessageEvent);
}
Also used : Import(org.kie.workbench.common.dmn.api.definition.model.Import) ArrayList(java.util.ArrayList) FlashMessage(org.kie.workbench.common.dmn.client.editors.common.messages.FlashMessage) BaseIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Test(org.junit.Test)

Example 12 with BaseIncludedModelActiveRecord

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

the class ImportRecordEngineTest method testIsValidWhenNameIsUnchanged.

@Test
public void testIsValidWhenNameIsUnchanged() {
    final BaseIncludedModelActiveRecord record = mock(BaseIncludedModelActiveRecord.class);
    final Import import1 = mock(Import.class);
    final Import import2 = mock(Import.class);
    final Name name1 = mock(Name.class);
    final Name name2 = mock(Name.class);
    final FlashMessage flashMessage = mock(FlashMessage.class);
    final List<Import> imports = new ArrayList<>(asList(import1, import2));
    when(name1.getValue()).thenReturn("file1");
    when(name2.getValue()).thenReturn("file2");
    when(record.getName()).thenReturn("file2");
    when(import1.getName()).thenReturn(name1);
    when(import2.getName()).thenReturn(name2);
    when(includedModelsIndex.getImport(record)).thenReturn(import2);
    when(stateProvider.getImports()).thenReturn(imports);
    when(messageFactory.getNameIsNotUniqueFlashMessage(record)).thenReturn(flashMessage);
    final boolean valid = recordEngine.isValid(record);
    assertTrue(valid);
    verifyZeroInteractions(flashMessageEvent);
}
Also used : Import(org.kie.workbench.common.dmn.api.definition.model.Import) ArrayList(java.util.ArrayList) FlashMessage(org.kie.workbench.common.dmn.client.editors.common.messages.FlashMessage) BaseIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Test(org.junit.Test)

Example 13 with BaseIncludedModelActiveRecord

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

the class ImportRecordEngineTest method testIsValidWhenNameIsBlank.

@Test
public void testIsValidWhenNameIsBlank() {
    final BaseIncludedModelActiveRecord record = mock(BaseIncludedModelActiveRecord.class);
    final Import anImport = mock(Import.class);
    final Name name = mock(Name.class);
    final FlashMessage flashMessage = mock(FlashMessage.class);
    final List<Import> imports = new ArrayList<>(singletonList(anImport));
    when(name.getValue()).thenReturn("file");
    when(record.getName()).thenReturn("");
    when(anImport.getName()).thenReturn(name);
    when(includedModelsIndex.getImport(record)).thenReturn(anImport);
    when(stateProvider.getImports()).thenReturn(imports);
    when(messageFactory.getNameIsBlankFlashMessage(record)).thenReturn(flashMessage);
    final boolean valid = recordEngine.isValid(record);
    assertFalse(valid);
    verify(flashMessageEvent).fire(flashMessage);
}
Also used : Import(org.kie.workbench.common.dmn.api.definition.model.Import) ArrayList(java.util.ArrayList) FlashMessage(org.kie.workbench.common.dmn.client.editors.common.messages.FlashMessage) BaseIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Test(org.junit.Test)

Example 14 with BaseIncludedModelActiveRecord

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

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

the class IncludedModelModalTest method testRefreshDataTypesList.

@Test
public void testRefreshDataTypesList() {
    final BaseIncludedModelActiveRecord includedModel = mock(BaseIncludedModelActiveRecord.class);
    final Consumer<List<ItemDefinition>> listConsumer = list -> {
    /* Nothing. */
    };
    final String modelName = "model1";
    final String namespace = "://namespace1";
    when(includedModel.getName()).thenReturn(modelName);
    when(includedModel.getNamespace()).thenReturn(namespace);
    doReturn(listConsumer).when(modal).getItemDefinitionConsumer();
    modal.refreshDataTypesList(includedModel);
    verify(client).loadItemDefinitionsByNamespace(modelName, namespace, listConsumer);
}
Also used : GwtMockitoTestRunner(com.google.gwtmockito.GwtMockitoTestRunner) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) DMNAssetsDropdown(org.kie.workbench.common.dmn.client.editors.included.modal.dropdown.DMNAssetsDropdown) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) RefreshDataTypesListEvent(org.kie.workbench.common.dmn.client.editors.types.common.events.RefreshDataTypesListEvent) IncludedModelsPagePresenter(org.kie.workbench.common.dmn.client.editors.included.IncludedModelsPagePresenter) BaseIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord) Maps(org.kie.soup.commons.util.Maps) Mockito.spy(org.mockito.Mockito.spy) Captor(org.mockito.Captor) ITEM_DEFINITION_COUNT_METADATA(org.kie.workbench.common.dmn.client.editors.included.modal.dropdown.DMNAssetsDropdownItemsProvider.ITEM_DEFINITION_COUNT_METADATA) ArgumentCaptor(org.mockito.ArgumentCaptor) IMPORT_TYPE_METADATA(org.kie.workbench.common.dmn.client.editors.included.modal.dropdown.DMNAssetsDropdownItemsProvider.IMPORT_TYPE_METADATA) HTMLElement(elemental2.dom.HTMLElement) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) PATH_METADATA(org.kie.workbench.common.dmn.client.editors.included.modal.dropdown.DMNAssetsDropdownItemsProvider.PATH_METADATA) Mockito.doReturn(org.mockito.Mockito.doReturn) Command(org.uberfire.mvp.Command) Before(org.junit.Before) PMMLIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.PMMLIncludedModelActiveRecord) ImportRecordEngine(org.kie.workbench.common.dmn.client.editors.included.imports.persistence.ImportRecordEngine) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) WIDTH(org.kie.workbench.common.dmn.client.editors.included.modal.IncludedModelModal.WIDTH) Mockito.doNothing(org.mockito.Mockito.doNothing) Mockito.when(org.mockito.Mockito.when) 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) DMNImportTypes(org.kie.workbench.common.dmn.api.editors.included.DMNImportTypes) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) DMNIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.DMNIncludedModelActiveRecord) RefreshDecisionComponents(org.kie.workbench.common.dmn.client.docks.navigator.events.RefreshDecisionComponents) EventSourceMock(org.uberfire.mocks.EventSourceMock) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) Arrays.asList(java.util.Arrays.asList) List(java.util.List) BaseIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord) 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