Search in sources :

Example 91 with CreationalContext

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

the class ModuleSaverTest method setUp.

@Before
public void setUp() throws Exception {
    fs = new SimpleFileSystemProvider();
    super.startWeld();
    // Instantiate Paths used in tests for Path conversion
    final Bean pathsBean = (Bean) beanManager.getBeans(Paths.class).iterator().next();
    final CreationalContext cc = beanManager.createCreationalContext(pathsBean);
    paths = (Paths) beanManager.getReference(pathsBean, Paths.class, cc);
    final Event<NewModuleEvent> newModuleEvent = mock(Event.class);
    when(ioService.createDirectory(Mockito.<org.uberfire.java.nio.file.Path>any())).thenAnswer(new Answer<Object>() {

        @Override
        public Object answer(final InvocationOnMock invocation) throws Throwable {
            return invocation.getArguments()[0];
        }
    });
    doCallRealMethod().when(resourceResolver).getDefaultWorkspacePath(any());
    doCallRealMethod().when(resourceResolver).getLegalId(any());
    saver = new ModuleSaver(ioService, pomService, mock(KModuleService.class), newModuleEvent, newPackageEvent, resourceResolver, mock(ProjectImportsService.class), mock(ModuleRepositoriesService.class), packageNameAllowListService, mock(CommentedOptionFactory.class), new SessionInfo() {

        @Override
        public String getId() {
            return "session";
        }

        @Override
        public User getIdentity() {
            return new UserImpl("testuser");
        }
    });
}
Also used : SessionInfo(org.uberfire.rpc.SessionInfo) Bean(javax.enterprise.inject.spi.Bean) SimpleFileSystemProvider(org.uberfire.java.nio.fs.file.SimpleFileSystemProvider) CreationalContext(javax.enterprise.context.spi.CreationalContext) NewModuleEvent(org.guvnor.common.services.project.events.NewModuleEvent) InvocationOnMock(org.mockito.invocation.InvocationOnMock) UserImpl(org.jboss.errai.security.shared.api.identity.UserImpl) Paths(org.uberfire.backend.server.util.Paths) Before(org.junit.Before)

Example 92 with CreationalContext

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

the class ModuleServiceImplResolvePackageInvalidNoKModuleTest method testResolvePackageDefaultResources.

@Test
public void testResolvePackageDefaultResources() throws Exception {
    final Bean moduleServiceBean = (Bean) beanManager.getBeans(KieModuleService.class).iterator().next();
    final CreationalContext cc = beanManager.createCreationalContext(moduleServiceBean);
    final KieModuleService moduleService = (KieModuleService) beanManager.getReference(moduleServiceBean, KieModuleService.class, cc);
    final URL rootUrl = this.getClass().getResource("/ModuleBackendTestModuleStructureInvalidNoKModule/src/main/resources");
    final org.uberfire.java.nio.file.Path nioRootPath = fs.getPath(rootUrl.toURI());
    final Path rootPath = paths.convert(nioRootPath);
    final URL testUrl = this.getClass().getResource("/ModuleBackendTestModuleStructureInvalidNoKModule/src/main/resources");
    final org.uberfire.java.nio.file.Path nioTestPath = fs.getPath(testUrl.toURI());
    final Path testPath = paths.convert(nioTestPath);
    // Test a non-Project Path resolves to null
    final Package result = moduleService.resolvePackage(testPath);
    assertNull(result);
}
Also used : Path(org.uberfire.backend.vfs.Path) KieModuleService(org.kie.workbench.common.services.shared.project.KieModuleService) CreationalContext(javax.enterprise.context.spi.CreationalContext) Package(org.guvnor.common.services.project.model.Package) URL(java.net.URL) Bean(javax.enterprise.inject.spi.Bean) Test(org.junit.Test)

Example 93 with CreationalContext

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

the class ModuleServiceImplResolvePackageNameValidTest method testResolvePackageNameWithNonProjectPath.

