Search in sources :

Example 6 with DataObject

use of org.kie.workbench.common.dmn.api.editors.types.DataObject in project kie-wb-common by kiegroup.

the class DataTypeListTest method testInsertProperties.

@Test
public void testInsertProperties() {
    final DataObject dataObject = mock(DataObject.class);
    final String myImportedClass = "org.MyClass";
    final DataType existingDt = mock(DataType.class);
    final DataTypeListItem dtListItem = mock(DataTypeListItem.class);
    final Optional<DataTypeListItem> dtListItemOptional = Optional.of(dtListItem);
    final DataObjectProperty property1 = mock(DataObjectProperty.class);
    final DataObjectProperty property2 = mock(DataObjectProperty.class);
    final List<DataObjectProperty> properties = Arrays.asList(property1, property2);
    final DataType property1DataType = mock(DataType.class);
    final DataType property2DataType = mock(DataType.class);
    when(dataObject.getClassType()).thenReturn(myImportedClass);
    when(dataObject.getProperties()).thenReturn(properties);
    doReturn(Optional.of(existingDt)).when(dataTypeList).findDataTypeByName(myImportedClass);
    doReturn(dtListItemOptional).when(dataTypeList).findItem(existingDt);
    doReturn(property1DataType).when(dataTypeList).createNewDataType(property1);
    doReturn(property2DataType).when(dataTypeList).createNewDataType(property2);
    dataTypeList.insertProperties(dataObject);
    verify(dtListItem).insertNestedField(property1DataType);
    verify(dtListItem).insertNestedField(property2DataType);
}
Also used : DataObjectProperty(org.kie.workbench.common.dmn.api.editors.types.DataObjectProperty) DataObject(org.kie.workbench.common.dmn.api.editors.types.DataObject) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Example 7 with DataObject

use of org.kie.workbench.common.dmn.api.editors.types.DataObject in project kie-wb-common by kiegroup.

the class DataTypeListTest method testRemoveFullQualifiedNames.

@Test
public void testRemoveFullQualifiedNames() {
    final String do1Class = "something.class1";
    final String do2Class = "something.class2";
    final String do3Class = "something.class3";
    final String extractedName1 = "class1";
    final String extractedName2 = "class2";
    final String extractedName3 = "class3";
    final String builtName1 = "name1";
    final String builtName2 = "name2";
    final String builtName3 = "name3";
    final DataObject do1 = createDataObject(do1Class);
    final DataObject do2 = createDataObject(do2Class);
    final DataObject do3 = createDataObject(do3Class);
    final HashMap<String, Integer> namesCount = new HashMap<>();
    final HashMap<String, String> renamed = new HashMap<>();
    namesCount.put("trash", 0);
    renamed.put("trash.from.previous", "previous");
    doReturn(namesCount).when(dataTypeList).getImportedNamesOccurrencesCount();
    doReturn(renamed).when(dataTypeList).getRenamedImportedDataTypes();
    final List<DataObject> imported = Arrays.asList(do1, do2, do3);
    when(do1.getClassNameWithoutPackage()).thenReturn(extractedName1);
    when(do2.getClassNameWithoutPackage()).thenReturn(extractedName2);
    when(do3.getClassNameWithoutPackage()).thenReturn(extractedName3);
    doReturn(builtName1).when(dataTypeList).buildName(extractedName1, namesCount);
    doReturn(builtName2).when(dataTypeList).buildName(extractedName2, namesCount);
    doReturn(builtName3).when(dataTypeList).buildName(extractedName3, namesCount);
    doNothing().when(dataTypeList).updatePropertiesReferences(imported, renamed);
    dataTypeList.removeFullQualifiedNames(imported);
    verify(do1).getClassNameWithoutPackage();
    verify(dataTypeList).buildName(extractedName1, namesCount);
    assertTrue(renamed.containsKey(do1Class));
    assertEquals(builtName1, renamed.get(do1Class));
    verify(do1).setClassType(builtName1);
    verify(do2).getClassNameWithoutPackage();
    verify(dataTypeList).buildName(extractedName2, namesCount);
    assertTrue(renamed.containsKey(do2Class));
    assertEquals(builtName2, renamed.get(do2Class));
    verify(do2).setClassType(builtName2);
    verify(do3).getClassNameWithoutPackage();
    verify(dataTypeList).buildName(extractedName3, namesCount);
    assertTrue(renamed.containsKey(do3Class));
    assertEquals(builtName3, renamed.get(do3Class));
    verify(do3).setClassType(builtName3);
    assertEquals(3, renamed.size());
    verify(dataTypeList).updatePropertiesReferences(imported, renamed);
}
Also used : DataObject(org.kie.workbench.common.dmn.api.editors.types.DataObject) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 8 with DataObject

