Search in sources :

Example 26 with BaseIncludedModelActiveRecord

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

the class ImportRecordEngineTest method testIsValidWhenNameIsNotUnique.

@Test
public void testIsValidWhenNameIsNotUnique() {
    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("file1");
    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);
    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 27 with BaseIncludedModelActiveRecord

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

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

the class BaseCardComponentTest method testGetSubTitleWhenPathIsNotEmpty.

@Test
public void testGetSubTitleWhenPathIsNotEmpty() {
    final BaseIncludedModelActiveRecord includedModel = prepareIncludedModelMock();
    final String expected = "/src/path/kie/dmn";
    doReturn(includedModel).when(card).getIncludedModel();
    when(includedModel.getPath()).thenReturn(expected);
    final String actual = card.getSubTitle();
    assertEquals(expected, actual);
}
Also used : BaseIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord) Test(org.junit.Test)

Example 29 with BaseIncludedModelActiveRecord

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

the class BaseCardComponentTest method doTestOnTitleChangedWhenIncludedModelIsValid.

private void doTestOnTitleChangedWhenIncludedModelIsValid(final String newName, final String expectedNewName) {
    final DMNCardsGridComponent grid = mock(DMNCardsGridComponent.class);
    final BaseIncludedModelActiveRecord includedModel = prepareIncludedModelMock();
    when(includedModel.getName()).thenReturn(expectedNewName);
    doReturn(true).when(includedModel).isValid();
    doReturn(emptyList()).when(includedModel).update();
    doReturn(includedModel).when(card).getIncludedModel();
    doReturn(grid).when(card).getGrid();
    final boolean titleChanged = card.onTitleChanged().apply(newName);
    assertEquals(expectedNewName, includedModel.getName());
    assertTrue(titleChanged);
    verify(includedModel).update();
    verify(grid).refresh();
    verify(card).refreshDecisionComponents();
}
Also used : BaseIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord)

Example 30 with BaseIncludedModelActiveRecord

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

the class BaseCardComponentTest method testGetSubTitleWhenPathIsEmpty.

@Test
public void testGetSubTitleWhenPathIsEmpty() {
    final BaseIncludedModelActiveRecord includedModel = prepareIncludedModelMock();
    final String expected = "://namespace";
    doReturn(includedModel).when(card).getIncludedModel();
    when(includedModel.getPath()).thenReturn("");
    when(includedModel.getNamespace()).thenReturn(expected);
    final String actual = card.getSubTitle();
    assertEquals(expected, actual);
}
Also used : 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