Search in sources :

Example 96 with DataType

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

the class DataTypeCreateHandlerTest method testInsertWhenAbsoluteParentDoesNotExist.

@Test
public void testInsertWhenAbsoluteParentDoesNotExist() {
    final String parentUUID = "parentUUID";
    final DataType dataType = mock(DataType.class);
    final DataType reference = mock(DataType.class);
    final DataType updatedDataType = mock(DataType.class);
    final ItemDefinition itemDefinition = mock(ItemDefinition.class);
    when(reference.getParentUUID()).thenReturn(parentUUID);
    doReturn(Optional.empty()).when(handler).lookupAbsoluteParent(reference);
    doReturn(updatedDataType).when(handler).updateDataTypeProperties(dataType, parentUUID, itemDefinition);
    final List<DataType> actualAffectedDataTypes = handler.insertSibling(dataType, reference, BELOW, itemDefinition);
    final List<DataType> expectedAffectedDataTypes = emptyList();
    verify(recordEngine).doUpdate(updatedDataType, itemDefinition);
    assertEquals(expectedAffectedDataTypes, actualAffectedDataTypes);
}
Also used : ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Example 97 with DataType

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

the class DataTypeCreateHandlerTest method testInsertWhenAbsoluteParentExists.

@Test
public void testInsertWhenAbsoluteParentExists() {
    final String uuid = "uuid";
    final String name = "name";
    final DataType dataType = mock(DataType.class);
    final DataType reference = mock(DataType.class);
    final DataType dataType0 = mock(DataType.class);
    final DataType dataType2 = mock(DataType.class);
    final DataType absoluteParent = mock(DataType.class);
    final DataType updatedDataType = mock(DataType.class);
    final ItemDefinition itemDefinition = mock(ItemDefinition.class);
    final List<DataType> expectedAffectedDataTypes = asList(mock(DataType.class), mock(DataType.class));
    final List<DataType> siblings = new ArrayList<DataType>() {

        {
            add(dataType0);
            add(reference);
            add(dataType2);
        }
    };
    when(absoluteParent.getUUID()).thenReturn(uuid);
    when(reference.getName()).thenReturn(name);
    when(updatedDataType.getName()).thenReturn(name);
    when(absoluteParent.getSubDataTypes()).thenReturn(siblings);
    when(recordEngine.update(absoluteParent)).thenReturn(expectedAffectedDataTypes);
    doReturn(Optional.of(absoluteParent)).when(handler).lookupAbsoluteParent(reference);
    doReturn(updatedDataType).when(handler).updateDataTypeProperties(dataType, uuid, itemDefinition);
    final List<DataType> actualAffectedDataTypes = handler.insertSibling(dataType, reference, BELOW, itemDefinition);
    verify(recordEngine).doUpdate(dataType, itemDefinition);
    assertEquals(asList(dataType0, reference, updatedDataType, dataType2), siblings);
    assertEquals(expectedAffectedDataTypes, actualAffectedDataTypes);
}
Also used : ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) ArrayList(java.util.ArrayList) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Example 98 with DataType

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

the class DataTypeCreateHandlerTest method testInsertNestedWhenReferenceTypeIsNotDefault.

@Test
public void testInsertNestedWhenReferenceTypeIsNotDefault() {
    final String parentUUID = "parentUUID";
    final String type = "tCity";
    final DataType dataType = mock(DataType.class);
    final DataType reference = mock(DataType.class);
    final DataType updatedDataType = mock(DataType.class);
    final DataTypeManager updatedDataTypeManager = mock(DataTypeManager.class);
    final DataTypeManager referenceDataTypeManager = mock(DataTypeManager.class);
    final ItemDefinition itemDefinition = mock(ItemDefinition.class);
    final List<DataType> expectedAffectedDataTypes = asList(mock(DataType.class), mock(DataType.class));
    final List<DataType> referenceSubDataTypes = new ArrayList<>();
    when(reference.getUUID()).thenReturn(parentUUID);
    when(reference.getType()).thenReturn(type);
    when(reference.getSubDataTypes()).thenReturn(referenceSubDataTypes);
    when(dataTypeManager.withDataType(updatedDataType)).thenReturn(updatedDataTypeManager);
    when(dataTypeManager.withDataType(reference)).thenReturn(referenceDataTypeManager);
    when(recordEngine.update(updatedDataType)).thenReturn(expectedAffectedDataTypes);
    doReturn(updatedDataType).when(handler).updateDataTypeProperties(dataType, parentUUID, itemDefinition);
    final List<DataType> actualAffectedDataTypes = handler.insertNested(dataType, reference, itemDefinition);
    verify(dataTypeManager, never()).asStructure();
    assertEquals(singletonList(updatedDataType), referenceSubDataTypes);
    assertEquals(expectedAffectedDataTypes, actualAffectedDataTypes);
}
Also used : DataTypeManager(org.kie.workbench.common.dmn.client.editors.types.common.DataTypeManager) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) ArrayList(java.util.ArrayList) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Example 99 with DataType

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

