use of org.kie.workbench.common.dmn.client.editors.types.common.DataType in project kie-wb-common by kiegroup.
the class DataTypeCreateHandlerTest method testInsertWhenAbsoluteParentDoesNotExist.
@Test
public void testInsertWhenAbsoluteParentDoesNotExist() {
final String parentUUID = "parentUUID";
final DataType dataType = mock(DataType.class);
final DataType reference = mock(DataType.class);
final DataType updatedDataType = mock(DataType.class);
final ItemDefinition itemDefinition = mock(ItemDefinition.class);
when(reference.getParentUUID()).thenReturn(parentUUID);
doReturn(Optional.empty()).when(handler).lookupAbsoluteParent(reference);
doReturn(updatedDataType).when(handler).updateDataTypeProperties(dataType, parentUUID, itemDefinition);
final List<DataType> actualAffectedDataTypes = handler.insertSibling(dataType, reference, BELOW, itemDefinition);
final List<DataType> expectedAffectedDataTypes = emptyList();
verify(recordEngine).doUpdate(updatedDataType, itemDefinition);
assertEquals(expectedAffectedDataTypes, actualAffectedDataTypes);
}
use of org.kie.workbench.common.dmn.client.editors.types.common.DataType in project kie-wb-common by kiegroup.
the class DataTypeCreateHandlerTest method testInsertWhenAbsoluteParentExists.
@Test
public void testInsertWhenAbsoluteParentExists() {
final String uuid = "uuid";
final String name = "name";
final DataType dataType = mock(DataType.class);
final DataType reference = mock(DataType.class);
final DataType dataType0 = mock(DataType.class);
final DataType dataType2 = mock(DataType.class);
final DataType absoluteParent = mock(DataType.class);
final DataType updatedDataType = mock(DataType.class);
final ItemDefinition itemDefinition = mock(ItemDefinition.class);
final List<DataType> expectedAffectedDataTypes = asList(mock(DataType.class), mock(DataType.class));
final List<DataType> siblings = new ArrayList<DataType>() {
{
add(dataType0);
add(reference);
add(dataType2);
}
};
when(absoluteParent.getUUID()).thenReturn(uuid);
when(reference.getName()).thenReturn(name);
when(updatedDataType.getName()).thenReturn(name);
when(absoluteParent.getSubDataTypes()).thenReturn(siblings);
when(recordEngine.update(absoluteParent)).thenReturn(expectedAffectedDataTypes);
doReturn(Optional.of(absoluteParent)).when(handler).lookupAbsoluteParent(reference);
doReturn(updatedDataType).when(handler).updateDataTypeProperties(dataType, uuid, itemDefinition);
final List<DataType> actualAffectedDataTypes = handler.insertSibling(dataType, reference, BELOW, itemDefinition);
verify(recordEngine).doUpdate(dataType, itemDefinition);
assertEquals(asList(dataType0, reference, updatedDataType, dataType2), siblings);
assertEquals(expectedAffectedDataTypes, actualAffectedDataTypes);
}
use of org.kie.workbench.common.dmn.client.editors.types.common.DataType 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);
}
use of org.kie.workbench.common.dmn.client.editors.types.common.DataType in project kie-wb-common by kiegroup.
the class DataTypeCreateHandlerTest method testLookupAbsoluteParentWhenReferenceTypeIsNotStructure.
@Test
public void testLookupAbsoluteParentWhenReferenceTypeIsNotStructure() {
final DataType reference = mock(DataType.class);
final DataType expectedParent = mock(DataType.class);
final DataType tCityTopLevel = mock(DataType.class);
final String parentUUID = "parentUUID";
final String structure = "Structure";
final String type = "tCity";
when(reference.getParentUUID()).thenReturn(parentUUID);
when(expectedParent.getType()).thenReturn(type);
when(tCityTopLevel.getName()).thenReturn(type);
when(dataTypeStore.get(parentUUID)).thenReturn(expectedParent);
when(dataTypeManager.structure()).thenReturn(structure);
when(dataTypeStore.getTopLevelDataTypes()).thenReturn(singletonList(tCityTopLevel));
final Optional<DataType> actualParent = handler.lookupAbsoluteParent(reference);
assertEquals(Optional.of(tCityTopLevel), actualParent);
}
use of org.kie.workbench.common.dmn.client.editors.types.common.DataType 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);
}
Aggregations