Search in sources :

Example 36 with KieModuleService

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

the class ModuleServiceImplResolvePackageValidTest method testResolvePackageWithJavaFileInSubPackage.

@Test
public void testResolvePackageWithJavaFileInSubPackage() 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/main/java/org/kie/test");
    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/java/org/kie/test/Bean.java");
    final org.uberfire.java.nio.file.Path nioTestPath = fs.getPath(testUrl.toURI());
    final Path testPath = paths.convert(nioTestPath);
    // Test a Java file resolves to the containing package
    final Package result = moduleService.resolvePackage(testPath);
    assertEquals(rootPath.toURI(), result.getPackageMainSrcPath().toURI());
}
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 37 with KieModuleService

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

the class ModuleServiceImplResolvePackagesTest method testResolvePackages.

@Test
public void testResolvePackages() 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 root = this.getClass().getResource("/ModuleBackendTestModule1");
    final URL pomUrl = this.getClass().getResource("/ModuleBackendTestModule1/pom.xml");
    final URL kmodule = this.getClass().getResource("/ModuleBackendTestModule1/src/main/resources/META-INF/kmodule.xml");
    final URL imports = this.getClass().getResource("/ModuleBackendTestModule1/project.imports");
    final URL repositories = this.getClass().getResource("/ModuleBackendTestModule1/project.repositories");
    final URL packageNameWhiteList = this.getClass().getResource("/ModuleBackendTestModule1/package-names-white-list");
    final POM pom = mock(POM.class);
    when(pom.getName()).thenReturn("ModuleBackendTestModule1");
    final Module module = new KieModule(paths.convert(fs.getPath(root.toURI())), paths.convert(fs.getPath(pomUrl.toURI())), paths.convert(fs.getPath(kmodule.toURI())), paths.convert(fs.getPath(imports.toURI())), paths.convert(fs.getPath(repositories.toURI())), paths.convert(fs.getPath(packageNameWhiteList.toURI())), pom);
    {
        Set<Package> packages = moduleService.resolvePackages((Package) null);
        assertEquals(0, packages.size());
    }
    Package defaultPkg = null;
    {
        Set<Package> packages = moduleService.resolvePackages(module);
        assertEquals(6, packages.size());
        for (final Package pkg : packages) {
            if (pkg.getCaption().equals("<default>")) {
                defaultPkg = pkg;
                break;
            }
        }
        assertEquals(defaultPkg, moduleService.resolveDefaultPackage(module));
    }
    assertNotNull(defaultPkg);
    assertEquals("<default>", defaultPkg.getCaption());
    assertEquals("<default>", defaultPkg.getRelativeCaption());
    Package rootPkg = null;
    {
        Set<Package> packages = moduleService.resolvePackages(defaultPkg);
        assertEquals(1, packages.size());
        rootPkg = packages.iterator().next();
    }
    assertNotNull(rootPkg);
    assertEquals("org", rootPkg.getCaption());
    assertEquals("org", rootPkg.getRelativeCaption());
    Package kiePkg = null;
    {
        Set<Package> packages = moduleService.resolvePackages(rootPkg);
        assertEquals(1, packages.size());
        kiePkg = packages.iterator().next();
    }
    assertNotNull(kiePkg);
    assertEquals("org.kie", kiePkg.getCaption());
    assertEquals("kie", kiePkg.getRelativeCaption());
    assertEquals(rootPkg, moduleService.resolveParentPackage(kiePkg));
    assertEquals(defaultPkg, moduleService.resolveParentPackage(rootPkg));
    assertNull(moduleService.resolveParentPackage(defaultPkg));
    {
        Set<Package> packages = moduleService.resolvePackages(kiePkg);
        assertEquals(1, packages.size());
    }
}
Also used : KieModuleService(org.kie.workbench.common.services.shared.project.KieModuleService) CreationalContext(javax.enterprise.context.spi.CreationalContext) Set(java.util.Set) Package(org.guvnor.common.services.project.model.Package) KieModule(org.kie.workbench.common.services.shared.project.KieModule) Module(org.guvnor.common.services.project.model.Module) URL(java.net.URL) KieModule(org.kie.workbench.common.services.shared.project.KieModule) Bean(javax.enterprise.inject.spi.Bean) POM(org.guvnor.common.services.project.model.POM) Test(org.junit.Test)

