Search in sources :

Example 6 with HasImports

use of org.kie.soup.project.datamodel.imports.HasImports in project kie-wb-common by kiegroup.

the class PackageDataModelOracleTest method testImportedNestedClassMethodInformation.

@Test
public void testImportedNestedClassMethodInformation() 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"));
        }

        @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 FQCN as the return type has not been imported
            final MethodInfo mf1 = new MethodInfo("methodDoingSomethingWithNestedField1", new ArrayList<String>(), String.class, null, DataType.TYPE_STRING);
            // Use FQCN as the return type has not been imported
            final MethodInfo mf2 = new MethodInfo("methodDoingSomethingThatReturnsAnOuterClass", new ArrayList<String>(), Product.class.getName(), null, Product.class.getName());
            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)

Aggregations

Test (org.junit.Test)6 RawMVELEvaluator (org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator)6 HasImports (org.kie.soup.project.datamodel.imports.HasImports)6 ModuleDataModelOracle (org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle)6 PackageDataModelOracle (org.kie.soup.project.datamodel.oracle.PackageDataModelOracle)6 PackageDataModelOracleBaselinePayload (org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload)6 IncrementalDataModelService (org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService)6 Path (org.uberfire.backend.vfs.Path)6 Import (org.kie.soup.project.datamodel.imports.Import)5 Imports (org.kie.soup.project.datamodel.imports.Imports)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 MethodInfo (org.kie.soup.project.datamodel.oracle.MethodInfo)4 ModelField (org.kie.soup.project.datamodel.oracle.ModelField)4