Search in sources :

Example 6 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 testInsertNestedWhenReferenceTypeIsATopLevelDataType.

@Test
public void testInsertNestedWhenReferenceTypeIsATopLevelDataType() {
    final String parentUUID = "parentUUID";
    final String type = "tCity";
    final DataType dataType = mock(DataType.class);
    final DataType reference = mock(DataType.class);
    final DataType topLevelReference = mock(DataType.class);
    final DataType updatedDataType = mock(DataType.class);
    final DataTypeManager updatedDataTypeManager = mock(DataTypeManager.class);
    final DataTypeManager topLevelReferenceDataTypeManager = 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(topLevelReference.getSubDataTypes()).thenReturn(referenceSubDataTypes);
    when(topLevelReference.getName()).thenReturn(type);
    when(topLevelReference.getType()).thenReturn(BuiltInType.STRING.getName());
    when(dataTypeManager.withDataType(topLevelReference)).thenReturn(topLevelReferenceDataTypeManager);
    when(dataTypeManager.withDataType(updatedDataType)).thenReturn(updatedDataTypeManager);
    when(recordEngine.update(updatedDataType)).thenReturn(expectedAffectedDataTypes);
    when(dataTypeStore.getTopLevelDataTypes()).thenReturn(singletonList(topLevelReference));
    doReturn(updatedDataType).when(handler).updateDataTypeProperties(dataType, parentUUID, itemDefinition);
    final List<DataType> actualAffectedDataTypes = handler.insertNested(dataType, reference, itemDefinition);
    verify(topLevelReferenceDataTypeManager).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 7 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 testAppend.

@Test
public void testAppend() {
    final DataType dataType = mock(DataType.class);
    final DataType dataTypeWithoutName = mock(DataType.class);
    final DataType updatedDataType = mock(DataType.class);
    final DataTypeManager withDataType = mock(DataTypeManager.class);
    final DataTypeManager withNoName = mock(DataTypeManager.class);
    final ItemDefinition itemDefinition = mock(ItemDefinition.class);
    final List<DataType> expectedAffectedDataTypes = asList(mock(DataType.class), mock(DataType.class));
    when(dataTypeManager.withDataType(dataType)).thenReturn(withDataType);
    when(withDataType.withNoName()).thenReturn(withNoName);
    when(withNoName.get()).thenReturn(dataTypeWithoutName);
    when(recordEngine.update(updatedDataType)).thenReturn(expectedAffectedDataTypes);
    doReturn(updatedDataType).when(handler).updateDataTypeProperties(dataTypeWithoutName, 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 8 with DataTypeManager

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

the class DataTypeSelectViewTest method testOptionGroupSorting.

@Test
@SuppressWarnings("unchecked")
public void testOptionGroupSorting() {
    final HTMLOptGroupElement groupElement = mock(HTMLOptGroupElement.class);
    final HTMLOptionElement optionElement = mock(HTMLOptionElement.class);
    final DataType customDataType1 = makeDataType("b");
    final DataType customDataType2 = makeDataType("a");
    final List<DataType> customDataTypes = new Lists.Builder().add(customDataType1).add(customDataType2).build();
    doReturn(groupElement).when(view).makeHTMLOptGroupElement();
    doReturn(optionElement).when(view).makeHTMLOptionElement();
    when(translationService.format(DataTypeSelectView_DefaultTitle)).thenReturn("Default");
    when(translationService.format(DataTypeSelectView_CustomTitle)).thenReturn("Custom");
    when(dataTypeStore.getTopLevelDataTypes()).thenReturn(customDataTypes);
    doAnswer(i -> {
        final BuiltInType bit = (BuiltInType) i.getArguments()[0];
        final DataTypeManager dtm = mock(DataTypeManager.class);
        final DataType dt = makeDataType(bit.getName());
        when(dtm.get()).thenReturn(dt);
        return dtm;
    }).when(dataTypeManager).from(any(BuiltInType.class));
    doAnswer(i -> dataTypeUtils.defaultDataTypes()).when(presenter).getDefaultDataTypes();
    doAnswer(i -> dataTypeUtils.customDataTypes()).when(presenter).getCustomDataTypes();
    view.setupDropdownItems();
    final int visibleItems = BuiltInType.values().length - 1;
    // Check all items were added to the group minus the UNDEFINED item
    verify(view, times(visibleItems + customDataTypes.size())).makeOption(dataTypeCaptor.capture(), any(Function.class));
    final List<DataType> dataTypes = dataTypeCaptor.getAllValues();
    // Check the items were sorted correctly
    assertEquals("Any", dataTypes.get(0).getType());
    assertEquals("boolean", dataTypes.get(1).getType());
    assertEquals("context", dataTypes.get(2).getType());
    assertEquals("date", dataTypes.get(3).getType());
    assertEquals("date and time", dataTypes.get(4).getType());
    assertEquals("days and time duration", dataTypes.get(5).getType());
    assertEquals("number", dataTypes.get(6).getType());
    assertEquals("string", dataTypes.get(7).getType());
    assertEquals("time", dataTypes.get(8).getType());
    assertEquals("years and months duration", dataTypes.get(9).getType());
    final int customDataTypesOffset = visibleItems;
    assertEquals("a", dataTypes.get(customDataTypesOffset).getType());
    assertEquals("b", dataTypes.get(customDataTypesOffset + 1).getType());
}
Also used : Function(java.util.function.Function) HTMLOptGroupElement(elemental2.dom.HTMLOptGroupElement) DataTypeManager(org.kie.workbench.common.dmn.client.editors.types.common.DataTypeManager) Lists(org.kie.soup.commons.util.Lists) HTMLOptionElement(elemental2.dom.HTMLOptionElement) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) BuiltInType(org.kie.workbench.common.dmn.api.property.dmn.types.BuiltInType) 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