Search in sources :

Example 51 with ItemDefinition

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

Example 52 with ItemDefinition

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

Example 53 with ItemDefinition

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);
}
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 54 with ItemDefinition

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));
}
Also used : 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) Test(org.junit.Test)

Example 55 with ItemDefinition

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);
}
Also used : 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) 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