Search in sources :

Example 31 with DataType

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

the class StructureTypesTooltipTest method testGetTypeFields.

@Test
public void testGetTypeFields() {
    final String typeName = "tPerson";
    final DataType tPerson = mock(DataType.class);
    final DataType name = mock(DataType.class);
    final DataType age = mock(DataType.class);
    doReturn(typeName).when(presenter).getTypeName();
    when(tPerson.getSubDataTypes()).thenReturn(asList(name, age));
    when(dataTypeManager.getTopLevelDataTypeWithName(typeName)).thenReturn(Optional.of(tPerson));
    final List<DataType> typeFields = presenter.getTypeFields();
    assertEquals(2, typeFields.size());
    assertTrue(typeFields.contains(name));
    assertTrue(typeFields.contains(age));
}
Also used : DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Example 32 with DataType

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

the class DataTypeNameFormatValidatorTest method testGetCallbackWhenIsNotValid.

@Test
public void testGetCallbackWhenIsNotValid() {
    final DataType dataType = mock(DataType.class);
    final Command onSuccess = mock(Command.class);
    final FlashMessage flashMessage = mock(FlashMessage.class);
    when(nameIsInvalidErrorMessage.getFlashMessage(dataType)).thenReturn(flashMessage);
    validator.getCallback(dataType, onSuccess).onSuccess(false);
    verify(flashMessageEvent).fire(flashMessage);
    verify(onSuccess, never()).execute();
}
Also used : Command(org.uberfire.mvp.Command) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) FlashMessage(org.kie.workbench.common.dmn.client.editors.common.messages.FlashMessage) Test(org.junit.Test)

Example 33 with DataType

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

the class DataTypeNameFormatValidatorTest method testGetCallbackWhenIsValid.

@Test
public void testGetCallbackWhenIsValid() {
    final DataType dataType = mock(DataType.class);
    final Command onSuccess = mock(Command.class);
    final FlashMessage flashMessage = mock(FlashMessage.class);
    when(nameIsInvalidErrorMessage.getFlashMessage(dataType)).thenReturn(flashMessage);
    validator.getCallback(dataType, onSuccess).onSuccess(true);
    verify(onSuccess).execute();
    verify(flashMessageEvent, never()).fire(flashMessage);
}
Also used : Command(org.uberfire.mvp.Command) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) FlashMessage(org.kie.workbench.common.dmn.client.editors.common.messages.FlashMessage) Test(org.junit.Test)

Example 34 with DataType

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

the class DataTypeStoreTest method testIndex.

@Test
public void testIndex() {
    // initial state
    assertEquals(1, store.size());
    // index new data type
    final DataType secondDataType = mock(DataType.class);
    final String secondUUID = "789";
    store.index(secondUUID, secondDataType);
    assertEquals(2, store.size());
    assertEquals(dataType, store.get(uuid));
    assertEquals(secondDataType, store.get(secondUUID));
}
Also used : DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Example 35 with DataType

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

the class DNDDataTypesHandlerTest method testShiftCurrentByReferenceWhenCurrentIsCollapsedAndItIsTopLevelShiftOperation.

@Test
public void testShiftCurrentByReferenceWhenCurrentIsCollapsedAndItIsTopLevelShiftOperation() {
    final DataType current = mock(DataType.class);
    final DataType clone = mock(DataType.class);
    final DataType reference = mock(DataType.class);
    final DataType cloneParent1 = mock(DataType.class);
    final DataType cloneParent2 = mock(DataType.class);
    final DNDDataTypesHandlerShiftStrategy strategy = INSERT_INTO_HOVERED_DATA_TYPE;
    final String referenceHash = "referenceHash";
    final String cloneHash = "cloneHash";
    final DataTypeListItem oldItem = mock(DataTypeListItem.class);
    final DataTypeListItem referenceItem = mock(DataTypeListItem.class);
    final DataTypeListItem cloneItem = mock(DataTypeListItem.class);
    final HTMLElement cloneHTMLElement = mock(HTMLElement.class);
    final String cloneParent1UUID = "cloneParent1UUID";
    final String cloneParent2UUID = "cloneParent2UUID";
    final DataTypeListItem cloneParent1Item = mock(DataTypeListItem.class);
    final DataTypeListItem cloneParent2Item = mock(DataTypeListItem.class);
    doReturn(clone).when(handler).cloneDataType(current);
    doReturn(true).when(handler).isTopLevelShiftOperation(current, strategy);
    when(dataTypeList.calculateHash(reference)).thenReturn(referenceHash);
    when(dataTypeList.calculateHash(clone)).thenReturn(cloneHash);
    when(dataTypeList.findItem(current)).thenReturn(Optional.of(oldItem));
    when(dataTypeList.findItemByDataTypeHash(referenceHash)).thenReturn(Optional.of(referenceItem));
    when(dataTypeList.findItemByDataTypeHash(cloneHash)).thenReturn(Optional.of(cloneItem));
    when(cloneItem.getDragAndDropElement()).thenReturn(cloneHTMLElement);
    when(oldItem.isCollapsed()).thenReturn(true);
    when(cloneItem.getDataType()).thenReturn(clone);
    when(clone.getParentUUID()).thenReturn(cloneParent1UUID);
    when(cloneParent1.getParentUUID()).thenReturn(cloneParent2UUID);
    when(cloneParent1.getUUID()).thenReturn(cloneParent1UUID);
    when(cloneParent2.getUUID()).thenReturn(cloneParent2UUID);
    when(dataTypeStore.get(cloneParent1UUID)).thenReturn(cloneParent1);
    when(dataTypeStore.get(cloneParent2UUID)).thenReturn(cloneParent2);
    when(dataTypeList.findItem(cloneParent1)).thenReturn(Optional.of(cloneParent1Item));
    when(dataTypeList.findItem(cloneParent2)).thenReturn(Optional.of(cloneParent2Item));
    handler.shiftCurrentByReference(current, reference, strategy);
    verify(cloneItem).collapse();
    verify(oldItem).destroyWithoutDependentTypes();
    verify(referenceItem).insertNestedField(clone);
    verify(dataTypeList).highlightLevel(cloneHTMLElement);
    verify(cloneParent1Item).expand();
    verify(cloneParent2Item).expand();
}
Also used : DataTypeListItem(org.kie.workbench.common.dmn.client.editors.types.listview.DataTypeListItem) HTMLElement(elemental2.dom.HTMLElement) 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