the class DataTypeCreateHandlerTest method testLookupAbsoluteParentWhenReferenceTypeIsNotStructure.

@Test
public void testLookupAbsoluteParentWhenReferenceTypeIsNotStructure() {
    final DataType reference = mock(DataType.class);
    final DataType expectedParent = mock(DataType.class);
    final DataType tCityTopLevel = mock(DataType.class);
    final String parentUUID = "parentUUID";
    final String structure = "Structure";
    final String type = "tCity";
    when(reference.getParentUUID()).thenReturn(parentUUID);
    when(expectedParent.getType()).thenReturn(type);
    when(tCityTopLevel.getName()).thenReturn(type);
    when(dataTypeStore.get(parentUUID)).thenReturn(expectedParent);
    when(dataTypeManager.structure()).thenReturn(structure);
    when(dataTypeStore.getTopLevelDataTypes()).thenReturn(singletonList(tCityTopLevel));
    final Optional<DataType> actualParent = handler.lookupAbsoluteParent(reference);
    assertEquals(Optional.of(tCityTopLevel), actualParent);
}
Also used : DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Example 100 with DataType

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

the class DataTypeCreateHandlerTest method testInsertNestedWhenReferenceTypeIsDefault.

@Test
public void testInsertNestedWhenReferenceTypeIsDefault() {
    final DataType dataType = mock(DataType.class);
    final DataType reference = mock(DataType.class);
    final DataTypeManager updatedDataTypeManager = mock(DataTypeManager.class);
    final DataTypeManager referenceDataTypeManager = mock(DataTypeManager.class);
    final ItemDefinition itemDefinition = mock(ItemDefinition.class);
    final String parentUUID = "parentUUID";
    final String type = BuiltInType.STRING.getName();
    final DataType updatedDataType = mock(DataType.class);
    final List<DataType> expectedAffectedDataTypes = asList(mock(DataType.class), mock(DataType.class));
    final List<DataType> referenceSubDataTypes = new ArrayList<>();
    when(reference.getUUID()).thenReturn(parentUUID);
    when(reference.getType()).thenReturn(type);
    when(reference.getSubDataTypes()).thenReturn(referenceSubDataTypes);
    when(dataTypeManager.withDataType(updatedDataType)).thenReturn(updatedDataTypeManager);
    when(dataTypeManager.withDataType(reference)).thenReturn(referenceDataTypeManager);
    when(recordEngine.update(updatedDataType)).thenReturn(expectedAffectedDataTypes);
    doReturn(updatedDataType).when(handler).updateDataTypeProperties(dataType, parentUUID, itemDefinition);
    final List<DataType> actualAffectedDataTypes = handler.insertNested(dataType, reference, itemDefinition);
    verify(referenceDataTypeManager).asStructure();
    assertEquals(singletonList(updatedDataType), referenceSubDataTypes);
    assertEquals(expectedAffectedDataTypes, actualAffectedDataTypes);
}
Also used : DataTypeManager(org.kie.workbench.common.dmn.client.editors.types.common.DataTypeManager) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) ArrayList(java.util.ArrayList) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Aggregations

DataType (org.kie.workbench.common.dmn.client.editors.types.common.DataType)274 Test (org.junit.Test)245 HTMLElement (elemental2.dom.HTMLElement)44 ItemDefinition (org.kie.workbench.common.dmn.api.definition.model.ItemDefinition)39 Element (elemental2.dom.Element)30 ArrayList (java.util.ArrayList)26 DOMTokenList (elemental2.dom.DOMTokenList)24 DataTypeListItem (org.kie.workbench.common.dmn.client.editors.types.listview.DataTypeListItem)14 HTMLDivElement (elemental2.dom.HTMLDivElement)13 HTMLButtonElement (elemental2.dom.HTMLButtonElement)12 Command (org.uberfire.mvp.Command)12 FlashMessage (org.kie.workbench.common.dmn.client.editors.common.messages.FlashMessage)9 DataTypeManager (org.kie.workbench.common.dmn.client.editors.types.common.DataTypeManager)9 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)8 DNDListComponent (org.kie.workbench.common.dmn.client.editors.types.listview.draganddrop.DNDListComponent)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)8 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)7 HTMLAnchorElement (elemental2.dom.HTMLAnchorElement)6 HTMLInputElement (elemental2.dom.HTMLInputElement)6 DataObject (org.kie.workbench.common.dmn.api.editors.types.DataObject)6