Search in sources :

Example 11 with ModuleDataModelOracleImpl

use of org.kie.soup.project.datamodel.commons.oracle.ModuleDataModelOracleImpl in project kie-wb-common by kiegroup.

the class PackageDataModelOracleTest method testIndirectRecursion.

@Test
public void testIndirectRecursion() throws Exception {
    // Build ModuleDMO
    final ModuleDataModelOracleBuilder moduleBuilder = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator());
    final ModuleDataModelOracleImpl moduleLoader = new ModuleDataModelOracleImpl();
    final ClassFactBuilder cb = new ClassFactBuilder(moduleBuilder, new HashMap<String, FactBuilder>(), TestIndirectRecursionClassA.class, false, type -> TypeSource.JAVA_PROJECT);
    cb.build(moduleLoader);
    // Build PackageDMO
    final PackageDataModelOracleBuilder packageBuilder = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator(), "org.kie.workbench.common.widgets.client.datamodel.testclasses");
    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(1, oracle.getFactTypes().length);
    assertEquals("TestIndirectRecursionClassA", oracle.getFactTypes()[0]);
    oracle.getFieldCompletions("TestIndirectRecursionClassA", new Callback<ModelField[]>() {

        @Override
        public void callback(final ModelField[] result) {
            assertEquals(2, result.length);
            assertEquals("TestIndirectRecursionClassB", result[0].getClassName());
            assertEquals("recursiveField", result[0].getName());
            assertEquals("TestIndirectRecursionClassA", result[1].getClassName());
            assertEquals(DataType.TYPE_THIS, result[1].getName());
        }
    });
}
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) 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) ClassFactBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ClassFactBuilder) FactBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.FactBuilder) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) ClassFactBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ClassFactBuilder) Test(org.junit.Test)

Example 12 with ModuleDataModelOracleImpl

use of org.kie.soup.project.datamodel.commons.oracle.ModuleDataModelOracleImpl 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, type -> 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 13 with ModuleDataModelOracleImpl

use of org.kie.soup.project.datamodel.commons.oracle.ModuleDataModelOracleImpl in project kie-wb-common by kiegroup.

the class PackageDataModelFactAnnotationsTest method testCorrectPackageDMOAnnotationAttributes.

@Test
public void testCorrectPackageDMOAnnotationAttributes() throws Exception {
    // Build ModuleDMO
    final ModuleDataModelOracleBuilder moduleBuilder = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator());
    final ModuleDataModelOracleImpl moduleLoader = new ModuleDataModelOracleImpl();
    final ClassFactBuilder cb = new ClassFactBuilder(moduleBuilder, Smurf.class, false, type -> 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);
    assertEquals(1, oracle.getFactTypes().length);
    assertEquals("Smurf", oracle.getFactTypes()[0]);
    oracle.getTypeAnnotations("Smurf", new Callback<Set<Annotation>>() {

        @Override
        public void callback(final Set<Annotation> annotations) {
            assertNotNull(annotations);
            assertEquals(1, annotations.size());
            final Annotation annotation = annotations.iterator().next();
            assertEquals("org.kie.workbench.common.widgets.client.datamodel.testclasses.annotations.SmurfDescriptor", annotation.getQualifiedTypeName());
            assertEquals("blue", annotation.getParameters().get("colour"));
            assertEquals("M", annotation.getParameters().get("gender"));
            assertEquals("Brains", annotation.getParameters().get("description"));
        }
    });
}
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) ClassFactBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ClassFactBuilder) Test(org.junit.Test)

Example 14 with ModuleDataModelOracleImpl

use of org.kie.soup.project.datamodel.commons.oracle.ModuleDataModelOracleImpl in project kie-wb-common by kiegroup.

the class PackageDataModelFactAnnotationsTest method testCorrectPackageDMOAnnotationAttributes2.

@Test
public void testCorrectPackageDMOAnnotationAttributes2() throws Exception {
    // Build ModuleDMO
    final ModuleDataModelOracleBuilder moduleBuilder = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator());
    final ModuleDataModelOracleImpl moduleLoader = new ModuleDataModelOracleImpl();
    final ClassFactBuilder cb = new ClassFactBuilder(moduleBuilder, RoleSmurf.class, false, type -> 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);
    assertEquals(1, oracle.getFactTypes().length);
    assertEquals("RoleSmurf", oracle.getFactTypes()[0]);
    oracle.getTypeAnnotations("RoleSmurf", new Callback<Set<Annotation>>() {

        @Override
        public void callback(final Set<Annotation> annotations) {
            assertNotNull(annotations);
            assertEquals(1, annotations.size());
            final Annotation annotation = annotations.iterator().next();
            assertEquals("org.kie.api.definition.type.Role", annotation.getQualifiedTypeName());
            assertEquals("EVENT", annotation.getParameters().get("value"));
        }
    });
}
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) ClassFactBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ClassFactBuilder) Test(org.junit.Test)

Example 15 with ModuleDataModelOracleImpl

use of org.kie.soup.project.datamodel.commons.oracle.ModuleDataModelOracleImpl 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, type -> 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)

Aggregations

ModuleDataModelOracleImpl (org.kie.soup.project.datamodel.commons.oracle.ModuleDataModelOracleImpl)37 RawMVELEvaluator (org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator)22 Test (org.junit.Test)20 ClassFactBuilder (org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ClassFactBuilder)20 ModuleDataModelOracleBuilder (org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ModuleDataModelOracleBuilder)20 ModelField (org.kie.soup.project.datamodel.oracle.ModelField)15 Annotation (org.kie.soup.project.datamodel.oracle.Annotation)14 ModuleDataModelOracle (org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle)14 PackageDataModelOracleBaselinePayload (org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload)13 Set (java.util.Set)12 PackageDataModelOracle (org.kie.soup.project.datamodel.oracle.PackageDataModelOracle)12 PackageDataModelOracleBuilder (org.kie.workbench.common.services.datamodel.backend.server.builder.packages.PackageDataModelOracleBuilder)12 IncrementalDataModelService (org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService)12 Path (org.uberfire.backend.vfs.Path)12 Map (java.util.Map)4 FactBuilder (org.kie.workbench.common.services.datamodel.backend.server.builder.projects.FactBuilder)2 Applicant (org.drools.workbench.screens.guided.dtable.backend.server.indexing.classes.Applicant)1 Before (org.junit.Before)1 APerson (org.kie.workbench.common.dmn.backend.editors.types.classes.APerson)1 Product (org.kie.workbench.common.services.datamodel.backend.server.testclasses.Product)1