use of org.kie.workbench.common.dmn.api.definition.model.ItemDefinition in project kie-wb-common by kiegroup.
the class DataTypeListItemTest method testUpdatePropertiesWithNameWithWhitespace.
@Test
public void testUpdatePropertiesWithNameWithWhitespace() {
final DataType dataType = spy(makeDataType());
final String uuid = "uuid";
final String expectedName = "name";
final String expectedNameWithWhitespace = " " + expectedName + " ";
final String expectedType = "type";
final String expectedConstraint = "constraint";
final boolean expectedList = true;
final ItemDefinition itemDefinition = mock(ItemDefinition.class);
when(dataType.getUUID()).thenReturn(uuid);
when(itemDefinitionStore.get(uuid)).thenReturn(itemDefinition);
when(view.getName()).thenReturn(expectedNameWithWhitespace);
when(dataTypeSelectComponent.getValue()).thenReturn(expectedType);
when(dataTypeConstraintComponent.getValue()).thenReturn(expectedConstraint);
when(dataTypeListComponent.getValue()).thenReturn(expectedList);
when(dataTypeManager.get()).thenReturn(dataType);
final DataType updatedDataType = listItem.updateProperties(dataType);
assertEquals(expectedName, updatedDataType.getName());
assertEquals(expectedType, updatedDataType.getType());
assertEquals(expectedConstraint, updatedDataType.getConstraint());
assertEquals(expectedList, updatedDataType.isList());
}
use of org.kie.workbench.common.dmn.api.definition.model.ItemDefinition in project kie-wb-common by kiegroup.
the class DataTypeManagerTest method testGetItemDefinitionWithItemComponent.
@Test
public void testGetItemDefinitionWithItemComponent() {
final ItemDefinition expectedItemDefinition = mock(ItemDefinition.class);
final ItemDefinition tPerson = mock(ItemDefinition.class);
final QName tPersonQName = mock(QName.class);
final String tPersonValue = "tPersonRaw";
when(tPerson.getTypeRef()).thenReturn(tPersonQName);
when(tPersonQName.getLocalPart()).thenReturn(tPersonValue);
when(itemDefinitionUtils.findByName(tPersonValue)).thenReturn(Optional.of(expectedItemDefinition));
final ItemDefinition actualItemDefinition = manager.getItemDefinitionWithItemComponent(tPerson);
assertEquals(expectedItemDefinition, actualItemDefinition);
}
use of org.kie.workbench.common.dmn.api.definition.model.ItemDefinition in project kie-wb-common by kiegroup.
the class DataTypeManagerTest method testMakeDataTypeFromItemDefinitionWithAnImportedItemDefinition.
@Test
public void testMakeDataTypeFromItemDefinitionWithAnImportedItemDefinition() {
final ItemDefinition itemDefinition = mock(ItemDefinition.class);
final Name name = mock(Name.class);
final QName typeRefMock = mock(QName.class);
when(name.getValue()).thenReturn("id");
when(typeRefMock.getLocalPart()).thenReturn("string");
when(itemDefinition.getName()).thenReturn(name);
when(itemDefinition.getItemComponent()).thenReturn(new ArrayList<>());
when(itemDefinition.getTypeRef()).thenReturn(typeRefMock);
when(itemDefinition.isImported()).thenReturn(true);
when(itemDefinitionUtils.getConstraintText(any())).thenCallRealMethod();
when(itemDefinitionUtils.findByName(any())).thenReturn(Optional.empty());
final DataType dataType = manager.from(itemDefinition).get();
assertTrue(dataType.isReadOnly());
}
use of org.kie.workbench.common.dmn.api.definition.model.ItemDefinition in project kie-wb-common by kiegroup.
the class DataTypeManagerTest method makeItem.
private ItemDefinition makeItem(final String itemName, final String itemType, final boolean isCollection, final ItemDefinition... subItemDefinitions) {
final List<ItemDefinition> itemDefinitions = new ArrayList<>(Arrays.asList(subItemDefinitions));
final ItemDefinition itemDefinition = mock(ItemDefinition.class);
final Name name = mock(Name.class);
final QName typeRefMock = mock(QName.class);
final QName typeRef = subItemDefinitions.length == 0 ? typeRefMock : null;
when(name.getValue()).thenReturn(itemName);
when(typeRefMock.getLocalPart()).thenReturn(itemType);
when(itemDefinition.getName()).thenReturn(name);
when(itemDefinition.getItemComponent()).thenReturn(itemDefinitions);
when(itemDefinition.getTypeRef()).thenReturn(typeRef);
when(itemDefinition.isIsCollection()).thenReturn(isCollection);
return itemDefinition;
}
use of org.kie.workbench.common.dmn.api.definition.model.ItemDefinition in project kie-wb-common by kiegroup.
the class DataTypeManagerTest method makeItem.
private ItemDefinition makeItem(final String itemName, final String itemType, final String constraint, final ItemDefinition... subItemDefinitions) {
final ItemDefinition itemDefinition = makeItem(itemName, itemType, false, subItemDefinitions);
final UnaryTests unaryTests = mock(UnaryTests.class);
when(unaryTests.getText()).thenReturn(new Text(constraint));
when(itemDefinition.getAllowedValues()).thenReturn(unaryTests);
return itemDefinition;
}
Aggregations