Search in sources :

Example 1 with JavaEnum

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

the class ModuleDataModelOracleUtils method addEnumType.

private static void addEnumType(DataModel dataModel, String factType, ClassMetadata classMetadata) {
    String packageName = NamingUtils.extractPackageName(factType);
    String className = NamingUtils.extractClassName(factType);
    Visibility visibility = DriverUtils.buildVisibility(classMetadata.getModifiers());
    JavaEnum javaEnum = new JavaEnumImpl(packageName, className, visibility);
    dataModel.addJavaEnum(javaEnum, ObjectSource.DEPENDENCY);
}
Also used : JavaEnumImpl(org.kie.workbench.common.services.datamodeller.core.impl.JavaEnumImpl) JavaEnum(org.kie.workbench.common.services.datamodeller.core.JavaEnum) Visibility(org.kie.workbench.common.services.datamodeller.core.Visibility)

Example 2 with JavaEnum

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

the class JavaRoasterModelDriverTest method modelReadTest.

@Test
public void modelReadTest() {
    try {
        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, getClass().getClassLoader(), filterHolder);
        ModelDriverResult modelDriverResult = javaRoasterModelDriver.loadModel();
        DataModel dataModelOriginal = createModel();
        assertNotNull(modelDriverResult);
        assertNotNull(modelDriverResult.getDataModel());
        assertEquals(dataModelOriginal.getDataObjects().size(), modelDriverResult.getDataModel().getDataObjects().size());
        for (DataObject dataObject : dataModelOriginal.getDataObjects()) {
            DataModelerAssert.assertEqualsDataObject(dataObject, modelDriverResult.getDataModel().getDataObject(dataObject.getClassName()));
        }
        for (JavaEnum javaEnum : dataModelOriginal.getJavaEnums()) {
            DataModelerAssert.assertEqualsJavaEnum(javaEnum, modelDriverResult.getDataModel().getJavaEnum(javaEnum.getClassName()));
        }
        org.uberfire.backend.vfs.Path errorFile1 = Paths.convert(rootPath.resolve(ERROR_FILE1));
        org.uberfire.backend.vfs.Path errorFile2 = Paths.convert(rootPath.resolve(ERROR_FILE2));
        verifyErrorFilesWereDetected(modelDriverResult, errorFile1, errorFile2);
    } 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) 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) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) 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) JavaEnum(org.kie.workbench.common.services.datamodeller.core.JavaEnum) NoSuchFileException(org.uberfire.java.nio.file.NoSuchFileException) IOException(java.io.IOException) 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) Test(org.junit.Test)

Example 3 with JavaEnum

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

the class ModuleDataModelOracleUtilsTest method createExpectedExternalEnums.

private List<JavaEnum> createExpectedExternalEnums() {
    List<JavaEnum> result = new ArrayList<>();
    result.add(new JavaEnumImpl(TEST_PACKAGE, "ExternalEnum1", Visibility.PUBLIC));
    result.add(new JavaEnumImpl(TEST_PACKAGE, "ExternalEnum2", Visibility.PUBLIC));
    return result;
}
Also used : JavaEnumImpl(org.kie.workbench.common.services.datamodeller.core.impl.JavaEnumImpl) JavaEnum(org.kie.workbench.common.services.datamodeller.core.JavaEnum) ArrayList(java.util.ArrayList)

Example 4 with JavaEnum

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

Aggregations

JavaEnum (org.kie.workbench.common.services.datamodeller.core.JavaEnum)4 JavaEnumImpl (org.kie.workbench.common.services.datamodeller.core.impl.JavaEnumImpl)3 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 DataModel (org.kie.workbench.common.services.datamodeller.core.DataModel)2 DataObject (org.kie.workbench.common.services.datamodeller.core.DataObject)2 Visibility (org.kie.workbench.common.services.datamodeller.core.Visibility)2 DataModelImpl (org.kie.workbench.common.services.datamodeller.core.impl.DataModelImpl)2 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 URI (java.net.URI)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Matcher (java.util.regex.Matcher)1 Generated (javax.annotation.Generated)1 Instance (javax.enterprise.inject.Instance)1