use of org.kie.workbench.common.dmn.api.editors.types.DataObject in project kie-wb-common by kiegroup.

the class ImportDataObjectModalTest method createDataObject.

private DataObject createDataObject(final String name) {
    final DataObject dataObject = mock(DataObject.class);
    when(dataObject.getClassNameWithoutPackage()).thenReturn(name);
    return dataObject;
}
Also used : DataObject(org.kie.workbench.common.dmn.api.editors.types.DataObject)

Example 9 with DataObject

use of org.kie.workbench.common.dmn.api.editors.types.DataObject in project kie-wb-common by kiegroup.

the class DataTypeListTest method testIsPropertyTypePresent.

@Test
public void testIsPropertyTypePresent() {
    final String someBuiltInType = BuiltInType.STRING.getName();
    final String anImportedType = "SomeImportedType";
    final String unknownType = "UnknownType";
    final DataObject dataObject = mock(DataObject.class);
    when(dataObject.getClassType()).thenReturn(anImportedType);
    final List<DataObject> imported = Arrays.asList(dataObject);
    boolean isPresent = dataTypeList.isPropertyTypePresent(someBuiltInType, imported);
    assertTrue("Built-in type is present", isPresent);
    isPresent = dataTypeList.isPropertyTypePresent(anImportedType, imported);
    assertTrue("Imported type is present", isPresent);
    isPresent = dataTypeList.isPropertyTypePresent(unknownType, imported);
    assertFalse("Type not imported or not built-in is not present", isPresent);
}
Also used : DataObject(org.kie.workbench.common.dmn.api.editors.types.DataObject) Test(org.junit.Test)

Example 10 with DataObject

use of org.kie.workbench.common.dmn.api.editors.types.DataObject in project kie-wb-common by kiegroup.

the class DataTypeListTest method testImportDataObjects.

@Test
public void testImportDataObjects() {
    final DataObject present = mock(DataObject.class);
    final DataObject notPresent = mock(DataObject.class);
    final List<DataObject> selectedDataObjects = asList(present, notPresent);
    final DataType presentDataType = mock(DataType.class);
    final DataType notPresentDataType = mock(DataType.class);
    final String notPresentClass = "not.present";
    final String importedPresentClass = "org.something.MyClass";
    final DataType existingDataType = mock(DataType.class);
    doReturn(presentDataType).when(dataTypeList).createNewDataType(present);
    doReturn(notPresentDataType).when(dataTypeList).createNewDataType(notPresent);
    doReturn(Optional.of(existingDataType)).when(dataTypeList).findDataTypeByName(importedPresentClass);
    doReturn(Optional.empty()).when(dataTypeList).findDataTypeByName(notPresentClass);
    doNothing().when(dataTypeList).replace(existingDataType, presentDataType);
    doNothing().when(dataTypeList).insertProperties(present);
    doNothing().when(dataTypeList).insertProperties(notPresent);
    doNothing().when(dataTypeList).insert(notPresentDataType);
    doNothing().when(dataTypeList).removeFullQualifiedNames(selectedDataObjects);
    when(notPresent.getClassType()).thenReturn(notPresentClass);
    when(present.getClassType()).thenReturn(importedPresentClass);
    dataTypeList.importDataObjects(selectedDataObjects);
    verify(dataTypeList).findDataTypeByName(importedPresentClass);
    verify(dataTypeList).replace(existingDataType, presentDataType);
    verify(dataTypeList).insertProperties(present);
    verify(dataTypeList, never()).insert(presentDataType);
    verify(dataTypeList).insert(notPresentDataType);
    verify(dataTypeList).insertProperties(notPresent);
    verify(dataTypeList).removeFullQualifiedNames(selectedDataObjects);
}
Also used : DataObject(org.kie.workbench.common.dmn.api.editors.types.DataObject) DataType(org.kie.workbench.common.dmn.client.editors.types.common.DataType) Test(org.junit.Test)

Aggregations

DataObject (org.kie.workbench.common.dmn.api.editors.types.DataObject)21 Test (org.junit.Test)13 TreeListItem (org.kie.workbench.common.dmn.client.editors.types.imported.treelist.TreeListItem)5 DataType (org.kie.workbench.common.dmn.client.editors.types.common.DataType)4 DataObjectProperty (org.kie.workbench.common.dmn.api.editors.types.DataObjectProperty)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Consumer (java.util.function.Consumer)1 ModuleDataModelOracle (org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle)1 BuiltInType (org.kie.workbench.common.dmn.api.property.dmn.types.BuiltInType)1 KieModule (org.kie.workbench.common.services.shared.project.KieModule)1 ServiceCallback (org.kie.workbench.common.stunner.core.client.service.ServiceCallback)1