use of org.kie.workbench.common.dmn.api.definition.model.ItemDefinition 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);
}
use of org.kie.workbench.common.dmn.api.definition.model.ItemDefinition in project kie-wb-common by kiegroup.
the class ItemDefinitionCreateHandlerTest method testLookupAbsoluteParentWhenParentIsStructure.
@Test
public void testLookupAbsoluteParentWhenParentIsStructure() {
final String referenceUUID = "referenceUUID";
final ItemDefinition parent = mock(ItemDefinition.class);
when(parent.getTypeRef()).thenReturn(null);
when(itemDefinitionStore.get(referenceUUID)).thenReturn(parent);
final Optional<ItemDefinition> actualParent = handler.lookupAbsoluteParent(referenceUUID);
final Optional<ItemDefinition> expectedParent = Optional.of(parent);
assertEquals(expectedParent, actualParent);
}
use of org.kie.workbench.common.dmn.api.definition.model.ItemDefinition in project kie-wb-common by kiegroup.
the class ItemDefinitionCreateHandlerTest method testLookupAbsoluteParentWhenParentIsNotStructure.
@Test
public void testLookupAbsoluteParentWhenParentIsNotStructure() {
final String type = "type";
final String referenceUUID = "referenceUUID";
final ItemDefinition parent = mock(ItemDefinition.class);
final Optional<ItemDefinition> expectedParent = Optional.of(mock(ItemDefinition.class));
final QName qName = mock(QName.class);
when(qName.getLocalPart()).thenReturn(type);
when(parent.getTypeRef()).thenReturn(qName);
when(itemDefinitionStore.get(referenceUUID)).thenReturn(parent);
when(itemDefinitionUtils.findByName(type)).thenReturn(expectedParent);
final Optional<ItemDefinition> actualParent = handler.lookupAbsoluteParent(referenceUUID);
assertEquals(expectedParent, actualParent);
}
use of org.kie.workbench.common.dmn.api.definition.model.ItemDefinition in project kie-wb-common by kiegroup.
the class ItemDefinitionCreateHandlerTest method testInsertNestedItemDefinitionWhenAbsoluteParentIsNotPresent.
@Test
public void testInsertNestedItemDefinitionWhenAbsoluteParentIsNotPresent() {
final DataType record = mock(DataType.class);
final DataType reference = mock(DataType.class);
final ItemDefinition relativeParent = mock(ItemDefinition.class);
final Optional<ItemDefinition> absoluteParent = Optional.empty();
final List<ItemDefinition> itemDefinitions = new ArrayList<>();
final String referenceUUID = "referenceUUID";
when(itemDefinitionStore.get(referenceUUID)).thenReturn(relativeParent);
when(reference.getUUID()).thenReturn(referenceUUID);
when(relativeParent.getItemComponent()).thenReturn(itemDefinitions);
doReturn(absoluteParent).when(handler).lookupAbsoluteParent(referenceUUID);
final ItemDefinition nestedItemDefinition = handler.insertNested(record, reference);
verify(relativeParent).setTypeRef(null);
assertEquals(nestedItemDefinition, itemDefinitions.get(0));
}
use of org.kie.workbench.common.dmn.api.definition.model.ItemDefinition in project kie-wb-common by kiegroup.
the class ItemDefinitionCreateHandlerTest method testInsertItemDefinition.
@Test
public void testInsertItemDefinition() {
final DataType record = mock(DataType.class);
final DataType reference = mock(DataType.class);
final ItemDefinition itemDefinitionReference = mock(ItemDefinition.class);
final ItemDefinition item = mock(ItemDefinition.class);
final List<ItemDefinition> actualItemDefinitions = new ArrayList<ItemDefinition>() {
{
add(item);
add(item);
add(itemDefinitionReference);
add(item);
}
};
final String uuid = "uuid";
when(reference.getUUID()).thenReturn(uuid);
when(itemDefinitionStore.get(uuid)).thenReturn(itemDefinitionReference);
doReturn(actualItemDefinitions).when(handler).getItemDefinitionSiblings(reference);
final ItemDefinition itemDefinition = handler.insertSibling(record, reference, BELOW);
final List<ItemDefinition> expectedItemDefinitions = asList(item, item, itemDefinitionReference, itemDefinition, item);
assertEquals(expectedItemDefinitions, actualItemDefinitions);
}
Aggregations