Search in sources :

Example 31 with DataObject

use of org.kie.workbench.common.services.datamodeller.core.DataObject in project kie-wb-common by kiegroup.

the class JavaRoasterModelDriverTest method createNestedClassUpdateTestResult.

private DataObject createNestedClassUpdateTestResult() {
    DataObject dataObject = createDataObject("org.kie.workbench.common.services.datamodeller.driver.package5", "NestedClassUpdateTestResult", null);
    JavaClass nestedClass = new JavaClassImpl("", "UpdatedNestedClass");
    nestedClass.addInterface("java.io.Serializable");
    nestedClass.addInterface("ParametrizedInterface<Double>");
    Annotation generatedAnnotation = createAnnotation(Generated.class);
    generatedAnnotation.setValue("value", Arrays.asList("foo.bar.Generator"));
    nestedClass.addAnnotation(generatedAnnotation);
    MethodImpl method = new MethodImpl("updatedMethod", Collections.EMPTY_LIST, "", new TypeImpl(void.class.getName()), Visibility.PUBLIC);
    generatedAnnotation = createAnnotation(Generated.class);
    generatedAnnotation.setValue("value", Arrays.asList("foo.bar.Generator"));
    method.addAnnotation(generatedAnnotation);
    nestedClass.addMethod(method);
    dataObject.addNestedClass(nestedClass);
    return dataObject;
}
Also used : JavaClassImpl(org.kie.workbench.common.services.datamodeller.core.impl.JavaClassImpl) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) Generated(javax.annotation.Generated) JavaClass(org.kie.workbench.common.services.datamodeller.core.JavaClass) MethodImpl(org.kie.workbench.common.services.datamodeller.core.impl.MethodImpl) ClassAnnotation(org.kie.workbench.common.services.datamodeller.annotations.ClassAnnotation) EnumsAnnotation(org.kie.workbench.common.services.datamodeller.annotations.EnumsAnnotation) AnnotationValuesAnnotation(org.kie.workbench.common.services.datamodeller.annotations.AnnotationValuesAnnotation) PrimitivesAnnotation(org.kie.workbench.common.services.datamodeller.annotations.PrimitivesAnnotation) TestAnnotation(org.kie.workbench.common.services.datamodeller.parser.test.TestAnnotation) MarkerAnnotation(org.kie.workbench.common.services.datamodeller.annotations.MarkerAnnotation) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation) TypeImpl(org.kie.workbench.common.services.datamodeller.core.impl.TypeImpl)

Example 32 with DataObject

use of org.kie.workbench.common.services.datamodeller.core.DataObject in project kie-wb-common by kiegroup.

the class JavaRoasterModelDriverTest method createAnnotationsUpdateTest.

private DataObject createAnnotationsUpdateTest() {
    DataObject dataObject = createDataObject("org.kie.workbench.common.services.datamodeller.driver.package3", "AnnotationsUpdateTest", null);
    dataObject.addAnnotation(createAnnotationValuesAnnotation());
    dataObject.addAnnotation(createClassAnnotation());
    dataObject.addAnnotation(createEnumsAnnotation());
    dataObject.addAnnotation(createPrimitivesAnnotation());
    return dataObject;
}
Also used : DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject)

Example 33 with DataObject

use of org.kie.workbench.common.services.datamodeller.core.DataObject in project kie-wb-common by kiegroup.

the class ModuleDataModelOracleUtilsTest method loadExternalDepsTest.

@Test
public void loadExternalDepsTest() {
    DataModel dataModel = new DataModelImpl();
    try {
        ModuleDataModelOracleUtils.loadExternalDependencies(dataModel, dataModelOracle, ModuleDataModelOracleUtilsTest.class.getClassLoader());
        // check that the expected classes were properly loaded.
        List<DataObject> expectedExternalClasses = createExpectedExternalClasses();
        assertEquals(expectedExternalClasses.size(), dataModel.getExternalClasses().size());
        for (DataObject externalClass : dataModel.getExternalClasses()) {
            // properties read from DMO are not necessary sorted.
            sortProperties(externalClass);
            assertTrue(expectedExternalClasses.contains(externalClass));
        }
        // check that the expected enums where properly loaded.
        List<JavaEnum> expectedExternalEnums = createExpectedExternalEnums();
        assertEquals(expectedExternalEnums.size(), dataModel.getDependencyJavaEnums().size());
        for (JavaEnum externalEnum : dataModel.getDependencyJavaEnums()) {
            assertTrue(expectedExternalEnums.contains(externalEnum));
        }
    } catch (Exception e) {
        fail("External deps loading test failed: " + e.getMessage());
    }
}
Also used : DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) JavaEnum(org.kie.workbench.common.services.datamodeller.core.JavaEnum) DataModel(org.kie.workbench.common.services.datamodeller.core.DataModel) DataModelImpl(org.kie.workbench.common.services.datamodeller.core.impl.DataModelImpl) Test(org.junit.Test)

