Search in sources :

Example 56 with PackageDataModelOracleBaselinePayload

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

the class PackageDataModelDeclaredTypesTest method testPackageDeclaredTypes.

@Test
public void testPackageDeclaredTypes() throws Exception {
    final Bean dataModelServiceBean = (Bean) beanManager.getBeans(DataModelService.class).iterator().next();
    final CreationalContext cc = beanManager.createCreationalContext(dataModelServiceBean);
    final DataModelService dataModelService = (DataModelService) beanManager.getReference(dataModelServiceBean, DataModelService.class, cc);
    final URL packageUrl = this.getClass().getResource("/DataModelBackendDeclaredTypesTest1/src/main/java/t1p1");
    final org.uberfire.java.nio.file.Path nioPackagePath = fs.getPath(packageUrl.toURI());
    final Path packagePath = paths.convert(nioPackagePath);
    final PackageDataModelOracle packageLoader = dataModelService.getDataModel(packagePath);
    // 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("t1p1");
    dataModel.setModelFields(packageLoader.getModuleModelFields());
    dataModel.setTypeSources(new HashMap<String, TypeSource>() {

        {
            put("t1p1.Bean1", TypeSource.JAVA_PROJECT);
            put("t1p1.DRLBean", TypeSource.DECLARED);
            put("t1p2.Bean2", TypeSource.JAVA_PROJECT);
            put("java.lang.String", TypeSource.JAVA_PROJECT);
            put("int", TypeSource.JAVA_PROJECT);
        }
    });
    PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
    assertNotNull(dataModel);
    assertEquals(2, oracle.getFactTypes().length);
    PackageDataModelOracleTestUtils.assertContains("Bean1", oracle.getFactTypes());
    PackageDataModelOracleTestUtils.assertContains("DRLBean", oracle.getFactTypes());
    assertEquals(2, oracle.getExternalFactTypes().length);
    PackageDataModelOracleTestUtils.assertContains("t1p2.Bean2", oracle.getExternalFactTypes());
    PackageDataModelOracleTestUtils.assertContains("java.lang.String", oracle.getExternalFactTypes());
    oracle.getTypeSource("Bean1", new Callback<TypeSource>() {

        @Override
        public void callback(final TypeSource result) {
            assertEquals(TypeSource.JAVA_PROJECT, result);
        }
    });
    oracle.getTypeSource("DRLBean", new Callback<TypeSource>() {

        @Override
        public void callback(final TypeSource result) {
            assertEquals(TypeSource.DECLARED, result);
        }
    });
}
Also used : Path(org.uberfire.backend.vfs.Path) IncrementalDataModelService(org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService) TypeSource(org.kie.soup.project.datamodel.oracle.TypeSource) URL(java.net.URL) Bean(javax.enterprise.inject.spi.Bean) CreationalContext(javax.enterprise.context.spi.CreationalContext) PackageDataModelOracleBaselinePayload(org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) DataModelService(org.kie.workbench.common.services.datamodel.backend.server.service.DataModelService) IncrementalDataModelService(org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService) Test(org.junit.Test)

Example 57 with PackageDataModelOracleBaselinePayload

use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload 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 58 with PackageDataModelOracleBaselinePayload

use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload 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 59 with PackageDataModelOracleBaselinePayload

use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload 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)

Example 60 with PackageDataModelOracleBaselinePayload

use of org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload 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)

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