Search in sources :

Example 21 with IncrementalDataModelService

use of org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService in project kie-wb-common by kiegroup.

the class PackageDataModelOracleTest method testSubClass.

@Test
public void testSubClass() throws IOException {
    final ModuleDataModelOracle moduleLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addClass(TestSubClass.class).build();
    final PackageDataModelOracle packageLoader = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator(), "org.kie.workbench.common.widgets.client.datamodel.testclasses").setModuleOracle(moduleLoader).build();
    // Emulate server-to-client conversions
    final Caller<IncrementalDataModelService> service = new MockIncrementalDataModelServiceCaller(packageLoader);
    final AsyncPackageDataModelOracle oracle = new AsyncPackageDataModelOracleImpl(service, validatorInstance);
    final PackageDataModelOracleBaselinePayload dataModel = new PackageDataModelOracleBaselinePayload();
    dataModel.setPackageName(packageLoader.getPackageName());
    dataModel.setModelFields(packageLoader.getModuleModelFields());
    dataModel.setFieldParametersType(packageLoader.getModuleFieldParametersType());
    PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
    assertEquals(1, oracle.getFactTypes().length);
    assertEquals(TestSubClass.class.getSimpleName(), oracle.getFactTypes()[0]);
    oracle.getFieldCompletions(TestSubClass.class.getSimpleName(), new Callback<ModelField[]>() {

        @Override
        public void callback(final ModelField[] fields) {
            assertEquals(4, fields.length);
            for (ModelField field : fields) {
                if ("this".equals(field.getName())) {
                    assertEquals(ModelField.FIELD_ORIGIN.SELF, field.getOrigin());
                } else if ("field1".equals(field.getName())) {
                    assertEquals(ModelField.FIELD_ORIGIN.INHERITED, field.getOrigin());
                } else if ("field2".equals(field.getName())) {
                    assertEquals(ModelField.FIELD_ORIGIN.DECLARED, field.getOrigin());
                } else if ("list".equals(field.getName())) {
                    assertEquals(ModelField.FIELD_ORIGIN.DELEGATED, field.getOrigin());
                }
            }
        }
    });
    assertEquals(DataType.TYPE_THIS, oracle.getFieldType(TestSubClass.class.getSimpleName(), "this"));
    assertEquals(TestSubClass.class.getSimpleName(), oracle.getFieldClassName(TestSubClass.class.getSimpleName(), "this"));
    assertEquals(DataType.TYPE_STRING, oracle.getFieldType(TestSubClass.class.getSimpleName(), "field1"));
    assertEquals(String.class.getName(), oracle.getFieldClassName(TestSubClass.class.getSimpleName(), "field1"));
    assertEquals(DataType.TYPE_STRING, oracle.getFieldType(TestSubClass.class.getSimpleName(), "field2"));
    assertEquals(String.class.getName(), oracle.getFieldClassName(TestSubClass.class.getSimpleName(), "field2"));
    assertEquals(DataType.TYPE_COLLECTION, oracle.getFieldType(TestSubClass.class.getSimpleName(), "list"));
    assertEquals(List.class.getName(), oracle.getFieldClassName(TestSubClass.class.getSimpleName(), "list"));
    assertEquals(String.class.getName(), oracle.getParametricFieldType(TestSubClass.class.getSimpleName(), "list"));
}
Also used : Path(org.uberfire.backend.vfs.Path) IncrementalDataModelService(org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService) ModuleDataModelOracle(org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) PackageDataModelOracleBaselinePayload(org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload) RawMVELEvaluator(org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator) TestSubClass(org.kie.workbench.common.widgets.client.datamodel.testclasses.TestSubClass) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 22 with IncrementalDataModelService

use of org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService in project kie-wb-common by kiegroup.

the class PackageDataModelOracleTest method testSuperClass.

