AbstractModuleService implements ModuleServiceCore<T>,
                   ModuleFactory<T> { @Override public void delete(final Path pathToPomXML, final String comment) { try { final org.uberfire.java.nio.file.Path projectDirectory = Paths.convert(pathToPomXML).getParent(); final Module module2Delete = resourceResolver.resolveModule(Paths.convert(projectDirectory)); final Optional<org.uberfire.java.nio.file.Path> parentPomPath = ofNullable(projectDirectory).flatMap(dir -> ofNullable(dir.getParent())) .map(dir -> dir.resolve(POM_PATH)) .filter(pom -> ioService.exists(pom)); final Optional<POM> parentPom = parentPomPath.map(pom -> pomService.load(Paths.convert(pom))); if (parentPomPath.isPresent() && parentPom.isPresent()) { ioService.delete(projectDirectory, StandardDeleteOption.NON_EMPTY_DIRECTORIES, commentedOptionFactory.makeCommentedOption(comment)); org.uberfire.java.nio.file.Path pomPath = parentPomPath.get(); POM pom = parentPom.get(); pom.setPackaging("pom"); pom.getModules().remove(module2Delete.getModuleName()); pomService.save(Paths.convert(pomPath), pom, null, "Removing child module " + module2Delete.getModuleName()); } else { Repository repo = repoService.getRepository(Paths.convert(projectDirectory)); repoService.removeRepository(repo.getSpace(), repo.getAlias()); } } catch (final Exception e) { throw ExceptionUtilities.handleException(e); } } protected  AbstractModuleService();  AbstractModuleService(final IOService ioService,
                                 final POMService pomService,
                                 final RepositoryService repoService,
                                 final Event<NewModuleEvent> newModuleEvent,
                                 final Event<NewPackageEvent> newPackageEvent,
                                 final Event<InvalidateDMOModuleCacheEvent> invalidateDMOCache,
                                 final SessionInfo sessionInfo,
                                 final CommentedOptionFactory commentedOptionFactory,
                                 final ModuleFinder moduleFinder,
                                 final ResourceResolver resourceResolver); @Override Set<Module> getAllModules(final Branch branch); @Override Package newPackage(final Package parentPackage,
                              final String packageName); @Override Path rename(final Path pathToPomXML,
                       final String newName,
                       final String comment); @Override void delete(final Path pathToPomXML,
                       final String comment); @Override void copy(final Path pathToPomXML,
                     final String newName,
                     final String comment); @Override void reImport(final Path pathToPomXML); @Override void createModuleDirectories(final Path repositoryRoot);  }
@Test public void testUseRepoServiceToDeleteRootModule() { when(path.getFileName()).thenReturn("pom.xml"); when(path.toURI()).thenReturn("file: when(resourceResolver.resolveModule(any(Path.class))).thenReturn(module); when(pomService.load(any())).thenReturn(mock(POM.class)); Repository repo = mock(Repository.class); when(repoService.getRepository(eq(org.uberfire.backend.server.util.Paths.convert(Paths.get("file: String alias = "repo-alias"; when(repo.getAlias()).thenReturn(alias); Space space = new Space("space"); when(repo.getSpace()).thenReturn(space); abstractProjectService.delete(path, ""); verify(repoService).removeRepository(eq(space), eq(alias)); verify(ioService, times(0)).delete(any(), any()); }
@Test public void testUseIOServiceToDeleteSubModule() { when(path.getFileName()).thenReturn("pom.xml"); when(path.toURI()).thenReturn("file: when(ioService.exists(any())).thenReturn(true); when(resourceResolver.resolveModule(any(Path.class))).thenReturn(module); when(pomService.load(any())).thenReturn(mock(POM.class)); Repository repo = mock(Repository.class); when(repoService.getRepository(path)).thenReturn(repo); String alias = "repo-alias"; when(repo.getAlias()).thenReturn(alias); Space space = new Space("space"); when(repo.getSpace()).thenReturn(space); abstractProjectService.delete(path, ""); verify(repoService, times(0)).removeRepository(any(), any()); verify(ioService).delete(eq(Paths.get("file: }