Search in sources :

Example 36 with DataObject

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

the class JavaRoasterModelDriverTest method methodUpdateTest.

@Test
public void methodUpdateTest() {
    try {
        // First read the MethodsUpdateTest
        Path methodsUpdateTestFilePath = rootPath.resolve("package4").resolve("MethodsUpdateTest.java");
        String source = ioService.readAllString(methodsUpdateTestFilePath);
        JavaClassSource methodsUpdateTestJavaClassSource = (JavaClassSource) Roaster.parse(source);
        ClassLoader classLoader = getClass().getClassLoader();
        ClassTypeResolver classTypeResolver = DriverUtils.createClassTypeResolver(methodsUpdateTestJavaClassSource, classLoader);
        final SourceFilter pojo1Filter = javaType -> false;
        final NestedClassFilter nestedClassFilter = javaType -> javaType.isClass() && javaType.getAnnotation(Generated.class) != null;
        final MethodFilter methodFilter = method -> !method.isConstructor() && method.getAnnotation(Generated.class) != null;
        FilterHolder filterHolder = mock(FilterHolder.class);
        when(filterHolder.getSourceFilters()).thenReturn(Collections.singleton(pojo1Filter));
        when(filterHolder.getNestedClassFilters()).thenReturn(Collections.singleton(nestedClassFilter));
        when(filterHolder.getMethodFilters()).thenReturn(Collections.singleton(methodFilter));
        JavaRoasterModelDriver javaRoasterModelDriver = new JavaRoasterModelDriver(ioService, rootPath, classLoader, filterHolder);
        ModelDriverResult result = javaRoasterModelDriver.loadDataObject(source, methodsUpdateTestFilePath);
        // 1) read the MethodsUpdateTest
        DataObject methodsUpdateTest = result.getDataModel().getDataObject("org.kie.workbench.common.services.datamodeller.driver.package4.MethodsUpdateTest");
        // 2) modify the MethodsUpdateTest according to the expected result.
        Method getTestStringMethod = methodsUpdateTest.getMethod("getTestString", Arrays.asList(List.class.getName()));
        Type methodReturnType = new TypeImpl(List.class.getName(), Arrays.asList(new TypeImpl(Integer.class.getName())));
        // List<Integer>
        getTestStringMethod.setReturnType(methodReturnType);
        Type parameterType1 = new TypeImpl(List.class.getName(), Arrays.asList(new TypeImpl(List.class.getName(), Arrays.asList(new TypeImpl("org.kie.workbench.common.services.datamodeller.driver.package4.MethodsUpdateTestResult")))));
        Parameter parameter1 = new ParameterImpl(parameterType1, "methodUpdateTestResultList");
        Type parameterType2 = new TypeImpl(int.class.getName());
        Parameter parameter2 = new ParameterImpl(parameterType2, "intParameter");
        getTestStringMethod.getParameters().clear();
        // ( List<List<MethodsUpdateTestResult>> methodUpdateTestResultList, int intParameter )
        getTestStringMethod.setParameters(Arrays.asList(parameter1, parameter2));
        getTestStringMethod.setBody("return Arrays.asList(1);");
        Method noOpMethodWithTestAnnotation = methodsUpdateTest.getMethod("noOpMethodWithTestAnnotation", Collections.EMPTY_LIST);
        noOpMethodWithTestAnnotation.setName("noOpMethodWithTestAnnotationUpdated");
        noOpMethodWithTestAnnotation.setBody("return 1;");
        noOpMethodWithTestAnnotation.setReturnType(new TypeImpl(Integer.class.getName()));
        // @TestAnnotation1("annotationParameterUpdated")
        Annotation testAnnotation = noOpMethodWithTestAnnotation.getAnnotation(TestAnnotation1.class.getName());
        testAnnotation.setValue("value", "annotationParameterUpdated");
        methodsUpdateTest.setName("MethodsUpdateTestResult");
        // 3) compare the modified data object with the expected data object.
        Path expectedFilePath = rootPath.resolve("package4").resolve("MethodsUpdateTestResult.java");
        String expectedSource = ioService.readAllString(expectedFilePath);
        JavaClassSource expectedJavaClassSource = (JavaClassSource) Roaster.parse(expectedSource);
        ModelDriverResult expectedResult = javaRoasterModelDriver.loadDataObject(expectedSource, expectedFilePath);
        DataObject methodsUpdateTestResult = expectedResult.getDataModel().getDataObject("org.kie.workbench.common.services.datamodeller.driver.package4.MethodsUpdateTestResult");
        // First check, the modified data object in memory should be the same as the readed from the model.
        DataModelerAssert.assertEqualsDataObject(methodsUpdateTestResult, methodsUpdateTest);
        // Second check, update the JavaClassSource corresponding to the MethodsUpdateTest
        javaRoasterModelDriver.updateSource(methodsUpdateTestJavaClassSource, methodsUpdateTest, new UpdateInfo(), classTypeResolver);
        ModelDriverResult updatedResult = javaRoasterModelDriver.loadDataObject(methodsUpdateTestJavaClassSource.toString(), methodsUpdateTestFilePath);
        // and now compare the updatedResult with the expected value.
        DataModelerAssert.assertEqualsDataObject(methodsUpdateTestResult, updatedResult.getDataModel().getDataObject("org.kie.workbench.common.services.datamodeller.driver.package4.MethodsUpdateTestResult"));
        logger.debug(methodsUpdateTestJavaClassSource.toString());
    } catch (Exception e) {
        e.printStackTrace();
        fail("Test failed: " + e.getMessage());
    }
}
Also used : Path(org.uberfire.java.nio.file.Path) Description(org.kie.api.definition.type.Description) Arrays(java.util.Arrays) ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) Timestamp(org.kie.api.definition.type.Timestamp) Label(org.kie.api.definition.type.Label) TestAnnotation1(org.kie.workbench.common.services.datamodeller.parser.test.TestAnnotation1) UpdateInfo(org.kie.workbench.common.services.datamodeller.driver.impl.UpdateInfo) LoggerFactory(org.slf4j.LoggerFactory) DataModelerAssert(org.kie.workbench.common.services.datamodeller.DataModelerAssert) Paths(org.uberfire.backend.server.util.Paths) Generated(javax.annotation.Generated) Matcher(java.util.regex.Matcher) Roaster(org.jboss.forge.roaster.Roaster) ClassAnnotation(org.kie.workbench.common.services.datamodeller.annotations.ClassAnnotation) SequenceGenerator(javax.persistence.SequenceGenerator) SimpleFileSystemProvider(org.uberfire.java.nio.fs.file.SimpleFileSystemProvider) JavaEnum(org.kie.workbench.common.services.datamodeller.core.JavaEnum) URI(java.net.URI) Instance(javax.enterprise.inject.Instance) Entity(javax.persistence.Entity) ParameterImpl(org.kie.workbench.common.services.datamodeller.core.impl.ParameterImpl) UniqueConstraint(javax.persistence.UniqueConstraint) ClassReactive(org.kie.api.definition.type.ClassReactive) JavaTypeInfo(org.kie.workbench.common.services.datamodeller.core.JavaTypeInfo) ENUM3(org.kie.workbench.common.services.datamodeller.annotations.ENUM3) NoSuchFileException(org.uberfire.java.nio.file.NoSuchFileException) List(java.util.List) AnnotationDefinition(org.kie.workbench.common.services.datamodeller.core.AnnotationDefinition) DataModelImpl(org.kie.workbench.common.services.datamodeller.core.impl.DataModelImpl) JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource) EnumsAnnotation(org.kie.workbench.common.services.datamodeller.annotations.EnumsAnnotation) AnnotationValuesAnnotation(org.kie.workbench.common.services.datamodeller.annotations.AnnotationValuesAnnotation) Role(org.kie.api.definition.type.Role) JavaClassImpl(org.kie.workbench.common.services.datamodeller.core.impl.JavaClassImpl) PrimitivesAnnotation(org.kie.workbench.common.services.datamodeller.annotations.PrimitivesAnnotation) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) JavaRoasterModelDriver(org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver) ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) Expires(org.kie.api.definition.type.Expires) TestAnnotation(org.kie.workbench.common.services.datamodeller.parser.test.TestAnnotation) MarkerAnnotation(org.kie.workbench.common.services.datamodeller.annotations.MarkerAnnotation) Parameter(org.kie.workbench.common.services.datamodeller.core.Parameter) Mock(org.mockito.Mock) Path(org.uberfire.java.nio.file.Path) RunWith(org.junit.runner.RunWith) DriverUtils(org.kie.workbench.common.services.datamodeller.util.DriverUtils) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation) Type(org.kie.workbench.common.services.datamodeller.core.Type) ArrayList(java.util.ArrayList) Table(javax.persistence.Table) TypeSafe(org.kie.api.definition.type.TypeSafe) Duration(org.kie.api.definition.type.Duration) DataModel(org.kie.workbench.common.services.datamodeller.core.DataModel) Before(org.junit.Before) Logger(org.slf4j.Logger) JavaEnumImpl(org.kie.workbench.common.services.datamodeller.core.impl.JavaEnumImpl) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) IOException(java.io.IOException) Test(org.junit.Test) Method(org.kie.workbench.common.services.datamodeller.core.Method) InputStreamReader(java.io.InputStreamReader) File(java.io.File) ImportImpl(org.kie.workbench.common.services.datamodeller.core.impl.ImportImpl) DataObjectImpl(org.kie.workbench.common.services.datamodeller.core.impl.DataObjectImpl) MethodImpl(org.kie.workbench.common.services.datamodeller.core.impl.MethodImpl) Mockito(org.mockito.Mockito) TestEnums(org.kie.workbench.common.services.datamodeller.annotations.TestEnums) AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl) Position(org.kie.api.definition.type.Position) JavaClass(org.kie.workbench.common.services.datamodeller.core.JavaClass) TypeImpl(org.kie.workbench.common.services.datamodeller.core.impl.TypeImpl) ModelDriverResult(org.kie.workbench.common.services.datamodeller.driver.model.ModelDriverResult) IOService(org.uberfire.io.IOService) BufferedReader(java.io.BufferedReader) Key(org.kie.api.definition.type.Key) Assert(org.junit.Assert) Collections(java.util.Collections) Visibility(org.kie.workbench.common.services.datamodeller.core.Visibility) InputStream(java.io.InputStream) TestAnnotation1(org.kie.workbench.common.services.datamodeller.parser.test.TestAnnotation1) JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource) Method(org.kie.workbench.common.services.datamodeller.core.Method) 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) NoSuchFileException(org.uberfire.java.nio.file.NoSuchFileException) IOException(java.io.IOException) Type(org.kie.workbench.common.services.datamodeller.core.Type) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) ParameterImpl(org.kie.workbench.common.services.datamodeller.core.impl.ParameterImpl) Parameter(org.kie.workbench.common.services.datamodeller.core.Parameter) List(java.util.List) ArrayList(java.util.ArrayList) ModelDriverResult(org.kie.workbench.common.services.datamodeller.driver.model.ModelDriverResult) ClassTypeResolver(org.kie.soup.project.datamodel.commons.types.ClassTypeResolver) JavaRoasterModelDriver(org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver) UpdateInfo(org.kie.workbench.common.services.datamodeller.driver.impl.UpdateInfo) TypeImpl(org.kie.workbench.common.services.datamodeller.core.impl.TypeImpl) Test(org.junit.Test)

