Search in sources :

Example 6 with IncrementalDataModelService

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

the class PackageDataModelFactFieldsAnnotationsTest method testIncorrectPackageDMOAnnotationAttributes.

@Test
public void testIncorrectPackageDMOAnnotationAttributes() throws Exception {
    // Build ModuleDMO
    final ModuleDataModelOracleBuilder moduleBuilder = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator());
    final ModuleDataModelOracleImpl moduleLoader = new ModuleDataModelOracleImpl();
    final ClassFactBuilder cb = new ClassFactBuilder(moduleBuilder, SmurfHouse.class, false, TypeSource.JAVA_PROJECT);
    cb.build(moduleLoader);
    // Build PackageDMO. Defaults to defaultpkg
    final PackageDataModelOracleBuilder packageBuilder = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator());
    packageBuilder.setModuleOracle(moduleLoader);
    final PackageDataModelOracle packageLoader = packageBuilder.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.setTypeAnnotations(packageLoader.getModuleTypeAnnotations());
    dataModel.setTypeFieldsAnnotations(packageLoader.getModuleTypeFieldsAnnotations());
    PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
    assertEquals(0, oracle.getFactTypes().length);
    oracle.getTypeFieldsAnnotations("SmurfHouse", new Callback<Map<String, Set<Annotation>>>() {

        @Override
        public void callback(final Map<String, Set<Annotation>> fieldAnnotations) {
            assertNotNull(fieldAnnotations);
            assertEquals(0, fieldAnnotations.size());
        }
    });
}
Also used : Path(org.uberfire.backend.vfs.Path) IncrementalDataModelService(org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService) Set(java.util.Set) PackageDataModelOracleBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.packages.PackageDataModelOracleBuilder) ModuleDataModelOracleImpl(org.kie.soup.project.datamodel.commons.oracle.ModuleDataModelOracleImpl) Annotation(org.kie.soup.project.datamodel.oracle.Annotation) ModuleDataModelOracleBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ModuleDataModelOracleBuilder) 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) Map(java.util.Map) ClassFactBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ClassFactBuilder) Test(org.junit.Test)

Example 7 with IncrementalDataModelService

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

the class PackageDataModelFactFieldsValidationsTest method getOracle.

@SuppressWarnings("unchecked")
private AsyncPackageDataModelOracle getOracle(final Class clazz, final Instance<DynamicValidator> validatorInstance) throws Exception {
    // Build ModuleDMO
    final ModuleDataModelOracleBuilder moduleBuilder = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator());
    final ModuleDataModelOracleImpl moduleLoader = new ModuleDataModelOracleImpl();
    final ClassFactBuilder cb = new ClassFactBuilder(moduleBuilder, clazz, false, TypeSource.JAVA_PROJECT);
    cb.build(moduleLoader);
    // Build PackageDMO
    final PackageDataModelOracleBuilder packageBuilder = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator(), "org.kie.workbench.common.widgets.client.datamodel.testclasses.annotations");
    packageBuilder.setModuleOracle(moduleLoader);
    final PackageDataModelOracle packageLoader = packageBuilder.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.setTypeAnnotations(packageLoader.getModuleTypeAnnotations());
    dataModel.setTypeFieldsAnnotations(packageLoader.getModuleTypeFieldsAnnotations());
    PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
    return oracle;
}
Also used : Path(org.uberfire.backend.vfs.Path) IncrementalDataModelService(org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService) PackageDataModelOracleBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.packages.PackageDataModelOracleBuilder) ModuleDataModelOracleImpl(org.kie.soup.project.datamodel.commons.oracle.ModuleDataModelOracleImpl) ModuleDataModelOracleBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ModuleDataModelOracleBuilder) 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) ClassFactBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ClassFactBuilder)

Example 8 with IncrementalDataModelService

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

the class PackageDataModelGettersAndSettersTest method testGettersAndSettersOnDeclaredModel.

@Test
public void testGettersAndSettersOnDeclaredModel() throws Exception {
    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("sex", 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);
    oracle.getFieldCompletions("Person", FieldAccessorsAndMutators.ACCESSOR, new Callback<ModelField[]>() {

        @Override
        public void callback(final ModelField[] getters) {
            assertEquals(3, getters.length);
            assertEquals("age", getters[0].getName());
            assertEquals("sex", getters[1].getName());
            assertEquals(DataType.TYPE_THIS, getters[2].getName());
        }
    });
    oracle.getFieldCompletions("Person", FieldAccessorsAndMutators.MUTATOR, new Callback<ModelField[]>() {

        @Override
        public void callback(final ModelField[] setters) {
            assertEquals(2, setters.length);
            assertEquals("age", setters[0].getName());
            assertEquals("sex", setters[1].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) 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 9 with IncrementalDataModelService

use of org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService 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 10 with IncrementalDataModelService

use of org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService 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.", checkBlackList(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)

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