Search in sources :

Example 46 with ItemDefinition

use of org.kie.workbench.common.dmn.api.definition.model.ItemDefinition in project kie-wb-common by kiegroup.

the class DataTypeCreateHandlerTest method testAppendWhenNameIsSet.

@Test
public void testAppendWhenNameIsSet() {
    final DataType dataType = mock(DataType.class);
    final DataType updatedDataType = mock(DataType.class);
    final DataTypeManager withDataType = mock(DataTypeManager.class);
    final ItemDefinition itemDefinition = mock(ItemDefinition.class);
    final List<DataType> expectedAffectedDataTypes = asList(mock(DataType.class), mock(DataType.class));
    final String existingName = "existing name";
    when(dataType.getName()).thenReturn(existingName);
    when(dataTypeManager.withDataType(dataType)).thenReturn(withDataType);
    when(recordEngine.update(updatedDataType)).thenReturn(expectedAffectedDataTypes);
    doReturn(updatedDataType).when(handler).updateDataTypeProperties(dataType, TOP_LEVEL_PARENT_UUID, itemDefinition);
    final List<DataType> actualAffectedDataTypes = handler.append(dataType, itemDefinition);
    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) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Example 47 with ItemDefinition

use of org.kie.workbench.common.dmn.api.definition.model.ItemDefinition in project kie-wb-common by kiegroup.

the class DataTypeCreateHandlerTest method testUpdateDataType.

@Test
public void testUpdateDataType() {
    final String parentUUID = "parentUUID";
    final DataType dataType = mock(DataType.class);
    final DataType expectedUpdateDataType = mock(DataType.class);
    final ItemDefinition itemDefinition = mock(ItemDefinition.class);
    final DataTypeManager dataTypeManagerWithDataType = mock(DataTypeManager.class);
    final DataTypeManager dataTypeManagerWithParentUUID = mock(DataTypeManager.class);
    final DataTypeManager dataTypeManagerWithItemDefinition = mock(DataTypeManager.class);
    final DataTypeManager dataTypeManagerWithIndexedItemDefinition = mock(DataTypeManager.class);
    final DataTypeManager dataTypeManagerWithItemDefinitionSubDataTypes = mock(DataTypeManager.class);
    final DataTypeManager dataTypeManagerWithUniqueName = mock(DataTypeManager.class);
    when(dataTypeManager.withDataType(dataType)).thenReturn(dataTypeManagerWithDataType);
    when(dataTypeManagerWithDataType.withParentUUID(parentUUID)).thenReturn(dataTypeManagerWithParentUUID);
    when(dataTypeManagerWithParentUUID.withItemDefinition(itemDefinition)).thenReturn(dataTypeManagerWithItemDefinition);
    when(dataTypeManagerWithItemDefinition.withIndexedItemDefinition()).thenReturn(dataTypeManagerWithIndexedItemDefinition);
    when(dataTypeManagerWithIndexedItemDefinition.withItemDefinitionSubDataTypes()).thenReturn(dataTypeManagerWithItemDefinitionSubDataTypes);
    when(dataTypeManagerWithItemDefinitionSubDataTypes.withUniqueName()).thenReturn(dataTypeManagerWithUniqueName);
    when(dataTypeManagerWithUniqueName.get()).thenReturn(expectedUpdateDataType);
    final DataType actualUpdatedDataType = handler.updateDataTypeProperties(dataType, parentUUID, itemDefinition);
    assertEquals(expectedUpdateDataType, actualUpdatedDataType);
}
Also used : DataTypeManager(org.kie.workbench.common.dmn.client.editors.types.common.DataTypeManager) 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 48 with ItemDefinition

use of org.kie.workbench.common.dmn.api.definition.model.ItemDefinition in project kie-wb-common by kiegroup.

the class DataTypeCreateHandlerTest method testInsertWhenAbsoluteParentDoesNotExist.

@Test
public void testInsertWhenAbsoluteParentDoesNotExist() {
    final String parentUUID = "parentUUID";
    final DataType dataType = mock(DataType.class);
    final DataType reference = mock(DataType.class);
    final DataType updatedDataType = mock(DataType.class);
    final ItemDefinition itemDefinition = mock(ItemDefinition.class);
    when(reference.getParentUUID()).thenReturn(parentUUID);
    doReturn(Optional.empty()).when(handler).lookupAbsoluteParent(reference);
    doReturn(updatedDataType).when(handler).updateDataTypeProperties(dataType, parentUUID, itemDefinition);
    final List<DataType> actualAffectedDataTypes = handler.insertSibling(dataType, reference, BELOW, itemDefinition);
    final List<DataType> expectedAffectedDataTypes = emptyList();
    verify(recordEngine).doUpdate(updatedDataType, itemDefinition);
    assertEquals(expectedAffectedDataTypes, actualAffectedDataTypes);
}
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 49 with ItemDefinition

use of org.kie.workbench.common.dmn.api.definition.model.ItemDefinition in project kie-wb-common by kiegroup.

the class DataTypeCreateHandlerTest method testInsertWhenAbsoluteParentExists.

@Test
public void testInsertWhenAbsoluteParentExists() {
    final String uuid = "uuid";
    final String name = "name";
    final DataType dataType = mock(DataType.class);
    final DataType reference = mock(DataType.class);
    final DataType dataType0 = mock(DataType.class);
    final DataType dataType2 = mock(DataType.class);
    final DataType absoluteParent = mock(DataType.class);
    final DataType updatedDataType = mock(DataType.class);
    final ItemDefinition itemDefinition = mock(ItemDefinition.class);
    final List<DataType> expectedAffectedDataTypes = asList(mock(DataType.class), mock(DataType.class));
    final List<DataType> siblings = new ArrayList<DataType>() {

        {
            add(dataType0);
            add(reference);
            add(dataType2);
        }
    };
    when(absoluteParent.getUUID()).thenReturn(uuid);
    when(reference.getName()).thenReturn(name);
    when(updatedDataType.getName()).thenReturn(name);
    when(absoluteParent.getSubDataTypes()).thenReturn(siblings);
    when(recordEngine.update(absoluteParent)).thenReturn(expectedAffectedDataTypes);
    doReturn(Optional.of(absoluteParent)).when(handler).lookupAbsoluteParent(reference);
    doReturn(updatedDataType).when(handler).updateDataTypeProperties(dataType, uuid, itemDefinition);
    final List<DataType> actualAffectedDataTypes = handler.insertSibling(dataType, reference, BELOW, itemDefinition);
    verify(recordEngine).doUpdate(dataType, itemDefinition);
    assertEquals(asList(dataType0, reference, updatedDataType, dataType2), siblings);
    assertEquals(expectedAffectedDataTypes, actualAffectedDataTypes);
}
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 50 with ItemDefinition

use of org.kie.workbench.common.dmn.api.definition.model.ItemDefinition in project kie-wb-common by kiegroup.

the class DataTypeCreateHandlerTest method testInsertNestedWhenReferenceTypeIsNotDefault.

@Test
public void testInsertNestedWhenReferenceTypeIsNotDefault() {
    final String parentUUID = "parentUUID";
    final String type = "tCity";
    final DataType dataType = mock(DataType.class);
    final DataType reference = mock(DataType.class);
    final DataType updatedDataType = mock(DataType.class);
    final DataTypeManager updatedDataTypeManager = mock(DataTypeManager.class);
    final DataTypeManager referenceDataTypeManager = mock(DataTypeManager.class);
    final ItemDefinition itemDefinition = mock(ItemDefinition.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(dataTypeManager, never()).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)

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