use of org.kie.workbench.common.dmn.api.definition.model.ItemDefinition 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);
}
use of org.kie.workbench.common.dmn.api.definition.model.ItemDefinition 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);
}
use of org.kie.workbench.common.dmn.api.definition.model.ItemDefinition 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.api.definition.model.ItemDefinition 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.api.definition.model.ItemDefinition 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);
}
Aggregations