@Test
public void testSuperClass() throws IOException {
    final ModuleDataModelOracle moduleLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addClass(TestSuperClass.class).build();
    final PackageDataModelOracle packageLoader = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator(), "org.kie.workbench.common.widgets.client.datamodel.testclasses").setModuleOracle(moduleLoader).build();
    // Emulate server-to-client conversions
    final Caller<IncrementalDataModelService> service = new MockIncrementalDataModelServiceCaller(packageLoader);
    final AsyncPackageDataModelOracle oracle = new AsyncPackageDataModelOracleImpl(service, validatorInstance);
    final PackageDataModelOracleBaselinePayload dataModel = new PackageDataModelOracleBaselinePayload();
    dataModel.setPackageName(packageLoader.getPackageName());
    dataModel.setModelFields(packageLoader.getModuleModelFields());
    dataModel.setFieldParametersType(packageLoader.getModuleFieldParametersType());
    PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
    assertEquals(1, oracle.getFactTypes().length);
    assertEquals(TestSuperClass.class.getSimpleName(), oracle.getFactTypes()[0]);
    oracle.getFieldCompletions(TestSuperClass.class.getSimpleName(), new Callback<ModelField[]>() {

        @Override
        public void callback(final ModelField[] fields) {
            assertEquals(3, fields.length);
        }
    });
    assertEquals(DataType.TYPE_THIS, oracle.getFieldType(TestSuperClass.class.getSimpleName(), "this"));
    assertEquals(TestSuperClass.class.getSimpleName(), oracle.getFieldClassName(TestSuperClass.class.getSimpleName(), "this"));
    assertEquals(DataType.TYPE_STRING, oracle.getFieldType(TestSuperClass.class.getSimpleName(), "field1"));
    assertEquals(String.class.getName(), oracle.getFieldClassName(TestSuperClass.class.getSimpleName(), "field1"));
    assertEquals(DataType.TYPE_COLLECTION, oracle.getFieldType(TestSuperClass.class.getSimpleName(), "list"));
    assertEquals(List.class.getName(), oracle.getFieldClassName(TestSuperClass.class.getSimpleName(), "list"));
    assertEquals(String.class.getName(), oracle.getParametricFieldType(TestSuperClass.class.getSimpleName(), "list"));
}
Also used : Path(org.uberfire.backend.vfs.Path) IncrementalDataModelService(org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService) ModuleDataModelOracle(org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle) TestSuperClass(org.kie.workbench.common.widgets.client.datamodel.testclasses.TestSuperClass) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) PackageDataModelOracleBaselinePayload(org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload) RawMVELEvaluator(org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 23 with IncrementalDataModelService

use of org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService in project kie-wb-common by kiegroup.

the class PackageDataModelOracleTest method testImportedNestedClassMethodInformationImportBothTypes.

@Test
public void testImportedNestedClassMethodInformationImportBothTypes() throws IOException {
    final ModuleDataModelOracle moduleLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addClass(TestSuperClass.NestedClass.class).build();
    final PackageDataModelOracle packageLoader = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator()).setModuleOracle(moduleLoader).build();
    // Emulate server-to-client conversions
    final Caller<IncrementalDataModelService> service = new MockIncrementalDataModelServiceCaller(packageLoader);
    final AsyncPackageDataModelOracle oracle = new AsyncPackageDataModelOracleImpl(service, validatorInstance);
    final PackageDataModelOracleBaselinePayload dataModel = new PackageDataModelOracleBaselinePayload();
    dataModel.setPackageName(packageLoader.getPackageName());
    dataModel.setModelFields(packageLoader.getModuleModelFields());
    dataModel.setMethodInformation(packageLoader.getModuleMethodInformation());
    dataModel.setFieldParametersType(packageLoader.getModuleFieldParametersType());
    final HasImports hasImports = new HasImports() {

        final Imports imports = new Imports();

        {
            imports.addImport(new Import("org.kie.workbench.common.widgets.client.datamodel.testclasses.TestSuperClass.NestedClass"));
            imports.addImport(new Import("org.kie.workbench.common.widgets.client.datamodel.testclasses.Product"));
        }

        @Override
        public Imports getImports() {
            return imports;
        }

        @Override
        public void setImports(Imports imports) {
        }
    };
    PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), hasImports, oracle, dataModel);
    assertEquals(1, oracle.getFactTypes().length);
    assertEquals("TestSuperClass.NestedClass", oracle.getFactTypes()[0]);
    oracle.getFieldCompletions("TestSuperClass.NestedClass", new Callback<ModelField[]>() {

        @Override
        public void callback(final ModelField[] fields) {
            assertEquals(2, fields.length);
        }
    });
    oracle.getMethodInfos("TestSuperClass.NestedClass", new Callback<List<MethodInfo>>() {

        @Override
        public void callback(final List<MethodInfo> methodInfos) {
            assertNotNull(methodInfos);
            assertEquals(3, methodInfos.size());
            // Use SimpleName as the return type has been imported
            final MethodInfo mf0 = new MethodInfo("methodDoingSomethingThatReturnsAnInnerClass", new ArrayList<String>(), "TestSuperClass.NestedClass", null, "TestSuperClass.NestedClass");
            // Use SimpleName as the return type has been imported
            final MethodInfo mf1 = new MethodInfo("methodDoingSomethingThatReturnsAnOuterClass", new ArrayList<String>(), Product.class.getSimpleName(), null, Product.class.getSimpleName());
            // Use FQCN as the return type has not been imported
            final MethodInfo mf2 = new MethodInfo("methodDoingSomethingWithNestedField1", new ArrayList<String>(), String.class, null, DataType.TYPE_STRING);
            assertTrue(methodInfos.contains(mf0));
            assertTrue(methodInfos.contains(mf1));
            assertTrue(methodInfos.contains(mf2));
        }
    });
}
Also used : Path(org.uberfire.backend.vfs.Path) IncrementalDataModelService(org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService) Import(org.kie.soup.project.datamodel.imports.Import) ModuleDataModelOracle(org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle) ArrayList(java.util.ArrayList) HasImports(org.kie.soup.project.datamodel.imports.HasImports) Imports(org.kie.soup.project.datamodel.imports.Imports) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) PackageDataModelOracleBaselinePayload(org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload) HasImports(org.kie.soup.project.datamodel.imports.HasImports) RawMVELEvaluator(org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) ArrayList(java.util.ArrayList) List(java.util.List) MethodInfo(org.kie.soup.project.datamodel.oracle.MethodInfo) Test(org.junit.Test)