Example 34 with DataObject

use of org.kie.workbench.common.services.datamodeller.core.DataObject in project kie-wb-common by kiegroup.

the class ModuleDataModelOracleUtilsTest method createExpectedExternalClasses.

private List<DataObject> createExpectedExternalClasses() {
    List<DataObject> result = new ArrayList<>();
    DataObject dataObject1 = new DataObjectImpl(TEST_PACKAGE, "ExternalPojo1");
    dataObject1.setSuperClassName(Object.class.getName());
    dataObject1.addProperty("field1", String.class.getName());
    dataObject1.addProperty("field2", String.class.getName());
    result.add(dataObject1);
    DataObject dataObject2 = new DataObjectImpl(TEST_PACKAGE, "ExternalPojo2");
    dataObject2.setSuperClassName(Object.class.getName());
    dataObject2.addProperty("field3", String.class.getName());
    dataObject2.addProperty("field4", String.class.getName());
    result.add(dataObject2);
    return result;
}
Also used : DataObjectImpl(org.kie.workbench.common.services.datamodeller.core.impl.DataObjectImpl) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) ArrayList(java.util.ArrayList) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject)

Example 35 with DataObject

use of org.kie.workbench.common.services.datamodeller.core.DataObject in project kie-wb-common by kiegroup.

the class JavaRoasterModelDriverTest method createAnnotationsUpdateTestResult.

