Search in sources :

Example 86 with DataType

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

the class DNDDataTypesHandlerContextTest method testGetStrategyInsertTopLevelDataType.

@Test
public void testGetStrategyInsertTopLevelDataType() {
    final Element previousElement = mock(Element.class);
    final String uuid = "0000-1111-2222-3333";
    final Optional<DataType> previousDataType = Optional.of(mock(DataType.class));
    when(dataTypeStore.get(uuid)).thenReturn(previousDataType.get());
    when(dndListComponent.getPreviousElement(any(), any())).thenReturn(Optional.of(previousElement));
    when(currentElement.getAttribute(DATA_X_POSITION)).thenReturn("0");
    when(previousElement.getAttribute(DATA_X_POSITION)).thenReturn("0");
    when(previousElement.getAttribute(UUID_ATTR)).thenReturn(uuid);
    loadReferenceContext();
    final DNDDataTypesHandlerShiftStrategy actualShiftStrategy = context.getStrategy();
    final DNDDataTypesHandlerShiftStrategy expectedShiftStrategy = INSERT_TOP_LEVEL_DATA_TYPE;
    assertEquals(expectedShiftStrategy, actualShiftStrategy);
}
Also used : Element(elemental2.dom.Element) HTMLElement(elemental2.dom.HTMLElement) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Example 87 with DataType

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

the class DNDDataTypesHandlerContextTest method testGetStrategyInsertSiblingDataType.

@Test
public void testGetStrategyInsertSiblingDataType() {
    final Element previousElement = mock(Element.class);
    final String uuid = "0000-1111-2222-3333";
    final Optional<DataType> previousDataType = Optional.of(mock(DataType.class));
    when(dataTypeStore.get(uuid)).thenReturn(previousDataType.get());
    when(dndListComponent.getPreviousElement(any(), any())).thenReturn(Optional.of(previousElement));
    when(currentElement.getAttribute(DATA_X_POSITION)).thenReturn("1");
    when(previousElement.getAttribute(DATA_X_POSITION)).thenReturn("1");
    when(previousElement.getAttribute(UUID_ATTR)).thenReturn(uuid);
    loadReferenceContext();
    final DNDDataTypesHandlerShiftStrategy actualShiftStrategy = context.getStrategy();
    final DNDDataTypesHandlerShiftStrategy expectedShiftStrategy = INSERT_SIBLING_DATA_TYPE;
    assertEquals(expectedShiftStrategy, actualShiftStrategy);
}
Also used : Element(elemental2.dom.Element) HTMLElement(elemental2.dom.HTMLElement) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Example 88 with DataType

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

the class ItemDefinitionRecordEngineTest method testDestroyWithoutDependentTypes.

@Test
public void testDestroyWithoutDependentTypes() {
    final DataType dataType = mock(DataType.class);
    final List<DataType> dependentDataTypes = asList(mock(DataType.class), mock(DataType.class));
    when(dataTypeDestroyHandler.refreshDependentDataTypes(dataType)).thenReturn(dependentDataTypes);
    final List<DataType> actualDependentDataTypes = recordEngine.destroyWithoutDependentTypes(dataType);
    final List<DataType> expectedDependentDataTypes = singletonList(dataType);
    verify(dataTypeDestroyHandler).destroy(dataType);
    verify(itemDefinitionDestroyHandler).destroy(dataType, false);
    assertEquals(expectedDependentDataTypes, actualDependentDataTypes);
}
Also used : DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Example 89 with DataType

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

the class ItemDefinitionRecordEngineTest method testIsValidWhenItIsTrue.

@Test
public void testIsValidWhenItIsTrue() {
    final DataType dataType = mock(DataType.class);
    doReturn(true).when(dataTypeNameValidator).isValid(dataType);
    assertTrue(recordEngine.isValid(dataType));
}
Also used : DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Example 90 with DataType

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

the class ItemDefinitionRecordEngineTest method testUpdateWhenDataTypeIsNotValid.

@Test
public void testUpdateWhenDataTypeIsNotValid() {
    final DataType dataType = mock(DataType.class);
    when(dataType.isValid()).thenReturn(false);
    assertThatThrownBy(() -> recordEngine.update(dataType)).isInstanceOf(UnsupportedOperationException.class).hasMessageContaining("An invalid Data Type cannot be updated.");
}
Also used : 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