Example 37 with DataObject

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

the class JavaRoasterModelDriverTest method createPojo1.

private DataObject createPojo1() {
    DataObject pojo1 = createDataObject("org.kie.workbench.common.services.datamodeller.driver.package1", "Pojo1", "org.kie.workbench.common.services.datamodeller.driver.package2.Pojo2");
    Annotation annotation;
    annotation = createAnnotation(Entity.class, "name", "Pojo1Entity");
    pojo1.addAnnotation(annotation);
    annotation = createAnnotation(Table.class, "name", "POJO1");
    annotation.setValue("catalog", "CATALOG_NAME");
    annotation.setValue("schema", "SCHEMA_NAME");
    // @UniqueConstraint( name = "constraint1", columnNames = {"column1", "column2"} )
    Annotation constraint1 = createAnnotation(UniqueConstraint.class);
    constraint1.setValue("name", "constraint1");
    constraint1.setValue("columnNames", createArrayParam("column1", "column2"));
    // @UniqueConstraint( name = "constraint2", columnNames = {"column3","column4"} )
    Annotation constraint2 = createAnnotation(UniqueConstraint.class);
    constraint2.setValue("name", "constraint2");
    constraint2.setValue("columnNames", createArrayParam("column3", "column4"));
    List<Annotation> uniqueConstraints = new ArrayList<Annotation>();
    uniqueConstraints.add(constraint1);
    uniqueConstraints.add(constraint2);
    // annotation.setValue( "uniqueConstraints", "{@UniqueConstraint(name=\"constraint1\",columnNames={\"column1\",\"column2\"}),@UniqueConstraint(name=\"constraint2\",columnNames={\"column3\",\"column4\"})}" );
    annotation.setValue("uniqueConstraints", uniqueConstraints);
    pojo1.addAnnotation(annotation);
    annotation = createAnnotation(SequenceGenerator.class, "name", "pojo1IdSeq");
    annotation.setValue("sequenceName", "POJO_ID_SEQ");
    annotation.setValue("allocationSize", new Integer("1"));
    pojo1.addAnnotation(annotation);
    annotation = createAnnotation(TypeSafe.class, "value", true);
    pojo1.addAnnotation(annotation);
    annotation = createAnnotation(Role.class, "value", Role.Type.EVENT.toString());
    pojo1.addAnnotation(annotation);
    annotation = createAnnotation(Label.class, "value", "Pojo1Label");
    pojo1.addAnnotation(annotation);
    annotation = createAnnotation(Description.class, "value", "Pojo1Description");
    pojo1.addAnnotation(annotation);
    annotation = createAnnotation(Duration.class, "value", "duration");
    pojo1.addAnnotation(annotation);
    annotation = createAnnotation(Timestamp.class, "value", "timestamp");
    pojo1.addAnnotation(annotation);
    annotation = createAnnotation(ClassReactive.class);
    pojo1.addAnnotation(annotation);
    annotation = createAnnotation(Expires.class, "value", "1h25m");
    pojo1.addAnnotation(annotation);
    ObjectProperty property = pojo1.addProperty("serialVersionUID", "long");
    property = pojo1.addProperty("field1", "java.lang.Character");
    annotation = createAnnotation(Position.class, "value", new Integer("0"));
    property.addAnnotation(annotation);
    annotation = createAnnotation(Key.class);
    property.addAnnotation(annotation);
    annotation = createAnnotation(Label.class, "value", "field1Label");
    property.addAnnotation(annotation);
    annotation = createAnnotation(Description.class, "value", "field1Description");
    property.addAnnotation(annotation);
    property = pojo1.addProperty("duration", "java.lang.Integer");
    annotation = createAnnotation(Position.class, "value", new Integer("1"));
    property.addAnnotation(annotation);
    property = pojo1.addProperty("timestamp", "java.util.Date");
    annotation = createAnnotation(Position.class, "value", new Integer("2"));
    property.addAnnotation(annotation);
    property = pojo1.addProperty("field2", "char");
    annotation = createAnnotation(Position.class, "value", new Integer("3"));
    property.addAnnotation(annotation);
    annotation = createAnnotation(Key.class);
    property.addAnnotation(annotation);
    annotation = createAnnotation(Label.class, "value", "field2Label");
    property.addAnnotation(annotation);
    annotation = createAnnotation(Description.class, "value", "field2Description");
    property.addAnnotation(annotation);
    return pojo1;
}
Also used : ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) Entity(javax.persistence.Entity) Table(javax.persistence.Table) Description(org.kie.api.definition.type.Description) Position(org.kie.api.definition.type.Position) SequenceGenerator(javax.persistence.SequenceGenerator) ArrayList(java.util.ArrayList) Label(org.kie.api.definition.type.Label) Duration(org.kie.api.definition.type.Duration) Timestamp(org.kie.api.definition.type.Timestamp) 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) TypeSafe(org.kie.api.definition.type.TypeSafe) Role(org.kie.api.definition.type.Role) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) ClassReactive(org.kie.api.definition.type.ClassReactive) Expires(org.kie.api.definition.type.Expires) Key(org.kie.api.definition.type.Key)

