Search in sources :

Example 21 with BaseIncludedModelActiveRecord

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

the class IncludedModelsIndexTest method testIndex.

@Test
public void testIndex() {
    final BaseIncludedModelActiveRecord includedModel = mock(BaseIncludedModelActiveRecord.class);
    final Import expectedImport = mock(Import.class);
    final String uuid = "456";
    when(includedModel.getUUID()).thenReturn(uuid);
    modelsIndex.index(includedModel, expectedImport);
    final Import actualImport = modelsIndex.getImport(includedModel);
    assertEquals(expectedImport, actualImport);
}
Also used : Import(org.kie.workbench.common.dmn.api.definition.model.Import) BaseIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord) Test(org.junit.Test)

Example 22 with BaseIncludedModelActiveRecord

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

the class IncludedModelErrorMessageFactoryTest method testGetNameIsNotUniqueFlashMessage.

@Test
public void testGetNameIsNotUniqueFlashMessage() {
    final BaseIncludedModelActiveRecord includedModel = mock(BaseIncludedModelActiveRecord.class);
    final Type expectedType = ERROR;
    final String expectedStrongMessage = "StrongMessage";
    final String expectedRegularMessage = "RegularMessage";
    final String expectedElementSelector = "[data-card-uuid=\"1234\"] [data-field=\"title-input\"]";
    when(includedModel.getUUID()).thenReturn("1234");
    when(includedModel.getName()).thenReturn("file");
    when(translationService.format(IncludedModelNameIsNotUniqueErrorMessage_StrongMessage, "file")).thenReturn(expectedStrongMessage);
    when(translationService.format(IncludedModelNameIsNotUniqueErrorMessage_RegularMessage)).thenReturn(expectedRegularMessage);
    final FlashMessage flashMessage = factory.getNameIsNotUniqueFlashMessage(includedModel);
    assertEquals(expectedType, flashMessage.getType());
    assertEquals(expectedStrongMessage, flashMessage.getStrongMessage());
    assertEquals(expectedRegularMessage, flashMessage.getRegularMessage());
    assertEquals(expectedElementSelector, flashMessage.getElementSelector());
}
Also used : Type(org.kie.workbench.common.dmn.client.editors.common.messages.FlashMessage.Type) FlashMessage(org.kie.workbench.common.dmn.client.editors.common.messages.FlashMessage) BaseIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord) Test(org.junit.Test)

Example 23 with BaseIncludedModelActiveRecord

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

the class IncludedModelsFactoryTest method testMakeIncludedDMNModels.

@Test
public void testMakeIncludedDMNModels() {
    final ImportDMN import1 = mock(ImportDMN.class);
    final ImportDMN import2 = mock(ImportDMN.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 drgElementsCount1 = 2;
    final Integer drgElementsCount2 = 8;
    final Integer itemDefinitionsCount1 = 4;
    final Integer itemDefinitionsCount2 = 16;
    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.DMN.getDefaultNamespace());
    when(import2.getImportType()).thenReturn(DMNImportTypes.DMN.getDefaultNamespace());
    when(import1.getLocationURI()).thenReturn(new LocationURI(uri1));
    when(import2.getLocationURI()).thenReturn(new LocationURI(uri2));
    when(import1.getDrgElementsCount()).thenReturn(drgElementsCount1);
    when(import2.getDrgElementsCount()).thenReturn(drgElementsCount2);
    when(import1.getItemDefinitionsCount()).thenReturn(itemDefinitionsCount1);
    when(import2.getItemDefinitionsCount()).thenReturn(itemDefinitionsCount2);
    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 DMNIncludedModelActiveRecord);
    assertTrue(includedModel2 instanceof DMNIncludedModelActiveRecord);
    assertEquals(itemDefinitionsCount1, ((DMNIncludedModelActiveRecord) includedModel1).getDataTypesCount());
    assertEquals(itemDefinitionsCount2, ((DMNIncludedModelActiveRecord) includedModel2).getDataTypesCount());
    assertEquals(drgElementsCount1, ((DMNIncludedModelActiveRecord) includedModel1).getDrgElementsCount());
    assertEquals(drgElementsCount2, ((DMNIncludedModelActiveRecord) includedModel2).getDrgElementsCount());
    assertEquals(recordEngine, includedModel1.getRecordEngine());
    assertEquals(recordEngine, includedModel2.getRecordEngine());
}
Also used : LocationURI(org.kie.workbench.common.dmn.api.property.dmn.LocationURI) ImportDMN(org.kie.workbench.common.dmn.api.definition.model.ImportDMN) Import(org.kie.workbench.common.dmn.api.definition.model.Import) 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) DMNIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.DMNIncludedModelActiveRecord) Test(org.junit.Test)

Example 24 with BaseIncludedModelActiveRecord

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

the class ImportRecordEngineTest method testUpdateWhenIncludedModelIsNotValid.

@Test
public void testUpdateWhenIncludedModelIsNotValid() {
    final BaseIncludedModelActiveRecord record = mock(BaseIncludedModelActiveRecord.class);
    final Import anImport = mock(Import.class);
    when(record.isValid()).thenReturn(false);
    when(includedModelsIndex.getImport(record)).thenReturn(anImport);
    assertThatThrownBy(() -> recordEngine.update(record)).isInstanceOf(UnsupportedOperationException.class).hasMessageContaining("An invalid Included Model cannot be updated.");
}
Also used : Import(org.kie.workbench.common.dmn.api.definition.model.Import) BaseIncludedModelActiveRecord(org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord) Test(org.junit.Test)

Example 25 with BaseIncludedModelActiveRecord

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

the class ImportRecordEngineTest method testDestroy.

@Test
public void testDestroy() {
    final BaseIncludedModelActiveRecord record = mock(BaseIncludedModelActiveRecord.class);
    final Import import1 = mock(Import.class);
    final Import import2 = mock(Import.class);
    final List<Import> expectedImports = singletonList(import1);
    final List<Import> actualImports = new ArrayList<>(asList(import1, import2));
    final String name = "name";
    when(record.getName()).thenReturn(name);
    when(includedModelsIndex.getImport(record)).thenReturn(import2);
    when(stateProvider.getImports()).thenReturn(actualImports);
    final List<BaseIncludedModelActiveRecord> actualResult = recordEngine.destroy(record);
    final List<BaseIncludedModelActiveRecord> expectedResult = singletonList(record);
    verify(definitionsHandler).destroy(record);
    verify(itemDefinitionHandler).destroy(name);
    verify(dmnIncludedModelHandler).destroy(name);
    verify(pmmlIncludedModelHandler).destroy(name);
    assertEquals(expectedImports, actualImports);
    assertEquals(expectedResult, actualResult);
}
Also used : Import(org.kie.workbench.common.dmn.api.definition.model.Import) ArrayList(java.util.ArrayList) 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