Example 38 with KieModuleService

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

the class BpmnFileIndexerTest method getModuleService.

@Override
protected KieModuleService getModuleService() {
    final org.uberfire.backend.vfs.Path mockRoot = mock(org.uberfire.backend.vfs.Path.class);
    when(mockRoot.toURI()).thenReturn(TEST_MODULE_ROOT);
    final KieModule mockModule = mock(KieModule.class);
    when(mockModule.getRootPath()).thenReturn(mockRoot);
    when(mockModule.getModuleName()).thenReturn(TEST_MODULE_NAME);
    POM mockPom = mock(POM.class);
    when(mockModule.getPom()).thenReturn(mockPom);
    GAV mockGAV = mock(GAV.class);
    when(mockPom.getGav()).thenReturn(mockGAV);
    when(mockGAV.toString()).thenReturn(DEPLOYMENT_ID);
    final Package mockPackage = mock(Package.class);
    when(mockPackage.getPackageName()).thenReturn(TEST_PACKAGE_NAME);
    final KieModuleService mockModuleService = mock(KieModuleService.class);
    when(mockModuleService.resolveModule(any(org.uberfire.backend.vfs.Path.class))).thenReturn(mockModule);
    when(mockModuleService.resolvePackage(any(org.uberfire.backend.vfs.Path.class))).thenReturn(mockPackage);
    return mockModuleService;
}
Also used : Path(org.uberfire.java.nio.file.Path) KieModuleService(org.kie.workbench.common.services.shared.project.KieModuleService) Package(org.guvnor.common.services.project.model.Package) GAV(org.guvnor.common.services.project.model.GAV) KieModule(org.kie.workbench.common.services.shared.project.KieModule) POM(org.guvnor.common.services.project.model.POM)

Example 39 with KieModuleService

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

the class ProjectExplorerContentResolverDefaultSelectionsTest method setUp.

@Before
public void setUp() throws Exception {
    // Ensure URLs use the default:// scheme
    fs.forceAsDefault();
    final KieModuleService moduleService = mock(KieModuleService.class);
    final ExplorerServiceHelper helper = mock(ExplorerServiceHelper.class);
    final ExplorerServiceHelper explorerServiceHelper = mock(ExplorerServiceHelper.class);
    repository1 = getGitRepository("repo1");
    repository2 = getGitRepository("repo2");
    repository1Module1 = createModule("master", "r1p1");
    repository1Modules = new HashSet<Module>() {

        {
            add(repository1Module1);
        }
    };
    repository2Module1 = createModule("master", "r2p1");
    repository2Modules = new HashSet<Module>() {

        {
            add(repository2Module1);
        }
    };
    userExplorerData = new UserExplorerData();
    helperWrapper = new HelperWrapper(helper);
    when(helper.getLastContent()).thenAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            return helperWrapper.getUserExplorerLastData();
        }
    });
    when(helper.loadUserContent()).thenReturn(userExplorerData);
    when(helper.getFolderListing(any(FolderItem.class), any(Module.class), any(Package.class), any(ActiveOptions.class))).thenReturn(new FolderListing(createFileItem(), Collections.EMPTY_LIST, Collections.EMPTY_LIST));
    when(moduleService.getAllModules(repository1.getDefaultBranch().get())).thenReturn(repository1Modules);
    when(moduleService.getAllModules(repository2.getDefaultBranch().get())).thenReturn(repository2Modules);
    doReturn(createPackage("master", repository1Module1.getModuleName())).when(moduleService).resolveDefaultPackage(repository1Module1);
    doReturn(createPackage("master", repository2Module1.getModuleName())).when(moduleService).resolveDefaultPackage(repository2Module1);
    resolver = new ProjectExplorerContentResolver(moduleService, helper, explorerServiceHelper, projectService);
}
Also used : ActiveOptions(org.kie.workbench.common.screens.explorer.service.ActiveOptions) KieModuleService(org.kie.workbench.common.services.shared.project.KieModuleService) FolderListing(org.kie.workbench.common.screens.explorer.model.FolderListing) FolderItem(org.kie.workbench.common.screens.explorer.model.FolderItem) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Package(org.guvnor.common.services.project.model.Package) Module(org.guvnor.common.services.project.model.Module) Before(org.junit.Before)

