use of org.kie.workbench.common.dmn.api.definition.model.ItemDefinition in project kie-wb-common by kiegroup.
the class ItemDefinitionUpdateHandlerTest method testMakeAllowedValuesWhenDataTypeAndItemDefinitionConstraintAreNotEqual.
@Test
public void testMakeAllowedValuesWhenDataTypeAndItemDefinitionConstraintAreNotEqual() {
final DataType dataType = mock(DataType.class);
final ItemDefinition itemDefinition = mock(ItemDefinition.class);
final String expectedText = "(1..20)";
final ConstraintType expectedConstraintType = ConstraintType.RANGE;
when(dataType.getConstraint()).thenReturn(expectedText);
when(dataType.getConstraintType()).thenReturn(expectedConstraintType);
final UnaryTests actualAllowedValues = handler.makeAllowedValues(dataType, itemDefinition);
assertNotNull(actualAllowedValues.getId());
assertNotNull(actualAllowedValues.getDescription());
assertEquals(expectedText, actualAllowedValues.getText().getValue());
assertNull(actualAllowedValues.getExpressionLanguage());
assertEquals(expectedConstraintType, actualAllowedValues.getConstraintType());
}
use of org.kie.workbench.common.dmn.api.definition.model.ItemDefinition in project kie-wb-common by kiegroup.
the class ItemDefinitionUpdateHandlerTest method testMakeQNameWithItemDefinition.
@Test
public void testMakeQNameWithItemDefinition() {
final ItemDefinition itemDefinition = mock(ItemDefinition.class);
final Name itemDefinitionName = mock(Name.class);
final String expectedName = "tAddress";
when(itemDefinitionName.getValue()).thenReturn(expectedName);
when(itemDefinition.getName()).thenReturn(itemDefinitionName);
final QName name = handler.makeQName(itemDefinition);
final String actual = name.toString();
final String expected = "tAddress";
assertEquals(expected, actual);
assertEquals(QName.NULL_NS_URI, name.getNamespaceURI());
}
use of org.kie.workbench.common.dmn.api.definition.model.ItemDefinition in project kie-wb-common by kiegroup.
the class ItemDefinitionUpdateHandlerTest method testUpdateWhenDataTypeIsNotStructure.
@Test
public void testUpdateWhenDataTypeIsNotStructure() {
final String structure = "Structure";
final String type = "type";
final String oldNameValue = "name";
final DataType dataType = mock(DataType.class);
final ItemDefinition itemDefinition = mock(ItemDefinition.class);
final QName qName = mock(QName.class);
final Name name = mock(Name.class);
final Name oldName = mock(Name.class);
final QName newQName = mock(QName.class);
final List<ItemDefinition> itemDefinitions = new ArrayList<ItemDefinition>() {
{
add(mock(ItemDefinition.class));
}
};
when(dataType.getType()).thenReturn(type);
when(dataTypeManager.structure()).thenReturn(structure);
when(itemDefinition.getItemComponent()).thenReturn(itemDefinitions);
when(itemDefinition.getName()).thenReturn(oldName);
when(oldName.getValue()).thenReturn(oldNameValue);
when(panelNotifier.withOldLocalPart(oldNameValue)).thenReturn(panelNotifier);
when(panelNotifier.withNewQName(newQName)).thenReturn(panelNotifier);
doReturn(newQName).when(handler).makeQName(itemDefinition);
doReturn(qName).when(handler).makeQName(dataType);
doReturn(name).when(handler).makeName(dataType);
handler.update(dataType, itemDefinition);
verify(itemDefinition).setTypeRef(qName);
verify(itemDefinition).setName(name);
verify(panelNotifier).notifyPanel();
verify(dataTypeChangedEvent).fire(any());
assertTrue(itemDefinitions.isEmpty());
}
use of org.kie.workbench.common.dmn.api.definition.model.ItemDefinition in project kie-wb-common by kiegroup.
the class ItemDefinitionUpdateHandlerTest method testUpdateWhenDataTypeIsStructure.
@Test
public void testUpdateWhenDataTypeIsStructure() {
final String structure = "Structure";
final String oldNameValue = "name";
final DataType dataType = mock(DataType.class);
final ItemDefinition itemDefinition = mock(ItemDefinition.class);
final Name name = mock(Name.class);
final Name oldName = mock(Name.class);
final QName newQName = mock(QName.class);
when(dataType.getType()).thenReturn(structure);
when(dataTypeManager.structure()).thenReturn(structure);
when(itemDefinition.getName()).thenReturn(oldName);
when(oldName.getValue()).thenReturn(oldNameValue);
when(panelNotifier.withOldLocalPart(oldNameValue)).thenReturn(panelNotifier);
when(panelNotifier.withNewQName(newQName)).thenReturn(panelNotifier);
doReturn(name).when(handler).makeName(dataType);
doReturn(newQName).when(handler).makeQName(itemDefinition);
handler.update(dataType, itemDefinition);
verify(itemDefinition).setTypeRef(null);
verify(itemDefinition).setName(name);
verify(panelNotifier).notifyPanel();
verify(dataTypeChangedEvent).fire(any());
}
use of org.kie.workbench.common.dmn.api.definition.model.ItemDefinition in project kie-wb-common by kiegroup.
the class ItemDefinitionUpdateHandlerTest method testMakeAllowedValuesWhenDataTypeConstraintIsBlank.
@Test
public void testMakeAllowedValuesWhenDataTypeConstraintIsBlank() {
final DataType dataType = mock(DataType.class);
final ItemDefinition itemDefinition = mock(ItemDefinition.class);
when(dataType.getConstraint()).thenReturn("");
final UnaryTests actualAllowedValues = handler.makeAllowedValues(dataType, itemDefinition);
assertNull(actualAllowedValues);
}
Aggregations