Search in sources :

Example 96 with PackageDataModelOracleBaselinePayload

use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload in project kie-wb-common by kiegroup.

the class PackageDataModelMethodsTest method testMethodsOnJavaClass_ArrayList.

@Test
public void testMethodsOnJavaClass_ArrayList() throws Exception {
    final ModuleDataModelOracle moduleLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addClass(ArrayList.class).build();
    final PackageDataModelOracle packageLoader = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator(), "java.util").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 MockHasImports(), oracle, dataModel);
    oracle.getMethodInfos(ArrayList.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()));
            }
        }
    });
}
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) 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) MethodInfo(org.kie.soup.project.datamodel.oracle.MethodInfo) Test(org.junit.Test)

Example 97 with PackageDataModelOracleBaselinePayload

use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload in project kie-wb-common by kiegroup.

the class PackageDataModelMethodsTest method testMethodsOnJavaClass_TreeMap.

@Test
public void testMethodsOnJavaClass_TreeMap() throws Exception {
    final ModuleDataModelOracle moduleLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addClass(TreeMap.class).build();
    final PackageDataModelOracle packageLoader = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator(), "java.util").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 MockHasImports(), oracle, dataModel);
    oracle.getFieldCompletions(TreeMap.class.getSimpleName(), FieldAccessorsAndMutators.ACCESSOR, new Callback<ModelField[]>() {

        @Override
        public void callback(final ModelField[] getters) {
            assertEquals(2, getters.length);
            assertEquals("empty", getters[0].getName());
            assertEquals("this", getters[1].getName());
        }
    });
    oracle.getMethodInfos(TreeMap.class.getSimpleName(), new Callback<List<MethodInfo>>() {

        @Override
        public void callback(final List<MethodInfo> mis) {
            assertContains("ceilingEntry", mis);
            assertContains("ceilingKey", mis);
            assertContains("clear", mis);
            assertContains("clone", mis);
            assertContains("comparator", mis);
            assertContains("containsKey", mis);
            assertContains("containsValue", mis);
            assertContains("descendingKeySet", mis);
            assertContains("descendingMap", mis);
            assertContains("firstEntry", mis);
            assertContains("firstKey", mis);
            assertContains("floorEntry", mis);
            assertContains("floorKey", mis);
            assertContains("get", mis);
            assertContains("headMap", mis);
            assertContains("headMap", mis);
            assertContains("higherEntry", mis);
            assertContains("higherKey", mis);
            assertContains("lastEntry", mis);
            assertContains("lastKey", mis);
            assertContains("lowerEntry", mis);
            assertContains("lowerKey", mis);
            assertContains("navigableKeySet", mis);
            assertContains("pollFirstEntry", mis);
            assertContains("pollLastEntry", mis);
            assertContains("put", mis);
            assertContains("remove", mis);
            assertContains("size", mis);
            assertContains("subMap", mis);
            assertContains("subMap", mis);
            assertContains("tailMap", mis);
            assertContains("tailMap", mis);
            assertContains("values", mis);
        }
    });
    oracle.getFieldCompletions(TreeMap.class.getSimpleName(), FieldAccessorsAndMutators.MUTATOR, new Callback<ModelField[]>() {

        @Override
        public void callback(final ModelField[] setters) {
            assertEquals(0, setters.length);
        }
    });
}
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) TreeMap(java.util.TreeMap) 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) MethodInfo(org.kie.soup.project.datamodel.oracle.MethodInfo) Test(org.junit.Test)

Example 98 with PackageDataModelOracleBaselinePayload

use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload in project kie-wb-common by kiegroup.

the class PackageDataModelOracleCompletionsTest method testFactFieldOperatorCompletions.

