Search in sources :

Example 11 with ModuleDataModelOracleBuilder

use of org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ModuleDataModelOracleBuilder in project kie-wb-common by kiegroup.

the class PackageDataModelFactAnnotationsTest method testIncorrectPackageDMOZeroAnnotationAttributes.

@Test
public void testIncorrectPackageDMOZeroAnnotationAttributes() throws Exception {
    // Build ModuleDMO
    final ModuleDataModelOracleBuilder moduleBuilder = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator());
    final ModuleDataModelOracleImpl moduleLoader = new ModuleDataModelOracleImpl();
    final ClassFactBuilder cb = new ClassFactBuilder(moduleBuilder, Product.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.getTypeAnnotations("Product", new Callback<Set<Annotation>>() {

        @Override
        public void callback(final Set<Annotation> annotations) {
            assertNotNull(annotations);
            assertEquals(0, annotations.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) ClassFactBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ClassFactBuilder) Test(org.junit.Test)

Example 12 with ModuleDataModelOracleBuilder

use of org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ModuleDataModelOracleBuilder in project kie-wb-common by kiegroup.

the class PackageDataModelFactAnnotationsTest method testCorrectPackageDMOZeroAnnotationAttributes.

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

        @Override
        public void callback(final Set<Annotation> annotations) {
            assertNotNull(annotations);
            assertEquals(0, annotations.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) ClassFactBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ClassFactBuilder) Test(org.junit.Test)

Example 13 with ModuleDataModelOracleBuilder

use of org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ModuleDataModelOracleBuilder in project kie-wb-common by kiegroup.

the class PackageDataModelFactAnnotationsTest 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, Smurf.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.getTypeAnnotations("Smurf", new Callback<Set<Annotation>>() {

        @Override
        public void callback(final Set<Annotation> annotations) {
            assertNotNull(annotations);
            assertEquals(0, annotations.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) ClassFactBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ClassFactBuilder) Test(org.junit.Test)

Example 14 with ModuleDataModelOracleBuilder

use of org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ModuleDataModelOracleBuilder in project kie-wb-common by kiegroup.

the class PackageDataModelFactFieldsAnnotationsTest 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, SmurfHouse.class, 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);
    assertEquals(1, oracle.getFactTypes().length);
    assertEquals("SmurfHouse", oracle.getFactTypes()[0]);
    oracle.getTypeFieldsAnnotations("SmurfHouse", new Callback<Map<String, Set<Annotation>>>() {

        @Override
        public void callback(final Map<String, Set<Annotation>> fieldsAnnotations) {
            assertNotNull(fieldsAnnotations);
            assertEquals(2, fieldsAnnotations.size());
            assertTrue(fieldsAnnotations.containsKey("occupant"));
            final Set<Annotation> occupantAnnotations = fieldsAnnotations.get("occupant");
            assertNotNull(occupantAnnotations);
            assertEquals(1, occupantAnnotations.size());
            final Annotation annotation = occupantAnnotations.iterator().next();
            assertEquals("org.kie.workbench.common.widgets.client.datamodel.testclasses.annotations.SmurfFieldDescriptor", annotation.getQualifiedTypeName());
            assertEquals("blue", annotation.getParameters().get("colour"));
            assertEquals("M", annotation.getParameters().get("gender"));
            assertEquals("Brains", annotation.getParameters().get("description"));
            assertTrue(fieldsAnnotations.containsKey("positionedOccupant"));
            final Set<Annotation> posOccupantAnnotations = fieldsAnnotations.get("positionedOccupant");
            assertNotNull(posOccupantAnnotations);
            assertEquals(1, posOccupantAnnotations.size());
            final Annotation annotation2 = posOccupantAnnotations.iterator().next();
            assertEquals("org.kie.workbench.common.widgets.client.datamodel.testclasses.annotations.SmurfFieldPositionDescriptor", annotation2.getQualifiedTypeName());
            assertEquals(1, annotation2.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) Map(java.util.Map) ClassFactBuilder(org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ClassFactBuilder) Test(org.junit.Test)

Example 15 with ModuleDataModelOracleBuilder

use of org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ModuleDataModelOracleBuilder in project kie-wb-common by kiegroup.

the class PackageDataModelFactFieldsAnnotationsTest method testIncorrectPackageDMOZeroAnnotationAttributes.

@Test
public void testIncorrectPackageDMOZeroAnnotationAttributes() throws Exception {
    // Build ModuleDMO
    final ModuleDataModelOracleBuilder moduleBuilder = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator());
    final ModuleDataModelOracleImpl moduleLoader = new ModuleDataModelOracleImpl();
    final ClassFactBuilder cb = new ClassFactBuilder(moduleBuilder, Product.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("Product", new Callback<Map<String, Set<Annotation>>>() {

        @Override
        public void callback(final Map<String, Set<Annotation>> fieldsAnnotations) {
            assertNotNull(fieldsAnnotations);
            assertEquals(0, fieldsAnnotations.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)

Aggregations

ModuleDataModelOracleBuilder (org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ModuleDataModelOracleBuilder)22 RawMVELEvaluator (org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator)21 ClassFactBuilder (org.kie.workbench.common.services.datamodel.backend.server.builder.projects.ClassFactBuilder)21 ModuleDataModelOracleImpl (org.kie.soup.project.datamodel.commons.oracle.ModuleDataModelOracleImpl)20 Test (org.junit.Test)19 Annotation (org.kie.soup.project.datamodel.oracle.Annotation)14 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 PackageDataModelOracleBaselinePayload (org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload)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)3 ModelField (org.kie.soup.project.datamodel.oracle.ModelField)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Before (org.junit.Before)1 ModuleDataModelOracle (org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle)1 Product (org.kie.workbench.common.services.datamodel.backend.server.testclasses.Product)1