Search in sources :

Example 26 with IncrementalDataModelService

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

the class PackageDataModelServiceTest method testModuleDataModelOracle.

@Test
public void testModuleDataModelOracle() 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("/DataModelBackendTest1/src/main/java/t3p1");
    final org.uberfire.java.nio.file.Path nioPackagePath = fs.getPath(packageUrl.toURI());
    final Path packagePath = paths.convert(nioPackagePath);
    final PackageDataModelOracle packageLoader = dataModelService.getDataModel(packagePath);
    final ModuleDataModelOracle moduleLoader = dataModelService.getModuleDataModel(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.setModelFields(moduleLoader.getModuleModelFields());
    PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
    assertNotNull(oracle);
    assertEquals(3, oracle.getAllFactTypes().length);
    assertContains("t3p1.Bean1", oracle.getAllFactTypes());
    assertContains("t3p2.Bean2", oracle.getAllFactTypes());
    assertContains("java.lang.String", oracle.getAllFactTypes());
    oracle.getFieldCompletions("t3p1.Bean1", new Callback<ModelField[]>() {

        @Override
        public void callback(final ModelField[] fields) {
            assertEquals(3, fields.length);
            assertContains("this", fields);
            assertContains("field1", fields);
            assertContains("field2", fields);
        }
    });
    oracle.getFieldCompletions("t3p2.Bean2", new Callback<ModelField[]>() {

        @Override
        public void callback(final ModelField[] fields) {
            assertEquals(2, fields.length);
            assertContains("this", fields);
            assertContains("field1", fields);
        }
    });
}
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) URL(java.net.URL) Bean(javax.enterprise.inject.spi.Bean) CreationalContext(javax.enterprise.context.spi.CreationalContext) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) 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 27 with IncrementalDataModelService

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

the class PackageDataModelServiceTest method testPackageDataModelOracle.

@Test
public void testPackageDataModelOracle() 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("/DataModelBackendTest1/src/main/java/t3p1");
    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("t3p1");
    dataModel.setModelFields(packageLoader.getModuleModelFields());
    PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
    assertNotNull(oracle);
    assertEquals(3, oracle.getAllFactTypes().length);
    assertContains("t3p1.Bean1", oracle.getAllFactTypes());
    assertContains("t3p2.Bean2", oracle.getAllFactTypes());
    assertContains("java.lang.String", oracle.getAllFactTypes());
    assertEquals(1, oracle.getFactTypes().length);
    assertContains("Bean1", oracle.getFactTypes());
    oracle.getFieldCompletions("Bean1", new Callback<ModelField[]>() {

        @Override
        public void callback(final ModelField[] fields) {
            assertEquals(3, fields.length);
            assertContains("this", fields);
            assertContains("field1", fields);
            assertContains("field2", fields);
        }
    });
    assertEquals(2, oracle.getExternalFactTypes().length);
    assertContains("t3p2.Bean2", oracle.getExternalFactTypes());
    assertContains("java.lang.String", oracle.getExternalFactTypes());
}
Also used : Path(org.uberfire.backend.vfs.Path) IncrementalDataModelService(org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService) URL(java.net.URL) Bean(javax.enterprise.inject.spi.Bean) CreationalContext(javax.enterprise.context.spi.CreationalContext) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) 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 28 with IncrementalDataModelService

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

the class PackageDataModelSuperTypesTest method testPackageSuperTypes.

