Search in sources :

Example 31 with Import

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

the class ImportsWidgetViewImplTest method checkAddImportSortsAlphabetically.

@Test
public void checkAddImportSortsAlphabetically() {
    final Import newImport = new Import("new1");
    when(addImportPopup.getImportType()).thenReturn(newImport.getType());
    view.makeAddImportCommand().execute();
    verify(lockRequired).fire(any(LockRequiredEvent.class));
    verify(view).updateRenderedColumns();
    final List<Import> imports = view.getDataProvider().getList();
    assertEquals(4, imports.size());
    assertEquals(newImport, imports.get(0));
    assertEquals(import3, imports.get(1));
    assertEquals(import2, imports.get(2));
    assertEquals(import1, imports.get(3));
}
Also used : LockRequiredEvent(org.uberfire.client.mvp.LockRequiredEvent) Import(org.kie.soup.project.datamodel.imports.Import) Test(org.junit.Test)

Example 32 with Import

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

the class PackageDataModelMethodsTest method testMethodsOnJavaClass_Number.

@Test
public void testMethodsOnJavaClass_Number() throws Exception {
    final ModuleDataModelOracle moduleLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addClass(Number.class).addFact("int").end().build();
    final PackageDataModelOracle packageLoader = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator(), "p0").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());
    PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new HasImports() {

        private Imports imports = new Imports() {

            {
                addImport(new Import("java.lang.Number"));
            }
        };

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

        @Override
        public void setImports(final Imports imports) {
        // Do nothing
        }
    }, oracle, dataModel);
    oracle.getMethodInfos(Number.class.getSimpleName(), new Callback<List<MethodInfo>>() {

        @Override
        public void callback(final List<MethodInfo> methodInfos) {
            assertNotNull(methodInfos);
            assertFalse(methodInfos.isEmpty());
            for (final MethodInfo methodInfo : methodInfos) {
                assertFalse("Method " + methodInfo.getName() + " is not allowed.", checkDenyList(methodInfo.getName()));
            }
        }
    });
    oracle.getMethodInfos("int", new Callback<List<MethodInfo>>() {

        @Override
        public void callback(final List<MethodInfo> methodInfos) {
            assertNotNull(methodInfos);
            assertTrue(methodInfos.isEmpty());
        }
    });
}
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) HasImports(org.kie.soup.project.datamodel.imports.HasImports) Imports(org.kie.soup.project.datamodel.imports.Imports) 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 33 with Import

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

the class PackageDataModelGlobalsTest method testGlobalCollections.

@Test
public void testGlobalCollections() throws Exception {
    final ModuleDataModelOracle moduleLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addClass(java.util.List.class).build();
    final PackageDataModelOracle packageLoader = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator(), "org.kie.workbench.common.services.datamodel.backend.server.testclasses").setModuleOracle(moduleLoader).addGlobals("global java.util.List list;").build();
    final HasImports imports = new MockHasImports();
    imports.getImports().addImport(new Import("java.util.List"));
    // 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.setGlobalTypes(packageLoader.getPackageGlobals());
    dataModel.setCollectionTypes(packageLoader.getModuleCollectionTypes());
    PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), imports, oracle, dataModel);
    assertNotNull(oracle);
    assertEquals(1, oracle.getFactTypes().length);
    assertEquals("List", oracle.getFactTypes()[0]);
    assertEquals(1, oracle.getGlobalVariables().length);
    assertEquals("list", oracle.getGlobalVariables()[0]);
    assertEquals("List", oracle.getGlobalVariable("list"));
    assertEquals(1, oracle.getGlobalCollections().length);
    assertEquals("list", oracle.getGlobalCollections()[0]);
}
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) 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) Test(org.junit.Test)

Example 34 with Import

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

the class AsyncPackageDataModelOracleUtilitiesTest method testFilterModelFieldsFactsShareNameInDifferentPackagesAnotherOneIsImported.

@Test
public void testFilterModelFieldsFactsShareNameInDifferentPackagesAnotherOneIsImported() throws Exception {
    Map<String, ModelField[]> projectModelFields = new TreeMap<String, ModelField[]>();
    projectModelFields.put("org.test.Person", new ModelField[] { getModelField("Person", "org.test.Person") });
    projectModelFields.put("org.test.sub.Person", new ModelField[] { getModelField("Person", "org.test.sub.Person") });
    projectModelFields.put("org.test.sub.Address", new ModelField[] { getModelField("Address", "org.test.sub.Address") });
    projectModelFields.put("org.test.Address", new ModelField[] { getModelField("Address", "org.test.Address") });
    FactNameToFQCNHandleRegistry registry = new FactNameToFQCNHandleRegistry();
    Imports imports = new Imports();
    imports.addImport(new Import("org.test.sub.Person"));
    imports.addImport(new Import("org.test.sub.Address"));
    AsyncPackageDataModelOracleUtilities.filterModelFields("org.another", imports, projectModelFields, registry);
    assertEquals("org.test.sub.Person", registry.get("Person"));
    assertEquals("org.test.sub.Address", registry.get("Address"));
}
Also used : Import(org.kie.soup.project.datamodel.imports.Import) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) Imports(org.kie.soup.project.datamodel.imports.Imports) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 35 with Import

use of org.kie.soup.project.datamodel.imports.Import 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)

Aggregations

Import (org.kie.soup.project.datamodel.imports.Import)103 Test (org.junit.Test)79 Imports (org.kie.soup.project.datamodel.imports.Imports)26 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)25 Scenario (org.drools.workbench.models.testscenarios.shared.Scenario)14 ArrayList (java.util.ArrayList)12 Path (org.uberfire.java.nio.file.Path)12 Query (org.apache.lucene.search.Query)11 FactData (org.drools.workbench.models.testscenarios.shared.FactData)11 VerifyFact (org.drools.workbench.models.testscenarios.shared.VerifyFact)11 BaseIndexingTest (org.kie.workbench.common.services.refactoring.backend.server.BaseIndexingTest)11 SingleTermQueryBuilder (org.kie.workbench.common.services.refactoring.backend.server.query.builder.SingleTermQueryBuilder)11 VerifyField (org.drools.workbench.models.testscenarios.shared.VerifyField)10 FieldData (org.drools.workbench.models.testscenarios.shared.FieldData)9 KieSession (org.kie.api.runtime.KieSession)9 ModelField (org.kie.soup.project.datamodel.oracle.ModelField)9 ValueReferenceIndexTerm (org.kie.workbench.common.services.refactoring.model.index.terms.valueterms.ValueReferenceIndexTerm)9 Path (org.uberfire.backend.vfs.Path)9 ProjectImports (org.guvnor.common.services.project.model.ProjectImports)8 Analyzer (org.drools.verifier.core.main.Analyzer)7