private DataObject createAnnotationsUpdateTestResult() {
    DataObject dataObject = createDataObject("org.kie.workbench.common.services.datamodeller.driver.package3", "AnnotationsUpdateTestResult", null);
    dataObject.addAnnotation(createMarkerAnnotation());
    /*
        @PrimitivesAnnotation( byteParam = ( byte ) 2, byteArrayParam = { 3, 4 },
        shortParam = 2, shortArrayParam = { 3, 4 },
        stringParam = "2", stringArrayParam = { "3", "4" }
         */
    Annotation primitivesAnnotation = createAnnotation(PrimitivesAnnotation.class);
    primitivesAnnotation.setValue("byteParam", new Byte("2"));
    // primitivesAnnotation.setValue( "byteArrayParam", "{3,4}" );
    primitivesAnnotation.setValue("byteArrayParam", createArrayParam((byte) 3, (byte) 4));
    primitivesAnnotation.setValue("shortParam", new Short("2"));
    primitivesAnnotation.setValue("shortArrayParam", createArrayParam((short) 3, (short) 4));
    primitivesAnnotation.setValue("stringParam", "2");
    primitivesAnnotation.setValue("stringArrayParam", createArrayParam("3", "4"));
    dataObject.addAnnotation(primitivesAnnotation);
    /*
        @EnumsAnnotation( enum1Param = TestEnums.ENUM1.VALUE2, enum1ArrayParam = { TestEnums.ENUM1.VALUE3 },
        enum2Param = TestEnums.ENUM2.VALUE2, enum2ArrayParam = { TestEnums.ENUM2.VALUE3 }
        )
        */
    Annotation enumsAnnotation = createAnnotation(EnumsAnnotation.class);
    enumsAnnotation.setValue("enum1Param", TestEnums.ENUM1.VALUE2.toString());
    // enumsAnnotation.setValue( "enum1ArrayParam", "{TestEnums.ENUM1.VALUE3}" );
    enumsAnnotation.setValue("enum1ArrayParam", createEnumArrayParam(TestEnums.ENUM1.VALUE3));
    enumsAnnotation.setValue("enum2Param", TestEnums.ENUM2.VALUE2.toString());
    // enumsAnnotation.setValue( "enum2ArrayParam", "{TestEnums.ENUM2.VALUE3}" );
    enumsAnnotation.setValue("enum2ArrayParam", createEnumArrayParam(TestEnums.ENUM2.VALUE3));
    dataObject.addAnnotation(enumsAnnotation);
    /*
        @ClassAnnotation( classParam = java.util.Collection.class,
                classArrayParam = { List.class }
        )
        */
    Annotation classAnnotation = createAnnotation(ClassAnnotation.class);
    classAnnotation.setValue("classParam", "java.util.Collection.class");
    classAnnotation.setValue("classArrayParam", createArrayParam("List.class"));
    dataObject.addAnnotation(classAnnotation);
    /*
        @AnnotationValuesAnnotation( primitivesParam = @PrimitivesAnnotation( stringParam = "\"line1\" \n line2 \\ \n line3" ),
            primitivesArrayParam = { @PrimitivesAnnotation( intParam = 2 ), @PrimitivesAnnotation( intParam = 3 ) },
            enumsParam = @EnumsAnnotation( enum1Param = TestEnums.ENUM1.VALUE2 ),
            enumsArrayParam = { @EnumsAnnotation( enum1Param = TestEnums.ENUM1.VALUE2 ), @EnumsAnnotation( enum1Param = TestEnums.ENUM1.VALUE3 ) },
            classAnnotationParam = @ClassAnnotation( classParam = Set.class ),
            classAnnotationArrayParam = { @ClassAnnotation( classParam = Set.class ), @ClassAnnotation( classParam = Set.class ) }
        )
        */
    Annotation annotationValuesAnnotation = createAnnotation(AnnotationValuesAnnotation.class);
    // annotation.setValue( "primitivesParam", "@PrimitivesAnnotation(stringParam="\"line1\" \n line2 \\ \n line3")" );
    Annotation primitivesParamValue = createAnnotation(PrimitivesAnnotation.class);
    // construct the value -> "\"line1\" \n line2 \\ \n line3"
    StringBuilder stringParamBuilder = new StringBuilder();
    stringParamBuilder.append('"').append("line1").append('"').append(" ").append('\n');
    stringParamBuilder.append(" line2 ").append('\\').append(" ").append('\n');
    stringParamBuilder.append(" line3");
    primitivesParamValue.setValue("stringParam", stringParamBuilder.toString());
    annotationValuesAnnotation.setValue("primitivesParam", primitivesParamValue);
    // @PrimitivesAnnotation(intParam=1)
    Annotation primitiveValue1 = createAnnotation(PrimitivesAnnotation.class);
    primitiveValue1.setValue("intParam", 2);
    // @PrimitivesAnnotation(intParam=3)
    Annotation primitiveValue2 = createAnnotation(PrimitivesAnnotation.class);
    primitiveValue2.setValue("intParam", 3);
    List<Annotation> primitivesArrayParamValue = new ArrayList<Annotation>();
    primitivesArrayParamValue.add(primitiveValue1);
    primitivesArrayParamValue.add(primitiveValue2);
    // annotation.setValue( "primitivesArrayParam", "{@PrimitivesAnnotation(intParam=2),@PrimitivesAnnotation(intParam=3)}" );
    annotationValuesAnnotation.setValue("primitivesArrayParam", primitivesArrayParamValue);
    // annotation.setValue( "enumsParam", "@EnumsAnnotation(enum1Param=TestEnums.ENUM1.VALUE2)" );
    Annotation enumsParamValue = createAnnotation(EnumsAnnotation.class);
    enumsParamValue.setValue("enum1Param", TestEnums.ENUM1.VALUE2.toString());
    annotationValuesAnnotation.setValue("enumsParam", enumsParamValue);
    // annotation.setValue( "enumsArrayParam", "{@EnumsAnnotation(enum1Param=TestEnums.ENUM1.VALUE2),@EnumsAnnotation(enum1Param=TestEnums.ENUM1.VALUE3)}" );
    Annotation enumArrayParam1 = createAnnotation(EnumsAnnotation.class);
    enumArrayParam1.setValue("enum1Param", TestEnums.ENUM1.VALUE2.toString());
    Annotation enumArrayParam2 = createAnnotation(EnumsAnnotation.class);
    enumArrayParam2.setValue("enum1Param", TestEnums.ENUM1.VALUE3.toString());
    List<Annotation> enumVarrayValues = new ArrayList<Annotation>();
    enumVarrayValues.add(enumArrayParam1);
    enumVarrayValues.add(enumArrayParam2);
    annotationValuesAnnotation.setValue("enumsArrayParam", enumVarrayValues);
    // annotation.setValue( "classAnnotationParam", "@ClassAnnotation(classParam=Set.class)" );
    Annotation classAnnotationParamValue = createAnnotation(ClassAnnotation.class);
    classAnnotationParamValue.setValue("classParam", "Set.class");
    annotationValuesAnnotation.setValue("classAnnotationParam", classAnnotationParamValue);
    // annotation.setValue( "classAnnotationArrayParam", "{@ClassAnnotation(classParam=Set.class),@ClassAnnotation(classParam=Set.class)}" );
    Annotation classAnnotationArrayParamValue1 = createAnnotation(ClassAnnotation.class);
    classAnnotationArrayParamValue1.setValue("classParam", "Set.class");
    Annotation classAnnotationArrayParamValue2 = createAnnotation(ClassAnnotation.class);
    classAnnotationArrayParamValue2.setValue("classParam", "Set.class");
    List<Annotation> classAnnotationArrayParamValue = new ArrayList<Annotation>();
    classAnnotationArrayParamValue.add(classAnnotationArrayParamValue1);
    classAnnotationArrayParamValue.add(classAnnotationArrayParamValue2);
    annotationValuesAnnotation.setValue("classAnnotationArrayParam", classAnnotationArrayParamValue);
    dataObject.addAnnotation(annotationValuesAnnotation);
    return dataObject;
}
Also used : DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) ArrayList(java.util.ArrayList) ClassAnnotation(org.kie.workbench.common.services.datamodeller.annotations.ClassAnnotation) EnumsAnnotation(org.kie.workbench.common.services.datamodeller.annotations.EnumsAnnotation) AnnotationValuesAnnotation(org.kie.workbench.common.services.datamodeller.annotations.AnnotationValuesAnnotation) PrimitivesAnnotation(org.kie.workbench.common.services.datamodeller.annotations.PrimitivesAnnotation) TestAnnotation(org.kie.workbench.common.services.datamodeller.parser.test.TestAnnotation) MarkerAnnotation(org.kie.workbench.common.services.datamodeller.annotations.MarkerAnnotation) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation)