Example 24 with IncrementalDataModelService

use of org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService in project kie-wb-common by kiegroup.

the class PackageDataModelOracleTest method testImportedNestedClassMethodInformationInPackageScope.

@Test
public void testImportedNestedClassMethodInformationInPackageScope() throws IOException {
    final ModuleDataModelOracle moduleLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addClass(TestSuperClass.NestedClass.class).build();
    final PackageDataModelOracle packageLoader = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator(), "org.kie.workbench.common.widgets.client.datamodel.testclasses").setModuleOracle(moduleLoader).build();
    // Emulate server-to-client conversions
    final Caller<IncrementalDataModelService> service = new MockIncrementalDataModelServiceCaller(packageLoader);
    final AsyncPackageDataModelOracle oracle = new AsyncPackageDataModelOracleImpl(service, validatorInstance);
    final PackageDataModelOracleBaselinePayload dataModel = new PackageDataModelOracleBaselinePayload();
    dataModel.setPackageName(packageLoader.getPackageName());
    dataModel.setModelFields(packageLoader.getModuleModelFields());
    dataModel.setMethodInformation(packageLoader.getModuleMethodInformation());
    dataModel.setFieldParametersType(packageLoader.getModuleFieldParametersType());
    final HasImports hasImports = new HasImports() {

        final Imports imports = new Imports();

        @Override
        public Imports getImports() {
            return imports;
        }

        @Override
        public void setImports(Imports imports) {
        }
    };
    PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), hasImports, oracle, dataModel);
    assertEquals(1, oracle.getFactTypes().length);
    assertEquals("TestSuperClass.NestedClass", oracle.getFactTypes()[0]);
    oracle.getFieldCompletions("TestSuperClass.NestedClass", new Callback<ModelField[]>() {

        @Override
        public void callback(final ModelField[] fields) {
            assertEquals(2, fields.length);
        }
    });
    oracle.getMethodInfos("TestSuperClass.NestedClass", new Callback<List<MethodInfo>>() {

        @Override
        public void callback(final List<MethodInfo> methodInfos) {
            assertNotNull(methodInfos);
            assertEquals(3, methodInfos.size());
            // Use SimpleName as the return type is in the same package represented by the Oracle
            final MethodInfo mf0 = new MethodInfo("methodDoingSomethingThatReturnsAnInnerClass", new ArrayList<String>(), "TestSuperClass.NestedClass", null, "TestSuperClass.NestedClass");
            // Use SimpleName as the return type is in the same package represented by the Oracle
            final MethodInfo mf1 = new MethodInfo("methodDoingSomethingThatReturnsAnOuterClass", new ArrayList<String>(), Product.class.getSimpleName(), null, Product.class.getSimpleName());
            // Use FQCN as the return type has not been imported
            final MethodInfo mf2 = new MethodInfo("methodDoingSomethingWithNestedField1", new ArrayList<String>(), String.class, null, DataType.TYPE_STRING);
            assertTrue(methodInfos.contains(mf0));
            assertTrue(methodInfos.contains(mf1));
            assertTrue(methodInfos.contains(mf2));
        }
    });
}
Also used : Path(org.uberfire.backend.vfs.Path) IncrementalDataModelService(org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService) ModuleDataModelOracle(org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle) ArrayList(java.util.ArrayList) HasImports(org.kie.soup.project.datamodel.imports.HasImports) Imports(org.kie.soup.project.datamodel.imports.Imports) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) PackageDataModelOracleBaselinePayload(org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload) HasImports(org.kie.soup.project.datamodel.imports.HasImports) RawMVELEvaluator(org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) ArrayList(java.util.ArrayList) List(java.util.List) MethodInfo(org.kie.soup.project.datamodel.oracle.MethodInfo) Test(org.junit.Test)

