Search in sources :

Example 1 with DataTypeManager

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

the class DataTypeCreateHandlerTest method testAppendWhenNameIsSet.

@Test
public void testAppendWhenNameIsSet() {
    final DataType dataType = mock(DataType.class);
    final DataType updatedDataType = mock(DataType.class);
    final DataTypeManager withDataType = mock(DataTypeManager.class);
    final ItemDefinition itemDefinition = mock(ItemDefinition.class);
    final List<DataType> expectedAffectedDataTypes = asList(mock(DataType.class), mock(DataType.class));
    final String existingName = "existing name";
    when(dataType.getName()).thenReturn(existingName);
    when(dataTypeManager.withDataType(dataType)).thenReturn(withDataType);
    when(recordEngine.update(updatedDataType)).thenReturn(expectedAffectedDataTypes);
    doReturn(updatedDataType).when(handler).updateDataTypeProperties(dataType, TOP_LEVEL_PARENT_UUID, itemDefinition);
    final List<DataType> actualAffectedDataTypes = handler.append(dataType, itemDefinition);
    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) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Example 2 with DataTypeManager

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

the class DataTypeCreateHandlerTest method testUpdateDataType.

@Test
public void testUpdateDataType() {
    final String parentUUID = "parentUUID";
    final DataType dataType = mock(DataType.class);
    final DataType expectedUpdateDataType = mock(DataType.class);
    final ItemDefinition itemDefinition = mock(ItemDefinition.class);
    final DataTypeManager dataTypeManagerWithDataType = mock(DataTypeManager.class);
    final DataTypeManager dataTypeManagerWithParentUUID = mock(DataTypeManager.class);
    final DataTypeManager dataTypeManagerWithItemDefinition = mock(DataTypeManager.class);
    final DataTypeManager dataTypeManagerWithIndexedItemDefinition = mock(DataTypeManager.class);
    final DataTypeManager dataTypeManagerWithItemDefinitionSubDataTypes = mock(DataTypeManager.class);
    final DataTypeManager dataTypeManagerWithUniqueName = mock(DataTypeManager.class);
    when(dataTypeManager.withDataType(dataType)).thenReturn(dataTypeManagerWithDataType);
    when(dataTypeManagerWithDataType.withParentUUID(parentUUID)).thenReturn(dataTypeManagerWithParentUUID);
    when(dataTypeManagerWithParentUUID.withItemDefinition(itemDefinition)).thenReturn(dataTypeManagerWithItemDefinition);
    when(dataTypeManagerWithItemDefinition.withIndexedItemDefinition()).thenReturn(dataTypeManagerWithIndexedItemDefinition);
    when(dataTypeManagerWithIndexedItemDefinition.withItemDefinitionSubDataTypes()).thenReturn(dataTypeManagerWithItemDefinitionSubDataTypes);
    when(dataTypeManagerWithItemDefinitionSubDataTypes.withUniqueName()).thenReturn(dataTypeManagerWithUniqueName);
    when(dataTypeManagerWithUniqueName.get()).thenReturn(expectedUpdateDataType);
    final DataType actualUpdatedDataType = handler.updateDataTypeProperties(dataType, parentUUID, itemDefinition);
    assertEquals(expectedUpdateDataType, actualUpdatedDataType);
}
Also used : DataTypeManager(org.kie.workbench.common.dmn.client.editors.types.common.DataTypeManager) 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 3 with DataTypeManager

use of org.kie.workbench.common.dmn.client.editors.types.common.DataTypeManager 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 4 with DataTypeManager

use of org.kie.workbench.common.dmn.client.editors.types.common.DataTypeManager 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)

Example 5 with DataTypeManager

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

the class DataTypeListTest method testRefreshSubItems.

