Search in sources :

Example 16 with DataType

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

the class DataTypeListTest method testRefreshItemsByUpdatedDataTypes.

@Test
public void testRefreshItemsByUpdatedDataTypes() {
    final String uuid1 = "uuid1";
    final String uuid2 = "uuid2";
    final String uuid3 = "uuid3";
    final DataType dataType1 = mock(DataType.class);
    final DataType dataType2 = mock(DataType.class);
    final DataType dataType3 = mock(DataType.class);
    final DataTypeListItem listItem = mock(DataTypeListItem.class);
    final List<DataType> subDataTypes = asList(dataType2, dataType3);
    final List<DataType> existingItems = new ArrayList<>(asList(dataType1, dataType2, dataType3));
    doReturn(Optional.of(listItem)).when(dataTypeList).findItem(dataType1);
    doReturn(Optional.empty()).when(dataTypeList).findItem(dataType2);
    doReturn(Optional.empty()).when(dataTypeList).findItem(dataType3);
    doNothing().when(dataTypeList).refreshSubItemsFromListItem(any(), anyListOf(DataType.class));
    when(dataType1.getUUID()).thenReturn(uuid1);
    when(dataType2.getUUID()).thenReturn(uuid2);
    when(dataType3.getUUID()).thenReturn(uuid3);
    when(dataType1.getSubDataTypes()).thenReturn(subDataTypes);
    dataTypeList.refreshItemsByUpdatedDataTypes(existingItems);
    verify(listItem).refresh();
    verify(dataTypeList).refreshSubItemsFromListItem(listItem, subDataTypes);
    verify(dndListComponent).consolidateYPosition();
    verify(dndListComponent).refreshItemsPosition();
    verify(searchBar).refresh();
}
Also used : ArrayList(java.util.ArrayList) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Example 17 with DataType

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

the class DataTypeListTest method testAddDataTypeWithDefinedDataType.

@Test
public void testAddDataTypeWithDefinedDataType() {
    final DataTypeListItem listItem = mock(DataTypeListItem.class);
    final DataType dataType = mock(DataType.class);
    doReturn(listItem).when(dataTypeList).makeListItem(dataType);
    dataTypeList.addDataType(dataType, false);
    verify(searchBar).reset();
    verify(dataType).create();
    verify(view).showOrHideNoCustomItemsMessage();
    verify(listItem).refresh();
    verify(listItem, never()).enableEditMode();
    verify(dndListComponent).refreshItemsCSSAndHTMLPosition();
}
Also used : DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Example 18 with DataType

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

the class DataTypeListTest method testInsertProperties.

@Test
public void testInsertProperties() {
    final DataObject dataObject = mock(DataObject.class);
    final String myImportedClass = "org.MyClass";
    final DataType existingDt = mock(DataType.class);
    final DataTypeListItem dtListItem = mock(DataTypeListItem.class);
    final Optional<DataTypeListItem> dtListItemOptional = Optional.of(dtListItem);
    final DataObjectProperty property1 = mock(DataObjectProperty.class);
    final DataObjectProperty property2 = mock(DataObjectProperty.class);
    final List<DataObjectProperty> properties = Arrays.asList(property1, property2);
    final DataType property1DataType = mock(DataType.class);
    final DataType property2DataType = mock(DataType.class);
    when(dataObject.getClassType()).thenReturn(myImportedClass);
    when(dataObject.getProperties()).thenReturn(properties);
    doReturn(Optional.of(existingDt)).when(dataTypeList).findDataTypeByName(myImportedClass);
    doReturn(dtListItemOptional).when(dataTypeList).findItem(existingDt);
    doReturn(property1DataType).when(dataTypeList).createNewDataType(property1);
    doReturn(property2DataType).when(dataTypeList).createNewDataType(property2);
    dataTypeList.insertProperties(dataObject);
    verify(dtListItem).insertNestedField(property1DataType);
    verify(dtListItem).insertNestedField(property2DataType);
}
Also used : DataObjectProperty(org.kie.workbench.common.dmn.api.editors.types.DataObjectProperty) DataObject(org.kie.workbench.common.dmn.api.editors.types.DataObject) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Example 19 with DataType

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

the class DataTypeListTest method testRemoveItemByDataType.

@Test
public void testRemoveItemByDataType() {
    final DataType dataType = mock(DataType.class);
    final String uuid = "uuid";
    doNothing().when(dataTypeList).removeItem(Mockito.<String>any());
    when(dataType.getUUID()).thenReturn(uuid);
    dataTypeList.removeItem(dataType);
    verify(dataTypeList).removeItem(uuid);
    verify(view).removeItem(dataType);
}
Also used : DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Example 20 with DataType

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

the class DataTypeListTest method testFindItemWhenItemExists.

@Test
public void testFindItemWhenItemExists() {
    final String uuid1 = "uuid1";
    final String uuid2 = "uuid2";
    final DataType dataType1 = mock(DataType.class);
    final DataType dataType2 = mock(DataType.class);
    final DataTypeListItem dataTypeListItem1 = mock(DataTypeListItem.class);
    final DataTypeListItem dataTypeListItem2 = mock(DataTypeListItem.class);
    final List<DataTypeListItem> existingItems = new ArrayList<>(asList(dataTypeListItem1, dataTypeListItem2));
    when(dataType1.getUUID()).thenReturn(uuid1);
    when(dataType2.getUUID()).thenReturn(uuid2);
    when(dataTypeListItem1.getDataType()).thenReturn(dataType1);
    when(dataTypeListItem2.getDataType()).thenReturn(dataType2);
    when(dataTypeList.getItems()).thenReturn(existingItems);
    final Optional<DataTypeListItem> item = dataTypeList.findItem(dataType1);
    assertEquals(dataTypeListItem1, item.get());
}
Also used : 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