@Test
public void testResolvePackageNameWithNonProjectPath() throws Exception {
    final Bean moduleServiceBean = (Bean) beanManager.getBeans(KieModuleService.class).iterator().next();
    final CreationalContext cc = beanManager.createCreationalContext(moduleServiceBean);
    final KieModuleService moduleService = (KieModuleService) beanManager.getReference(moduleServiceBean, KieModuleService.class, cc);
    final URL testUrl = this.getClass().getResource("/");
    final org.uberfire.java.nio.file.Path testNioPath = fs.getPath(testUrl.toURI());
    final Path testPath = paths.convert(testNioPath);
    // Test a non-Project Path resolves to null
    final Package result = moduleService.resolvePackage(testPath);
    assertNull(result);
}
Also used : Path(org.uberfire.backend.vfs.Path) KieModuleService(org.kie.workbench.common.services.shared.project.KieModuleService) CreationalContext(javax.enterprise.context.spi.CreationalContext) Package(org.guvnor.common.services.project.model.Package) URL(java.net.URL) Bean(javax.enterprise.inject.spi.Bean) Test(org.junit.Test)

Example 94 with CreationalContext

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

the class ModuleServiceImplResolvePackageNameValidTest method testResolvePackageWithResourcesFileInDefaultPackage.

@Test
public void testResolvePackageWithResourcesFileInDefaultPackage() throws Exception {
    final Bean moduleServiceBean = (Bean) beanManager.getBeans(KieModuleService.class).iterator().next();
    final CreationalContext cc = beanManager.createCreationalContext(moduleServiceBean);
    final KieModuleService moduleService = (KieModuleService) beanManager.getReference(moduleServiceBean, KieModuleService.class, cc);
    final URL testUrl = this.getClass().getResource("/ModuleBackendTestModuleStructureValid/src/main/resources/rule1.drl");
    final org.uberfire.java.nio.file.Path nioTestPath = fs.getPath(testUrl.toURI());
    final Path testPath = paths.convert(nioTestPath);
    // Test a Resources file resolves to the containing package
    final Package result = moduleService.resolvePackage(testPath);
    assertEquals("", result.getPackageName());
}
Also used : Path(org.uberfire.backend.vfs.Path) KieModuleService(org.kie.workbench.common.services.shared.project.KieModuleService) CreationalContext(javax.enterprise.context.spi.CreationalContext) Package(org.guvnor.common.services.project.model.Package) URL(java.net.URL) Bean(javax.enterprise.inject.spi.Bean) Test(org.junit.Test)

Example 95 with CreationalContext

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

the class ModuleServiceImplResolvePackageNameValidTest method testResolvePackageWithSrcPath.

@Test
public void testResolvePackageWithSrcPath() throws Exception {
    final Bean moduleServiceBean = (Bean) beanManager.getBeans(KieModuleService.class).iterator().next();
    final CreationalContext cc = beanManager.createCreationalContext(moduleServiceBean);
    final KieModuleService moduleService = (KieModuleService) beanManager.getReference(moduleServiceBean, KieModuleService.class, cc);
    final URL rootUrl = this.getClass().getResource("/ModuleBackendTestModuleStructureValid/src");
    final org.uberfire.java.nio.file.Path nioRootPath = fs.getPath(rootUrl.toURI());
    final Path rootPath = paths.convert(nioRootPath);
    // Test a root/src resolves to null
    final Package result = moduleService.resolvePackage(rootPath);
    assertNull(result);
}
Also used : Path(org.uberfire.backend.vfs.Path) KieModuleService(org.kie.workbench.common.services.shared.project.KieModuleService) CreationalContext(javax.enterprise.context.spi.CreationalContext) Package(org.guvnor.common.services.project.model.Package) URL(java.net.URL) Bean(javax.enterprise.inject.spi.Bean) Test(org.junit.Test)

Aggregations

CreationalContext (javax.enterprise.context.spi.CreationalContext)129 Bean (javax.enterprise.inject.spi.Bean)110 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)10 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 ArrayList (java.util.ArrayList)4 Context (javax.enterprise.context.spi.Context)4 InjectionTarget (javax.enterprise.inject.spi.InjectionTarget)4 WebBeansContext (org.apache.webbeans.config.WebBeansContext)4 Annotation (java.lang.annotation.Annotation)3 Method (java.lang.reflect.Method)3 Type (java.lang.reflect.Type)3 HashMap (java.util.HashMap)3