Aggregations

DataObject (org.kie.workbench.common.services.datamodeller.core.DataObject)95 Test (org.junit.Test)45 ObjectProperty (org.kie.workbench.common.services.datamodeller.core.ObjectProperty)40 DataModel (org.kie.workbench.common.services.datamodeller.core.DataModel)29 Annotation (org.kie.workbench.common.services.datamodeller.core.Annotation)28 DataObjectImpl (org.kie.workbench.common.services.datamodeller.core.impl.DataObjectImpl)21 ArrayList (java.util.ArrayList)17 AnnotationValuesAnnotation (org.kie.workbench.common.services.datamodeller.annotations.AnnotationValuesAnnotation)17 ClassAnnotation (org.kie.workbench.common.services.datamodeller.annotations.ClassAnnotation)17 EnumsAnnotation (org.kie.workbench.common.services.datamodeller.annotations.EnumsAnnotation)17 MarkerAnnotation (org.kie.workbench.common.services.datamodeller.annotations.MarkerAnnotation)17 PrimitivesAnnotation (org.kie.workbench.common.services.datamodeller.annotations.PrimitivesAnnotation)17 TestAnnotation (org.kie.workbench.common.services.datamodeller.parser.test.TestAnnotation)17 AnnotationImpl (org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl)16 DomainEditorBaseTest (org.kie.workbench.common.screens.datamodeller.client.widgets.DomainEditorBaseTest)15 MethodImpl (org.kie.workbench.common.services.datamodeller.core.impl.MethodImpl)12 List (java.util.List)11 TypeImpl (org.kie.workbench.common.services.datamodeller.core.impl.TypeImpl)11 Method (org.kie.workbench.common.services.datamodeller.core.Method)10 Generated (javax.annotation.Generated)8