Search in sources :

Example 61 with ItemDefinition

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());
}
Also used : ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Example 62 with ItemDefinition

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);
}
Also used : QName(org.kie.workbench.common.dmn.api.property.dmn.QName) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) Test(org.junit.Test)

Example 63 with ItemDefinition

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());
}
Also used : QName(org.kie.workbench.common.dmn.api.property.dmn.QName) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Test(org.junit.Test)

Example 64 with 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 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;
}
Also used : QName(org.kie.workbench.common.dmn.api.property.dmn.QName) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) ArrayList(java.util.ArrayList) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name)

Example 65 with 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;
}
Also used : ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) Text(org.kie.workbench.common.dmn.api.property.dmn.Text) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests)

Aggregations

ItemDefinition (org.kie.workbench.common.dmn.api.definition.model.ItemDefinition)119 Test (org.junit.Test)86 DataType (org.kie.workbench.common.dmn.client.editors.types.common.DataType)39 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)37 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)36 ArrayList (java.util.ArrayList)18 Definitions (org.kie.workbench.common.dmn.api.definition.model.Definitions)16 UnaryTests (org.kie.workbench.common.dmn.api.definition.model.UnaryTests)9 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)8 DecisionTable (org.kie.workbench.common.dmn.api.definition.model.DecisionTable)7 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)7 JSITItemDefinition (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITItemDefinition)7 Text (org.kie.workbench.common.dmn.api.property.dmn.Text)6 DataTypeManager (org.kie.workbench.common.dmn.client.editors.types.common.DataTypeManager)6 QName (javax.xml.namespace.QName)4 Import (org.kie.workbench.common.dmn.api.definition.model.Import)4 InputClause (org.kie.workbench.common.dmn.api.definition.model.InputClause)4 RefreshDataTypesListEvent (org.kie.workbench.common.dmn.client.editors.types.common.events.RefreshDataTypesListEvent)4 DMNGraphUtils (org.kie.workbench.common.dmn.client.graph.DMNGraphUtils)4 PMMLDocumentMetadata (org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata)3