@Test
public void testPackageSuperTypes() throws Exception {
    final URL packageUrl = this.getClass().getResource("/DataModelBackendSuperTypesTest1/src/main/java/t2p1");
    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("t2p1");
    dataModel.setModelFields(packageLoader.getModuleModelFields());
    dataModel.setSuperTypes(new HashMap<String, List<String>>() {

        {
            put("t2p1.Bean1", null);
            put("t2p1.Bean2", new ArrayList<String>() {

                {
                    add("t2p1.Bean1");
                }
            });
            put("t2p2.Bean3", new ArrayList<String>() {

                {
                    add("t2p1.Bean1");
                }
            });
            put("t2p1.Bean4", new ArrayList<String>() {

                {
                    add("t2p2.Bean3");
                }
            });
        }
    });
    PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
    assertNotNull(oracle);
    assertEquals(3, oracle.getFactTypes().length);
    assertContains("Bean1", oracle.getFactTypes());
    assertContains("Bean2", oracle.getFactTypes());
    assertContains("Bean4", oracle.getFactTypes());
    oracle.getSuperType("Bean1", new Callback<String>() {

        @Override
        public void callback(final String result) {
            assertEquals("java.lang.Object", result);
        }
    });
    oracle.getSuperType("Bean2", new Callback<String>() {

        @Override
        public void callback(final String result) {
            assertEquals("Bean1", result);
        }
    });
    oracle.getSuperType("Bean4", new Callback<String>() {

        @Override
        public void callback(final String result) {
            assertEquals("t2p2.Bean3", result);
        }
    });
}
Also used : Path(org.uberfire.backend.vfs.Path) IncrementalDataModelService(org.kie.workbench.common.services.datamodel.service.IncrementalDataModelService) ArrayList(java.util.ArrayList) URL(java.net.URL) PackageDataModelOracleBaselinePayload(org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 29 with IncrementalDataModelService

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

the class PackageDataModelSuperTypesTest method testModuleSuperTypes.

@Test
public void testModuleSuperTypes() throws Exception {
    final URL packageUrl = this.getClass().getResource("/DataModelBackendSuperTypesTest1/src/main/java/t2p1");
    final org.uberfire.java.nio.file.Path nioPackagePath = fs.getPath(packageUrl.toURI());
    final Path packagePath = paths.convert(nioPackagePath);
    final PackageDataModelOracle packageLoader = dataModelService.getDataModel(packagePath);
    final ModuleDataModelOracle moduleLoader = dataModelService.getModuleDataModel(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("t2p1");
    dataModel.setModelFields(moduleLoader.getModuleModelFields());
    dataModel.setSuperTypes(new HashMap<String, List<String>>() {

        {
            put("t2p1.Bean1", null);
            put("t2p1.Bean2", new ArrayList<String>() {

                {
                    add("t2p1.Bean1");
                }
            });
            put("t2p2.Bean3", new ArrayList<String>() {

                {
                    add("t2p1.Bean1");
                }
            });
            put("t2p1.Bean4", new ArrayList<String>() {

                {
                    add("t2p2.Bean3");
                }
            });
        }
    });
    PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
    assertNotNull(oracle);
    assertEquals(5, oracle.getAllFactTypes().length);
    assertContains("t2p1.Bean1", oracle.getAllFactTypes());
    assertContains("t2p1.Bean2", oracle.getAllFactTypes());
    assertContains("t2p2.Bean3", oracle.getAllFactTypes());
    assertContains("t2p1.Bean4", oracle.getAllFactTypes());
    assertContains("java.lang.String", oracle.getAllFactTypes());
    oracle.getSuperType("Bean1", new Callback<String>() {

        @Override
        public void callback(final String result) {
            assertEquals("java.lang.Object", result);
        }
    });
    oracle.getSuperType("Bean2", new Callback<String>() {

        @Override
        public void callback(final String result) {
            assertEquals("Bean1", result);
        }
    });
    oracle.getSuperType("Bean4", new Callback<String>() {

        @Override
        public void callback(final String result) {
            assertEquals("t2p2.Bean3", result);
        }
    });
}
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) URL(java.net.URL) PackageDataModelOracleBaselinePayload(org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 30 with IncrementalDataModelService

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

the class PackageDataModelExtendJavaTypeTest method testModuleExtendJavaTypeWithImport.

@Test
public void testModuleExtendJavaTypeWithImport() throws Exception {
    final URL packageUrl = this.getClass().getResource("/DataModelBackendExtendJavaTypeTest2/src/main/java/t5p1");
    final org.uberfire.java.nio.file.Path nioPackagePath = fs.getPath(packageUrl.toURI());
    final Path packagePath = paths.convert(nioPackagePath);
    final PackageDataModelOracle packageLoader = dataModelService.getDataModel(packagePath);
    final ModuleDataModelOracle projectLoader = dataModelService.getModuleDataModel(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("t5p1");
    dataModel.setModelFields(projectLoader.getModuleModelFields());
    dataModel.setEventTypes(new HashMap<String, Boolean>() {

        {
            put("t5p1.Bean1", true);
        }
    });
    PackageDataModelOracleTestUtils.populateDataModelOracle(mock(Path.class), new MockHasImports(), oracle, dataModel);
    assertNotNull(oracle);
    assertEquals(1, oracle.getFactTypes().length);
    assertContains("Bean1", oracle.getFactTypes());
    oracle.isFactTypeAnEvent("Bean1", new Callback<Boolean>() {

        @Override
        public void callback(final Boolean result) {
            assertTrue(result);
        }
    });
}
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) URL(java.net.URL) PackageDataModelOracleBaselinePayload(org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) 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