Search in sources :

Example 46 with KieModuleService

use of org.kie.workbench.common.services.shared.project.KieModuleService in project kie-wb-common by kiegroup.

the class FindRulesByModuleQueryValidIndexTermsTest method getModuleService.

@Override
protected KieModuleService getModuleService() {
    final KieModuleService mock = super.getModuleService();
    when(mock.resolveModule(any(org.uberfire.backend.vfs.Path.class))).thenAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            org.uberfire.backend.vfs.Path resource = (org.uberfire.backend.vfs.Path) invocationOnMock.getArguments()[0];
            if (resource.toURI().contains(TEST_MODULE_ROOT)) {
                return getKieModuleMock(TEST_MODULE_ROOT, TEST_MODULE_NAME);
            } else if (resource.toURI().contains(SOME_OTHER_PROJECT_ROOT)) {
                return getKieModuleMock(SOME_OTHER_PROJECT_ROOT, SOME_OTHER_PROJECT_NAME);
            } else {
                return null;
            }
        }
    });
    return mock;
}
Also used : KieModuleService(org.kie.workbench.common.services.shared.project.KieModuleService) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock)

Example 47 with KieModuleService

use of org.kie.workbench.common.services.shared.project.KieModuleService in project kie-wb-common by kiegroup.

the class ModuleImplResolveModuleValidTest method testResolveModuleWithRootPath.

@Test
public void testResolveModuleWithRootPath() 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");
    final org.uberfire.java.nio.file.Path nioRootPath = fs.getPath(rootUrl.toURI());
    final Path rootPath = paths.convert(nioRootPath);
    // Test a root resolves to the Module's root
    final Module result = moduleService.resolveModule(rootPath);
    assertEquals(rootPath.toURI(), result.getRootPath().toURI());
}
Also used : Path(org.uberfire.backend.vfs.Path) KieModuleService(org.kie.workbench.common.services.shared.project.KieModuleService) CreationalContext(javax.enterprise.context.spi.CreationalContext) Module(org.guvnor.common.services.project.model.Module) URL(java.net.URL) Bean(javax.enterprise.inject.spi.Bean) Test(org.junit.Test)

Example 48 with KieModuleService

use of org.kie.workbench.common.services.shared.project.KieModuleService in project kie-wb-common by kiegroup.

the class ModuleImplResolveModuleValidTest method testResolveModuleWithResourcesFile.

@Test
public void testResolveModuleWithResourcesFile() 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");
    final org.uberfire.java.nio.file.Path nioRootPath = fs.getPath(rootUrl.toURI());
    final Path rootPath = paths.convert(nioRootPath);
    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 child folder resolves to the Module's root
    final Module result = moduleService.resolveModule(testPath);
    assertEquals(rootPath.toURI(), result.getRootPath().toURI());
}
Also used : Path(org.uberfire.backend.vfs.Path) KieModuleService(org.kie.workbench.common.services.shared.project.KieModuleService) CreationalContext(javax.enterprise.context.spi.CreationalContext) Module(org.guvnor.common.services.project.model.Module) URL(java.net.URL) Bean(javax.enterprise.inject.spi.Bean) Test(org.junit.Test)

Example 49 with KieModuleService

use of org.kie.workbench.common.services.shared.project.KieModuleService in project kie-wb-common by kiegroup.

the class ModuleImplResolveModuleValidTest method testResolveModuleWithGlobalFile.

@Test
public void testResolveModuleWithGlobalFile() 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");
    final org.uberfire.java.nio.file.Path nioRootPath = fs.getPath(rootUrl.toURI());
    final Path rootPath = paths.convert(nioRootPath);
    final URL testUrl = this.getClass().getResource("/ModuleBackendTestModuleStructureValid/global/themes.json");
    final org.uberfire.java.nio.file.Path nioTestPath = fs.getPath(testUrl.toURI());
    final Path testPath = paths.convert(nioTestPath);
    // Test a child folder resolves to the Module's root
    final Module result = moduleService.resolveModule(testPath);
    assertEquals(rootPath.toURI(), result.getRootPath().toURI());
}
Also used : Path(org.uberfire.backend.vfs.Path) KieModuleService(org.kie.workbench.common.services.shared.project.KieModuleService) CreationalContext(javax.enterprise.context.spi.CreationalContext) Module(org.guvnor.common.services.project.model.Module) URL(java.net.URL) Bean(javax.enterprise.inject.spi.Bean) Test(org.junit.Test)

Example 50 with KieModuleService

use of org.kie.workbench.common.services.shared.project.KieModuleService 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)

Aggregations

KieModuleService (org.kie.workbench.common.services.shared.project.KieModuleService)77 CreationalContext (javax.enterprise.context.spi.CreationalContext)67 Bean (javax.enterprise.inject.spi.Bean)67 Test (org.junit.Test)66 Path (org.uberfire.backend.vfs.Path)59 URL (java.net.URL)58 Package (org.guvnor.common.services.project.model.Package)49 Module (org.guvnor.common.services.project.model.Module)15 Before (org.junit.Before)4 KieModule (org.kie.workbench.common.services.shared.project.KieModule)4 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4 Path (org.uberfire.java.nio.file.Path)4 GAV (org.guvnor.common.services.project.model.GAV)3 POM (org.guvnor.common.services.project.model.POM)3 Answer (org.mockito.stubbing.Answer)3 HashSet (java.util.HashSet)2 Set (java.util.Set)2 FolderListing (org.kie.workbench.common.screens.explorer.model.FolderListing)2 IOException (java.io.IOException)1 TreeSet (java.util.TreeSet)1