Example 25 with IncrementalDataModelService

use of org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService in project kie-wb-common by kiegroup.

the class PackageDataModelOracleTest method testDataTypes.

@Test
public void testDataTypes() throws IOException {
    final ModuleDataModelOracle moduleLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addClass(TestDataTypes.class).build();
    final PackageDataModelOracle packageLoader = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator(), "org.kie.workbench.common.widgets.client.datamodel.testclasses").setModuleOracle(moduleLoader).build();
    // Emulate server-to-client conversions
    final Caller<IncrementalDataModelService> service = new MockIncrementalDataModelServiceCaller(packageLoader);
    final AsyncPackageDataModelOracle oracle = new AsyncPackageDataModelOracleImpl(service, validatorInstance);
    final PackageDataModelOracleBaselinePayload dataModel = new PackageDataModelOracleBaselinePayload();
    dataModel.setPackageName(packageLoader.getPackageName());
    dataModel.setModelFields(packageLoader.getModuleModelFields());
    dataModel.setFieldParametersType(packageLoader.getModuleFieldParametersType());
    PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
    assertEquals(1, oracle.getFactTypes().length);
    assertEquals(TestDataTypes.class.getSimpleName(), oracle.getFactTypes()[0]);
    oracle.getFieldCompletions(TestDataTypes.class.getSimpleName(), new Callback<ModelField[]>() {

        @Override
        public void callback(final ModelField[] fields) {
            assertEquals(20, fields.length);
        }
    });
    assertEquals(DataType.TYPE_THIS, oracle.getFieldType(TestDataTypes.class.getSimpleName(), "this"));
    assertEquals(DataType.TYPE_STRING, oracle.getFieldType(TestDataTypes.class.getSimpleName(), "fieldString"));
    assertEquals(DataType.TYPE_BOOLEAN, oracle.getFieldType(TestDataTypes.class.getSimpleName(), "fieldBooleanObject"));
    assertEquals(DataType.TYPE_DATE, oracle.getFieldType(TestDataTypes.class.getSimpleName(), "fieldDate"));
    assertEquals(DataType.TYPE_NUMERIC_BIGDECIMAL, oracle.getFieldType(TestDataTypes.class.getSimpleName(), "fieldNumeric"));
    assertEquals(DataType.TYPE_NUMERIC_BIGDECIMAL, oracle.getFieldType(TestDataTypes.class.getSimpleName(), "fieldBigDecimal"));
    assertEquals(DataType.TYPE_NUMERIC_BIGINTEGER, oracle.getFieldType(TestDataTypes.class.getSimpleName(), "fieldBigInteger"));
    assertEquals(DataType.TYPE_NUMERIC_BYTE, oracle.getFieldType(TestDataTypes.class.getSimpleName(), "fieldByteObject"));
    assertEquals(DataType.TYPE_NUMERIC_DOUBLE, oracle.getFieldType(TestDataTypes.class.getSimpleName(), "fieldDoubleObject"));
    assertEquals(DataType.TYPE_NUMERIC_FLOAT, oracle.getFieldType(TestDataTypes.class.getSimpleName(), "fieldFloatObject"));
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, oracle.getFieldType(TestDataTypes.class.getSimpleName(), "fieldIntegerObject"));
    assertEquals(DataType.TYPE_NUMERIC_LONG, oracle.getFieldType(TestDataTypes.class.getSimpleName(), "fieldLongObject"));
    assertEquals(DataType.TYPE_NUMERIC_SHORT, oracle.getFieldType(TestDataTypes.class.getSimpleName(), "fieldShortObject"));
    assertEquals(DataType.TYPE_BOOLEAN, oracle.getFieldType(TestDataTypes.class.getSimpleName(), "fieldBooleanPrimitive"));
    assertEquals(DataType.TYPE_NUMERIC_BYTE, oracle.getFieldType(TestDataTypes.class.getSimpleName(), "fieldBytePrimitive"));
    assertEquals(DataType.TYPE_NUMERIC_DOUBLE, oracle.getFieldType(TestDataTypes.class.getSimpleName(), "fieldDoublePrimitive"));
    assertEquals(DataType.TYPE_NUMERIC_FLOAT, oracle.getFieldType(TestDataTypes.class.getSimpleName(), "fieldFloatPrimitive"));
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, oracle.getFieldType(TestDataTypes.class.getSimpleName(), "fieldIntegerPrimitive"));
    assertEquals(DataType.TYPE_NUMERIC_LONG, oracle.getFieldType(TestDataTypes.class.getSimpleName(), "fieldLongPrimitive"));
    assertEquals(DataType.TYPE_NUMERIC_SHORT, oracle.getFieldType(TestDataTypes.class.getSimpleName(), "fieldShortPrimitive"));
}
Also used : Path(org.uberfire.backend.vfs.Path) IncrementalDataModelService(org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService) ModuleDataModelOracle(org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) TestDataTypes(org.kie.workbench.common.widgets.client.datamodel.testclasses.TestDataTypes) PackageDataModelOracleBaselinePayload(org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload) RawMVELEvaluator(org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) Test(org.junit.Test)

