Search in sources :

Example 56 with ItemDefinition

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

Example 57 with ItemDefinition

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

Example 58 with ItemDefinition

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());
}
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) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Test(org.junit.Test)

Example 59 with ItemDefinition

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

Example 60 with ItemDefinition

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

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