Search in sources :

Example 26 with DataModel

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

the class JavaRoasterModelDriverTest method modelVetoingTest.

@Test
public void modelVetoingTest() throws Exception {
    try {
        final SourceFilter pojo1Filter = javaType -> javaType.getName().equals("Pojo1");
        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));
        final JavaRoasterModelDriver javaRoasterModelDriver = new JavaRoasterModelDriver(ioService, rootPath, getClass().getClassLoader(), filterHolder);
        ModelDriverResult modelDriverResult = javaRoasterModelDriver.loadModel();
        DataModel dataModelOriginal = createModel();
        assertNotNull(modelDriverResult);
        assertNotNull(modelDriverResult.getDataModel());
        assertEquals(dataModelOriginal.getDataObjects().size() - 1, modelDriverResult.getDataModel().getDataObjects().size());
        for (DataObject dataObject : modelDriverResult.getDataModel().getDataObjects()) {
            if (!dataObject.getClassName().endsWith("Pojo1")) {
                DataModelerAssert.assertEqualsDataObject(dataObject, modelDriverResult.getDataModel().getDataObject(dataObject.getClassName()));
            } else {
                fail("Pojo1 should have been vetoed.");
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail("Test failed: " + e.getMessage());
    }
}
Also used : 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) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) DataModel(org.kie.workbench.common.services.datamodeller.core.DataModel) ModelDriverResult(org.kie.workbench.common.services.datamodeller.driver.model.ModelDriverResult) JavaRoasterModelDriver(org.kie.workbench.common.services.datamodeller.driver.impl.JavaRoasterModelDriver) NoSuchFileException(org.uberfire.java.nio.file.NoSuchFileException) IOException(java.io.IOException) Test(org.junit.Test)

Example 27 with DataModel

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

the class GenerationEngineTest method testAllFieldAnnotationsStringGeneration.

@Test
public void testAllFieldAnnotationsStringGeneration() {
    DataModel dataModel = dataModelOracleDriver.createModel();
    DataObject object1 = dataModel.addDataObject("com.test.Object1");
    ObjectProperty prop1 = object1.addProperty("attribute1", "java.lang.String");
    Annotation label = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.Label.class.getName()));
    label.setValue("value", "Attribute 1");
    Annotation desc = new AnnotationImpl(annotationDefinitions.get(org.kie.api.definition.type.Description.class.getName()));
    desc.setValue("value", "Description for Attribute 1");
    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");
    prop1.addAnnotation(label);
    prop1.addAnnotation(desc);
    prop1.addAnnotation(key);
    prop1.addAnnotation(position);
    GenerationContext generationContext = new GenerationContext(dataModelOracleDriver.createModel());
    try {
        String result = engine.generateAllAnnotationsString(generationContext, prop1);
        assertEquals(results.getProperty("testAllFieldAnnotationsStringGeneration"), 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) AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation) Test(org.junit.Test)

Example 28 with DataModel

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

the class GenerationEngineTest method testKeyFieldsConstructorStringGeneration.

@Test
public void testKeyFieldsConstructorStringGeneration() {
    DataModel dataModel = dataModelOracleDriver.createModel();
    DataObject object1 = dataModel.addDataObject("com.test.Object1");
    DataObject object2 = dataModel.addDataObject("com.test.sub.Object2");
    ObjectProperty prop1 = object1.addProperty("attribute1", "java.lang.String");
    ((ObjectPropertyImpl) prop1).setFileOrder(1);
    ObjectProperty prop2 = object1.addProperty("attribute2", "java.lang.Boolean");
    ((ObjectPropertyImpl) prop2).setFileOrder(2);
    ObjectProperty prop3 = object1.addProperty("attribute3", object2.getClassName());
    ((ObjectPropertyImpl) prop3).setFileOrder(0);
    ObjectProperty prop4 = object1.addProperty("attribute4", "long");
    ((ObjectPropertyImpl) 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()));
    prop3.addAnnotation(key);
    prop1.addAnnotation(key);
    prop2.addAnnotation(key);
    GenerationContext generationContext = new GenerationContext(dataModel);
    try {
        String result = engine.generateKeyFieldsConstructorString(generationContext, object1);
        assertEquals(results.getProperty("testKeyFieldsConstructorStringGeneration"), 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) AnnotationImpl(org.kie.workbench.common.services.datamodeller.core.impl.AnnotationImpl) Annotation(org.kie.workbench.common.services.datamodeller.core.Annotation) Test(org.junit.Test)

Example 29 with DataModel

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

the class GenerationEngineTest method testAllConstructorsStringGeneration.

@Test
public void testAllConstructorsStringGeneration() {
    DataModel dataModel = dataModelOracleDriver.createModel();
    DataObject object1 = dataModel.addDataObject("com.test.Object1");
    DataObject object2 = dataModel.addDataObject("com.test.sub.Object2");
    ObjectProperty prop1 = object1.addProperty("attribute1", "java.lang.String");
    ((ObjectPropertyImpl) prop1).setFileOrder(0);
    ObjectProperty prop2 = object1.addProperty("attribute2", "java.lang.Boolean");
    ((ObjectPropertyImpl) prop2).setFileOrder(1);
    ObjectProperty prop3 = object1.addProperty("attribute3", object2.getClassName());
    ((ObjectPropertyImpl) prop3).setFileOrder(2);
    ObjectProperty prop4 = object1.addProperty("attribute4", "long");
    ((ObjectPropertyImpl) 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");
    prop3.addAnnotation(key);
    prop3.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");
    prop4.addAnnotation(position);
    GenerationContext generationContext = new GenerationContext(dataModel);
    try {
        String result = engine.generateAllConstructorsString(generationContext, object1);
        assertEquals(results.getProperty("testAllConstructorsStringGeneration"), 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) 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 30 with DataModel

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

the class GenerationEngineTest method testFieldAccessorStringGeneration.

@Test
public void testFieldAccessorStringGeneration() {
    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.generateFieldGetterString(generationContext, property);
        assertEquals(results.getProperty("testFieldAccessorStringGeneration"), 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)

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