Aggregations

PackageDataModelOracle (org.kie.soup.project.datamodel.oracle.PackageDataModelOracle)55 PackageDataModelOracleBaselinePayload (org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload)55 IncrementalDataModelService (org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService)55 Path (org.uberfire.backend.vfs.Path)55 Test (org.junit.Test)54 RawMVELEvaluator (org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator)46 ModuleDataModelOracle (org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle)38 ModelField (org.kie.soup.project.datamodel.oracle.ModelField)31 ModuleDataModelOracleImpl (org.kie.soup.project.datamodel.commons.oracle.ModuleDataModelOracleImpl)12 PackageDataModelOracleBuilder (org.kie.workbench.common.services.datamodel.backend.server.builder.packages.PackageDataModelOracleBuilder)12 ClassFactBuilder (org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ClassFactBuilder)12 ModuleDataModelOracleBuilder (org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ModuleDataModelOracleBuilder)12 ArrayList (java.util.ArrayList)11 List (java.util.List)11 URL (java.net.URL)9 Set (java.util.Set)9 Annotation (org.kie.soup.project.datamodel.oracle.Annotation)9 HasImports (org.kie.soup.project.datamodel.imports.HasImports)6 MethodInfo (org.kie.soup.project.datamodel.oracle.MethodInfo)6 Import (org.kie.soup.project.datamodel.imports.Import)5