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());
}
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());
}
}
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;
}
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);
}
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));
}
Aggregations