Example 38 with DataObject

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

the class JavaRoasterModelDriverTest method createMethodsUpdateTest.

private DataObject createMethodsUpdateTest() {
    DataObject dataObject = createDataObject("org.kie.workbench.common.services.datamodeller.driver.package4", "MethodsUpdateTest", null);
    Type methodReturnType = new TypeImpl(List.class.getName(), Arrays.asList(new TypeImpl(String.class.getName())));
    Parameter parameter = new ParameterImpl(new TypeImpl(List.class.getName(), Arrays.asList(new TypeImpl("org.kie.workbench.common.services.datamodeller.driver.package4.MethodsUpdateTest"))), "methodUpdateTestList");
    Method methodImpl = new MethodImpl("getTestString", Arrays.asList(parameter), "return Arrays.asList(\"testString\");", methodReturnType, Visibility.PUBLIC);
    Annotation testAnnotation = createAnnotation(TestAnnotation.class);
    methodImpl.addAnnotation(testAnnotation);
    dataObject.addMethod(methodImpl);
    methodImpl = new MethodImpl("noOpMethodWithTestAnnotation", Collections.EMPTY_LIST, "", new TypeImpl(void.class.getName()), Visibility.PUBLIC);
    Annotation testAnnotation1 = createAnnotation(Generated.class);
    testAnnotation1.setValue("value", "foo.bar.Generator");
    methodImpl.addAnnotation(testAnnotation1);
    Annotation testAnnotation2 = createAnnotation(TestAnnotation1.class);
    testAnnotation2.setValue("value", "annotationParameter");
    methodImpl.addAnnotation(testAnnotation2);
    dataObject.addMethod(methodImpl);
    return dataObject;
}
Also used : Type(org.kie.workbench.common.services.datamodeller.core.Type) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) MethodImpl(org.kie.workbench.common.services.datamodeller.core.impl.MethodImpl) ParameterImpl(org.kie.workbench.common.services.datamodeller.core.impl.ParameterImpl) Parameter(org.kie.workbench.common.services.datamodeller.core.Parameter) List(java.util.List) ArrayList(java.util.ArrayList) Method(org.kie.workbench.common.services.datamodeller.core.Method) 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 39 with DataObject

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

