Search in sources :

Example 41 with DataObject

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

the class GenerationEngineTest method testMaxFieldsForConstructorsStringGeneration2.

@Test
public void testMaxFieldsForConstructorsStringGeneration2() {
    DataModel dataModel = dataModelOracleDriver.createModel();
    DataObject object1 = dataModel.addDataObject("com.test.MaxFieldsForConstructor2");
    ObjectProperty prop1;
    // The constructor for this data object should be generated, since we don't reach the limit.
    for (int i = 0; i < GenerationTools.MAX_FIELDS_FOR_DEFAULT_CONSTRUCTOR; i++) {
        prop1 = object1.addProperty("attribute" + normalize(i), "java.lang.String");
    }
    GenerationContext generationContext = new GenerationContext(dataModel);
    try {
        String result = engine.generateAllConstructorsString(generationContext, object1);
        assertEquals(results.getProperty("testMaxFieldsForConstructorsStringGeneration2"), result);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) DataModel(org.kie.workbench.common.services.datamodeller.core.DataModel) Test(org.junit.Test)

Example 42 with DataObject

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

the class GenerationEngineTest method testFieldStringGeneration.

@Test
public void testFieldStringGeneration() {
    DataModel dataModel = dataModelOracleDriver.createModel();
    DataObject object = dataModel.addDataObject("com.test.Object1");
    ObjectProperty property = object.addProperty("attribute1", "java.lang.String");
    GenerationContext generationContext = new GenerationContext(dataModel);
    try {
        String result = engine.generateFieldString(generationContext, property);
        assertEquals(results.getProperty("testFieldStringGeneration"), result);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) DataModel(org.kie.workbench.common.services.datamodeller.core.DataModel) Test(org.junit.Test)

Example 43 with DataObject

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

the class GenerationEngineTest method testEqualsStringGeneration.

@Test
public void testEqualsStringGeneration() {
    DataModel dataModel = dataModelOracleDriver.createModel();
    DataObject object1 = dataModel.addDataObject("com.test.Object1");
    DataObject object2 = dataModel.addDataObject("com.test.sub.Object2");
    ObjectPropertyImpl prop1 = (ObjectPropertyImpl) object1.addProperty("attribute1", "java.lang.String");
    prop1.setFileOrder(0);
    ObjectPropertyImpl prop2 = (ObjectPropertyImpl) object1.addProperty("attribute2", "java.lang.Boolean");
    prop2.setFileOrder(1);
    ObjectPropertyImpl prop3 = (ObjectPropertyImpl) object1.addProperty("attribute3", object2.getClassName());
    prop3.setFileOrder(2);
    ObjectPropertyImpl prop4 = (ObjectPropertyImpl) object1.addProperty("attribute4", "long");
    prop4.setFileOrder(3);
    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.generateEqualsString(generationContext, object1);
        assertEquals(results.getProperty("testEqualsStringGeneration"), result);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation) ObjectPropertyImpl(org.kie.workbench.common.services.datamodeller.core.impl.ObjectPropertyImpl) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) DataModel(org.kie.workbench.common.services.datamodeller.core.DataModel) Test(org.junit.Test)

Example 44 with DataObject

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

the class GenerationEngineTest method testMaxFieldsForConstructorsStringGeneration1.

@Test
public void testMaxFieldsForConstructorsStringGeneration1() {
    DataModel dataModel = dataModelOracleDriver.createModel();
    DataObject object1 = dataModel.addDataObject("com.test.MaxFieldsForConstructor1");
    ObjectProperty prop1;
    // The constructor for this data object should be generated, since we don't reach the limit.
    for (int i = 0; i < GenerationTools.MAX_FIELDS_FOR_DEFAULT_CONSTRUCTOR - 1; i++) {
        prop1 = object1.addProperty("attribute" + normalize(i), "java.lang.String");
        ((ObjectPropertyImpl) prop1).setFileOrder(i);
    }
    GenerationContext generationContext = new GenerationContext(dataModel);
    try {
        String result = engine.generateAllConstructorsString(generationContext, object1);
        assertEquals(results.getProperty("testMaxFieldsForConstructorsStringGeneration1"), result);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) ObjectPropertyImpl(org.kie.workbench.common.services.datamodeller.core.impl.ObjectPropertyImpl) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) DataModel(org.kie.workbench.common.services.datamodeller.core.DataModel) Test(org.junit.Test)

Example 45 with DataObject

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

the class GenerationEngineTest method testClassWithNestedClassStringGeneration.

@Test
public void testClassWithNestedClassStringGeneration() {
    DataModel dataModel = dataModelOracleDriver.createModel();
    DataObject object = dataModel.addDataObject("com.test.Object1");
    GenerationContext generationContext = new GenerationContext(dataModel);
    try {
        String result = engine.generateNestedClassString(generationContext, object);
        assertEquals(results.getProperty("testNestedClassStringGeneration"), results.getProperty("testNestedClassStringGeneration"), 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