Example 40 with KieModuleService

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

the class ProjectExplorerContentResolverTest method setUp.

@Before
public void setUp() throws Exception {
    // Ensure URLs use the default:// scheme
    fs.forceAsDefault();
    final KieModuleService moduleService = mock(KieModuleService.class);
    final ExplorerServiceHelper helper = mock(ExplorerServiceHelper.class);
    space = new Space("test-realm");
    repository = getGitRepository();
    final UserExplorerData userExplorerData = new UserExplorerData();
    masterModules = new HashSet<>();
    masterModules.add(createModule("master", masterBranch, "module 1"));
    masterModules.add(createModule("master", masterBranch, "module 2"));
    devModules = new HashSet<>();
    devModules.add(createModule("dev-1.0.0", devBranch, "module 1"));
    devModules.add(createModule("dev-1.0.0", devBranch, "module 2"));
    helperWrapper = new HelperWrapper(helper);
    when(helper.getLastContent()).thenAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            return helperWrapper.getUserExplorerLastData();
        }
    });
    when(helper.loadUserContent()).thenReturn(userExplorerData);
    when(helper.getFolderListing(any(FolderItem.class), any(Module.class), any(Package.class), any(ActiveOptions.class))).thenReturn(new FolderListing(getFileItem(), Collections.EMPTY_LIST, Collections.EMPTY_LIST));
    when(moduleService.getAllModules(masterBranch)).thenReturn(masterModules);
    when(moduleService.getAllModules(devBranch)).thenReturn(devModules);
    when(moduleService.resolveDefaultPackage(any(Module.class))).thenReturn(new Package());
    resolver = spy(new ProjectExplorerContentResolver(moduleService, helper, explorerServiceHelper, projectService));
}
Also used : Space(org.uberfire.spaces.Space) ActiveOptions(org.kie.workbench.common.screens.explorer.service.ActiveOptions) KieModuleService(org.kie.workbench.common.services.shared.project.KieModuleService) FolderListing(org.kie.workbench.common.screens.explorer.model.FolderListing) FolderItem(org.kie.workbench.common.screens.explorer.model.FolderItem) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Package(org.guvnor.common.services.project.model.Package) Module(org.guvnor.common.services.project.model.Module) Before(org.junit.Before)

Aggregations

KieModuleService (org.kie.workbench.common.services.shared.project.KieModuleService)75 CreationalContext (javax.enterprise.context.spi.CreationalContext)66 Bean (javax.enterprise.inject.spi.Bean)66 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)16 Before (org.junit.Before)4 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4 KieModule (org.kie.workbench.common.services.shared.project.KieModule)3 Answer (org.mockito.stubbing.Answer)3 Path (org.uberfire.java.nio.file.Path)3 Set (java.util.Set)2 POM (org.guvnor.common.services.project.model.POM)2 FolderItem (org.kie.workbench.common.screens.explorer.model.FolderItem)2 FolderListing (org.kie.workbench.common.screens.explorer.model.FolderListing)2 ActiveOptions (org.kie.workbench.common.screens.explorer.service.ActiveOptions)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1