the class GenerationEngineTest method testJavaClassStringGeneration.

@Test
public void testJavaClassStringGeneration() {
    DataModel dataModel = dataModelOracleDriver.createModel();
    DataObject object1 = dataModel.addDataObject("com.test.Object1");
    DataObject object2 = dataModel.addDataObject("com.test.sub.Object2");
    Annotation label = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.Label.class.getName()));
    label.setValue("value", "Object1 Label");
    object1.addAnnotation(label);
    Annotation classReactive = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.ClassReactive.class.getName()));
    object1.addAnnotation(classReactive);
    Annotation propReactive = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.PropertyReactive.class.getName()));
    object1.addAnnotation(propReactive);
    Annotation role = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.Role.class.getName()));
    role.setValue("value", org.kie.api.definition.type.Role.Type.EVENT.name());
    object1.addAnnotation(role);
    ObjectProperty prop1 = object1.addProperty("attribute1", "java.lang.String");
    ObjectProperty prop2 = object1.addProperty("attribute2", "java.lang.Boolean");
    ObjectProperty prop3 = object1.addProperty("attribute3", object2.getClassName());
    ObjectProperty prop4 = object1.addProperty("attribute4", "long");
    Annotation key = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.Key.class.getName()));
    Annotation position = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.Position.class.getName()));
    position.setValue("value", "0");
    prop4.addAnnotation(key);
    prop4.addAnnotation(position);
    position = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.Position.class.getName()));
    position.setValue("value", "1");
    prop1.addAnnotation(key);
    prop1.addAnnotation(position);
    position = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.Position.class.getName()));
    position.setValue("value", "2");
    prop2.addAnnotation(key);
    prop2.addAnnotation(position);
    position = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.Position.class.getName()));
    position.setValue("value", "3");
    prop3.addAnnotation(position);
    GenerationContext generationContext = new GenerationContext(dataModel);
    try {
        String result = engine.generateJavaClassString(generationContext, object1);
        logger.debug(result);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) DataModel(org.kie.workbench.common.services.datamodeller.core.DataModel) Test(org.junit.Test)

Example 40 with DataObject

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

the class GenerationEngineTest method testAllFieldsConstructorStringGeneration.

@Test
public void testAllFieldsConstructorStringGeneration() {
    DataModel dataModel = dataModelOracleDriver.createModel();
    DataObject object1 = dataModel.addDataObject("com.test.Object1");
    DataObject object2 = dataModel.addDataObject("com.test.sub.Object2");
    object1.addProperty("attribute1", "java.lang.String");
    object1.addProperty("attribute2", "java.lang.Boolean");
    object1.addProperty("attribute3", object2.getClassName());
    GenerationContext generationContext = new GenerationContext(dataModel);
    try {
        String result = engine.generateAllFieldsConstructorString(generationContext, object1);
        assertEquals(results.getProperty("testAllFieldsConstructorStringGeneration"), result);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) DataModel(org.kie.workbench.common.services.datamodeller.core.DataModel) Test(org.junit.Test)

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