Search in sources :

Example 46 with Import

use of org.kie.workbench.common.dmn.api.definition.model.Import 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 47 with Import

use of org.kie.workbench.common.dmn.api.definition.model.Import in project kie-wb-common by kiegroup.

the class IncludedModelsPageStateProviderImplTest method testGetImportsWhenDiagramIsPresent.

@Test
public void testGetImportsWhenDiagramIsPresent() {
    final Definitions definitions = mock(Definitions.class);
    final List<Import> expectedImports = asList(mock(Import.class), mock(Import.class));
    when(dmnGraphUtils.getDefinitions(diagram)).thenReturn(definitions);
    when(definitions.getImport()).thenReturn(expectedImports);
    final List<Import> actualImports = stateProvider.getImports();
    assertEquals(expectedImports, actualImports);
}
Also used : Import(org.kie.workbench.common.dmn.api.definition.model.Import) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) Test(org.junit.Test)

Example 48 with Import

use of org.kie.workbench.common.dmn.api.definition.model.Import 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 49 with Import

use of org.kie.workbench.common.dmn.api.definition.model.Import 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)

Example 50 with Import

use of org.kie.workbench.common.dmn.api.definition.model.Import 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)

Aggregations

Import (org.kie.workbench.common.dmn.api.definition.model.Import)51 Test (org.junit.Test)37 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)26 Definitions (org.kie.workbench.common.dmn.api.definition.model.Definitions)14 ArrayList (java.util.ArrayList)11 BaseIncludedModelActiveRecord (org.kie.workbench.common.dmn.client.editors.included.BaseIncludedModelActiveRecord)11 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)10 LocationURI (org.kie.workbench.common.dmn.api.property.dmn.LocationURI)10 ImportPMML (org.kie.workbench.common.dmn.api.definition.model.ImportPMML)9 JSITImport (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport)9 HashMap (java.util.HashMap)8 DRGElement (org.kie.workbench.common.dmn.api.definition.model.DRGElement)8 ImportDMN (org.kie.workbench.common.dmn.api.definition.model.ImportDMN)8 JSITDefinitions (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions)7 JSITDRGElement (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDRGElement)6 DMNIncludedModelActiveRecord (org.kie.workbench.common.dmn.client.editors.included.DMNIncludedModelActiveRecord)5 PMMLDocumentMetadata (org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata)4 List (java.util.List)3 Map (java.util.Map)3 QName (javax.xml.namespace.QName)3