@Test
public void testRefreshSubItems() {
    final DataTypeListItem listItem0 = mock(DataTypeListItem.class);
    final DataTypeListItem listItem1 = mock(DataTypeListItem.class);
    final DataTypeListItem listItem2 = mock(DataTypeListItem.class);
    final DataTypeListItem listItem3 = mock(DataTypeListItem.class);
    final DataType dataType0 = mock(DataType.class);
    final DataType dataType1 = mock(DataType.class);
    final DataType dataType2 = mock(DataType.class);
    final DataType dataType3 = mock(DataType.class);
    final DataTypeManager dataTypeManager1 = mock(DataTypeManager.class);
    final DataTypeManager dataTypeManager2 = mock(DataTypeManager.class);
    final DataTypeManager dataTypeManager3 = mock(DataTypeManager.class);
    final ArrayList<Object> items = new ArrayList<>();
    final int level = 1;
    final HTMLElement element0 = mock(HTMLElement.class);
    final HTMLElement element1 = mock(HTMLElement.class);
    final HTMLElement element2 = mock(HTMLElement.class);
    final HTMLElement element3 = mock(HTMLElement.class);
    when(listItem0.getLevel()).thenReturn(level);
    when(listItem0.getDataType()).thenReturn(dataType0);
    when(listItem0.getDragAndDropElement()).thenReturn(element0);
    when(listItem1.getDataType()).thenReturn(dataType1);
    when(listItem1.getDragAndDropElement()).thenReturn(element1);
    when(listItem2.getDataType()).thenReturn(dataType2);
    when(listItem2.getDragAndDropElement()).thenReturn(element2);
    when(listItem3.getDataType()).thenReturn(dataType3);
    when(listItem3.getDragAndDropElement()).thenReturn(element3);
    when(dataTypeManager.from(dataType1)).thenReturn(dataTypeManager1);
    when(dataTypeManager.from(dataType2)).thenReturn(dataTypeManager2);
    when(dataTypeManager.from(dataType3)).thenReturn(dataTypeManager3);
    doReturn(singletonList(listItem1)).when(dataTypeList).makeTreeListItems(dataType1, level + 1);
    doReturn(singletonList(listItem2)).when(dataTypeList).makeTreeListItems(dataType2, level + 1);
    doReturn(singletonList(listItem3)).when(dataTypeList).makeTreeListItems(dataType3, level + 1);
    doReturn(items).when(dataTypeList).getItems();
    dataTypeList.refreshSubItemsFromListItem(listItem0, asList(dataType1, dataType2, dataType3));
    verify(view).cleanSubTypes(eq(dataType0));
    verify(view).addSubItems(eq(dataType0), listItemsCaptor.capture());
    verify(dataTypeManager1).withIndexedItemDefinition();
    verify(dataTypeManager2).withIndexedItemDefinition();
    verify(dataTypeManager3).withIndexedItemDefinition();
    verify(dndListComponent).setInitialPositionY(eq(element0), htmlElementsCaptor.capture());
    final List<HTMLElement> capturedElements = htmlElementsCaptor.getValue();
    final List<HTMLElement> expectedElements = asList(element1, element2, element3);
    assertEquals(expectedElements, capturedElements);
    final List<DataTypeListItem> actualItems = listItemsCaptor.getValue();
    final List<DataTypeListItem> expectedItems = asList(listItem1, listItem2, listItem3);
    assertEquals(expectedItems, actualItems);
}
Also used : DataTypeManager(org.kie.workbench.common.dmn.client.editors.types.common.DataTypeManager) HTMLElement(elemental2.dom.HTMLElement) ArrayList(java.util.ArrayList) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) DataObject(org.kie.workbench.common.dmn.api.editors.types.DataObject) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 DataType (org.kie.workbench.common.dmn.client.editors.types.common.DataType)8 DataTypeManager (org.kie.workbench.common.dmn.client.editors.types.common.DataTypeManager)8 ItemDefinition (org.kie.workbench.common.dmn.api.definition.model.ItemDefinition)6 ArrayList (java.util.ArrayList)4 HTMLElement (elemental2.dom.HTMLElement)1 HTMLOptGroupElement (elemental2.dom.HTMLOptGroupElement)1 HTMLOptionElement (elemental2.dom.HTMLOptionElement)1 Function (java.util.function.Function)1 Lists (org.kie.soup.commons.util.Lists)1 DataObject (org.kie.workbench.common.dmn.api.editors.types.DataObject)1 BuiltInType (org.kie.workbench.common.dmn.api.property.dmn.types.BuiltInType)1