Search in sources :

Example 11 with DataModel

use of org.kie.workbench.common.services.datamodeller.core.DataModel 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 12 with DataModel

use of org.kie.workbench.common.services.datamodeller.core.DataModel 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 13 with DataModel

use of org.kie.workbench.common.services.datamodeller.core.DataModel 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 14 with DataModel

use of org.kie.workbench.common.services.datamodeller.core.DataModel 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 15 with DataModel

use of org.kie.workbench.common.services.datamodeller.core.DataModel 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

DataModel (org.kie.workbench.common.services.datamodeller.core.DataModel)31 DataObject (org.kie.workbench.common.services.datamodeller.core.DataObject)25 Test (org.junit.Test)21 ObjectProperty (org.kie.workbench.common.services.datamodeller.core.ObjectProperty)14 Annotation (org.kie.workbench.common.services.datamodeller.core.Annotation)9 AnnotationImpl (org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl)9 ArrayList (java.util.ArrayList)6 ObjectPropertyImpl (org.kie.workbench.common.services.datamodeller.core.impl.ObjectPropertyImpl)6 ModelDriverResult (org.kie.workbench.common.services.datamodeller.driver.model.ModelDriverResult)6 DataModelImpl (org.kie.workbench.common.services.datamodeller.core.impl.DataModelImpl)5 IOException (java.io.IOException)4 KieModule (org.kie.workbench.common.services.shared.project.KieModule)4 List (java.util.List)3 ModelDriverException (org.kie.workbench.common.services.datamodeller.driver.ModelDriverException)3 BufferedReader (java.io.BufferedReader)2 File (java.io.File)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 URI (java.net.URI)2 Arrays (java.util.Arrays)2