@Test
public void testFactFieldOperatorCompletions() {
    final ModuleDataModelOracle moduleLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addFact("Person").addField(new ModelField("age", Integer.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_NUMERIC_INTEGER)).addField(new ModelField("rank", Integer.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_COMPARABLE)).addField(new ModelField("name", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).end().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());
    PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
    Callback<String[]> personCallback = spy(new Callback<String[]>() {

        @Override
        public void callback(final String[] personThisOperators) {
            assertArrayEquals(new String[] { "==", "!=", "== null", "!= null", "memberOf", "not memberOf" }, personThisOperators);
        }
    });
    oracle.getOperatorCompletions("Person", "this", personCallback);
    verify(personCallback).callback(any(String[].class));
    Callback<String[]> personAgeCallback = spy(new Callback<String[]>() {

        @Override
        public void callback(final String[] personAgeOperators) {
            assertArrayEquals(new String[] { "==", "!=", "<", ">", "<=", ">=", "== null", "!= null", "memberOf", "not memberOf", "in", "not in" }, personAgeOperators);
        }
    });
    oracle.getOperatorCompletions("Person", "age", personAgeCallback);
    verify(personAgeCallback).callback(any(String[].class));
    Callback<String[]> personRankCallback = spy(new Callback<String[]>() {

        @Override
        public void callback(final String[] personRankOperators) {
            assertArrayEquals(new String[] { "==", "!=", "<", ">", "<=", ">=", "== null", "!= null", "memberOf", "not memberOf" }, personRankOperators);
        }
    });
    oracle.getOperatorCompletions("Person", "rank", personRankCallback);
    verify(personRankCallback).callback(any(String[].class));
    Callback<String[]> personNameCallback = spy(new Callback<String[]>() {

        @Override
        public void callback(final String[] personNameOperators) {
            assertArrayEquals(new String[] { "==", "!=", "<", ">", "<=", ">=", "contains", "not contains", "matches", "not matches", "soundslike", "not soundslike", "memberOf", "not memberOf", "== null", "!= null", "in", "not in" }, personNameOperators);
        }
    });
    oracle.getOperatorCompletions("Person", "name", personNameCallback);
    verify(personNameCallback).callback(any(String[].class));
}
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) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) Test(org.junit.Test)

Example 99 with PackageDataModelOracleBaselinePayload

use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload in project kie-wb-common by kiegroup.

the class PackageDataModelOracleCompletionsTest method testFactFieldCompletions.

@Test
public void testFactFieldCompletions() {
    final ModuleDataModelOracle moduleLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addFact("Person").addField(new ModelField("age", Integer.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_NUMERIC_INTEGER)).addField(new ModelField("rank", Integer.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_COMPARABLE)).addField(new ModelField("name", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).end().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());
    PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
    Callback<ModelField[]> callback = spy(new Callback<ModelField[]>() {

        @Override
        public void callback(final ModelField[] fields) {
            assertEquals(4, fields.length);
            assertEquals("age", fields[0].getName());
            assertEquals("name", fields[1].getName());
            assertEquals("rank", fields[2].getName());
            assertEquals("this", fields[3].getName());
        }
    });
    oracle.getFieldCompletions("Person", callback);
    verify(callback).callback(any(ModelField[].class));
}
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) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) Test(org.junit.Test)

Example 100 with PackageDataModelOracleBaselinePayload

use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload in project kie-wb-common by kiegroup.

the class PackageDataModelOracleTest method testImportedNestedClass.

@Test
public void testImportedNestedClass() 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.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);
        }
    });
    assertEquals("TestSuperClass.NestedClass", oracle.getFieldType("TestSuperClass.NestedClass", "this"));
    assertEquals("TestSuperClass.NestedClass", oracle.getFieldClassName("TestSuperClass.NestedClass", "this"));
    assertEquals(DataType.TYPE_STRING, oracle.getFieldType("TestSuperClass.NestedClass", "nestedField1"));
    assertEquals(String.class.getName(), oracle.getFieldClassName("TestSuperClass.NestedClass", "nestedField1"));
}
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) 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) Test(org.junit.Test)

Aggregations

PackageDataModelOracleBaselinePayload (org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload)124 Path (org.uberfire.backend.vfs.Path)105 Test (org.junit.Test)102 RawMVELEvaluator (org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator)95 PackageDataModelOracle (org.kie.soup.project.datamodel.oracle.PackageDataModelOracle)84 ModuleDataModelOracle (org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle)82 ModelField (org.kie.soup.project.datamodel.oracle.ModelField)76 IncrementalDataModelService (org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService)55 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)51 AsyncPackageDataModelOracle (org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle)48 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)45 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)43 LimitedEntryConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52)38 ArrayList (java.util.ArrayList)32 List (java.util.List)32 DTCellValue52 (org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)28 ActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52)20 ActionSetFieldCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52)20 LimitedEntryActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionInsertFactCol52)18 LimitedEntryActionSetFieldCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionSetFieldCol52)18