Search in sources :

Example 31 with CreationalContext

use of javax.enterprise.context.spi.CreationalContext in project kie-wb-common by kiegroup.

the class ResourceChangeIncrementalBuilderWithoutFullBuildTest method testResourceDeleted.

@Test
public void testResourceDeleted() throws Exception {
    final Bean buildChangeListenerBean = (Bean) beanManager.getBeans(org.guvnor.common.services.builder.ResourceChangeIncrementalBuilder.class).iterator().next();
    final CreationalContext cc = beanManager.createCreationalContext(buildChangeListenerBean);
    final org.guvnor.common.services.builder.ResourceChangeIncrementalBuilder buildChangeListener = (org.guvnor.common.services.builder.ResourceChangeIncrementalBuilder) beanManager.getReference(buildChangeListenerBean, org.guvnor.common.services.builder.ResourceChangeIncrementalBuilder.class, cc);
    final URL resourceUrl = this.getClass().getResource("/BuildChangeListenerRepo/src/main/resources/delete.drl");
    final org.uberfire.java.nio.file.Path nioResourcePath = fs.getPath(resourceUrl.toURI());
    final Path resourcePath = paths.convert(nioResourcePath);
    // Perform incremental build (Without a full Build first)
    buildChangeListener.deleteResource(resourcePath);
    waitForBuildResults(buildResultsObserver);
    final BuildResults buildResults = buildResultsObserver.getBuildResults();
    assertNotNull(buildResults);
    assertEquals(0, buildResults.getErrorMessages().size());
    assertEquals(1, buildResults.getInformationMessages().size());
    final IncrementalBuildResults incrementalBuildResults = buildResultsObserver.getIncrementalBuildResults();
    assertNull(incrementalBuildResults);
}
Also used : Path(org.uberfire.backend.vfs.Path) IncrementalBuildResults(org.guvnor.common.services.project.builder.model.IncrementalBuildResults) BuildResults(org.guvnor.common.services.project.builder.model.BuildResults) IncrementalBuildResults(org.guvnor.common.services.project.builder.model.IncrementalBuildResults) URL(java.net.URL) Bean(javax.enterprise.inject.spi.Bean) CreationalContext(javax.enterprise.context.spi.CreationalContext) Test(org.junit.Test)

Example 32 with CreationalContext

use of javax.enterprise.context.spi.CreationalContext in project kie-wb-common by kiegroup.

the class ResourceChangeIncrementalBuilderWithoutFullBuildTest method testResourceAdded.

@Test
public void testResourceAdded() throws Exception {
    final Bean buildChangeListenerBean = (Bean) beanManager.getBeans(org.guvnor.common.services.builder.ResourceChangeIncrementalBuilder.class).iterator().next();
    final CreationalContext cc = beanManager.createCreationalContext(buildChangeListenerBean);
    final org.guvnor.common.services.builder.ResourceChangeIncrementalBuilder buildChangeListener = (org.guvnor.common.services.builder.ResourceChangeIncrementalBuilder) beanManager.getReference(buildChangeListenerBean, org.guvnor.common.services.builder.ResourceChangeIncrementalBuilder.class, cc);
    final URL resourceUrl = this.getClass().getResource("/BuildChangeListenerRepo/src/main/resources/add.drl");
    final org.uberfire.java.nio.file.Path nioResourcePath = fs.getPath(resourceUrl.toURI());
    final Path resourcePath = paths.convert(nioResourcePath);
    // Perform incremental build (Without a full Build first)
    buildChangeListener.addResource(resourcePath);
    waitForBuildResults(buildResultsObserver);
    final BuildResults buildResults = buildResultsObserver.getBuildResults();
    assertNotNull(buildResults);
    assertEquals(0, buildResults.getErrorMessages().size());
    assertEquals(1, buildResults.getInformationMessages().size());
    final IncrementalBuildResults incrementalBuildResults = buildResultsObserver.getIncrementalBuildResults();
    assertNull(incrementalBuildResults);
}
Also used : Path(org.uberfire.backend.vfs.Path) IncrementalBuildResults(org.guvnor.common.services.project.builder.model.IncrementalBuildResults) BuildResults(org.guvnor.common.services.project.builder.model.BuildResults) IncrementalBuildResults(org.guvnor.common.services.project.builder.model.IncrementalBuildResults) URL(java.net.URL) Bean(javax.enterprise.inject.spi.Bean) CreationalContext(javax.enterprise.context.spi.CreationalContext) Test(org.junit.Test)

Example 33 with CreationalContext

use of javax.enterprise.context.spi.CreationalContext 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 34 with CreationalContext

use of javax.enterprise.context.spi.CreationalContext 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 35 with CreationalContext

use of javax.enterprise.context.spi.CreationalContext 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)

Aggregations

CreationalContext (javax.enterprise.context.spi.CreationalContext)132 Bean (javax.enterprise.inject.spi.Bean)113 Test (org.junit.Test)83 URL (java.net.URL)67 Path (org.uberfire.backend.vfs.Path)67 KieModuleService (org.kie.workbench.common.services.shared.project.KieModuleService)66 Package (org.guvnor.common.services.project.model.Package)43 Module (org.guvnor.common.services.project.model.Module)13 BeanManager (javax.enterprise.inject.spi.BeanManager)11 BuildResults (org.guvnor.common.services.project.builder.model.BuildResults)6 IncrementalBuildResults (org.guvnor.common.services.project.builder.model.IncrementalBuildResults)6 Before (org.junit.Before)6 Weld (org.jboss.weld.environment.se.Weld)5 Context (javax.enterprise.context.spi.Context)4 InjectionTarget (javax.enterprise.inject.spi.InjectionTarget)4 WebBeansContext (org.apache.webbeans.config.WebBeansContext)4 Fabric8Extension (io.fabric8.cdi.Fabric8Extension)3 Annotation (java.lang.annotation.Annotation)3 Method (java.lang.reflect.Method)3 Type (java.lang.reflect.Type)3