WorkspaceProjectServiceImpl implements WorkspaceProjectService { @Override public void removeBranch(final String branchName, final WorkspaceProject project, final String userIdentifier) { final Branch branch = project .getRepository() .getBranch(branchName) .orElseThrow(() -> new IllegalStateException("The branch [" + branchName + "] does not exists")); try { ioService.startBatch(pathUtil.convert(branch.getPath()).getFileSystem()); repositoryService .getRepositoryFromSpace(project.getSpace(), project.getRepository().getAlias()) .getBranch(branch.getName()) .ifPresent(updatedBranch -> { final org.uberfire.java.nio.file.Path branchPath = pathUtil.convert(branch.getPath()); ioService.delete(branchPath); spaceConfigStorageRegistry .get(project.getSpace().getName()) .deleteBranchPermissions(branch.getName(), project.getRepository().getIdentifier()); changeRequestService.deleteChangeRequests(project.getSpace().getName(), project.getRepository().getAlias(), branch.getName(), userIdentifier); final Repository repository = repositoryService.getRepositoryFromSpace( project.getSpace(), project.getRepository().getAlias()); repositoryUpdatedEvent.fire(new RepositoryUpdatedEvent(repository)); }); } finally { ioService.endBatch(); } } WorkspaceProjectServiceImpl(); @Inject  WorkspaceProjectServiceImpl(final OrganizationalUnitService organizationalUnitService,
                                       final RepositoryService repositoryService,
                                       final SpacesAPI spaces,
                                       final Event<NewProjectEvent> newProjectEvent,
                                       final Event<RepositoryUpdatedEvent> repositoryUpdatedEvent,
                                       final Event<NewBranchEvent> newBranchEvent,
                                       final Instance<ModuleService<? extends Module>> moduleServices,
                                       final ModuleRepositoryResolver repositoryResolver,
                                       @Named("ioStrategy") final IOService ioService,
                                       final SpaceConfigStorageRegistry spaceConfigStorageRegistry,
                                       final PathUtil pathUtil,
                                       final ChangeRequestService changeRequestService,
                                       final POMService pomService); @Override Collection<WorkspaceProject> getAllWorkspaceProjects(); @Override Collection<WorkspaceProject> getAllWorkspaceProjects(final OrganizationalUnit organizationalUnit); @Override Collection<WorkspaceProject> getAllWorkspaceProjectsByName(final OrganizationalUnit organizationalUnit,
                                                                      final String name); Collection<WorkspaceProject> getAllWorkspaceProjectsByName(final OrganizationalUnit organizationalUnit,
                                                                      final String name,
                                                                      final boolean includeDeleted); @Override boolean spaceHasNoProjectsWithName(final OrganizationalUnit organizationalUnit,
                                              final String name,
                                              final WorkspaceProject projectToIgnore); @Override WorkspaceProject newProject(final OrganizationalUnit organizationalUnit,
                                       final POM pom); @Override WorkspaceProject newProject(final OrganizationalUnit organizationalUnit,
                                       final POM pom,
                                       final DeploymentMode mode); @Override WorkspaceProject newProject(final OrganizationalUnit organizationalUnit,
                                       final POM pom,
                                       final DeploymentMode mode,
                                       final List<Contributor> contributors); @Override WorkspaceProject newProject(final OrganizationalUnit organizationalUnit,
                                       final POM pom,
                                       final DeploymentMode mode,
                                       final List<Contributor> contributors,
                                       final Repository templateRepository); @Override WorkspaceProject newProject(final OrganizationalUnit organizationalUnit,
                                       final POM pom,
                                       final DeploymentMode mode,
                                       final List<Contributor> contributors,
                                       final Repository templateRepository,
                                       final String remoteRepositoryUrl); @Override String createFreshProjectName(final OrganizationalUnit organizationalUnit,
                                         final String name); @Override WorkspaceProject resolveProject(final Repository repository); @Override WorkspaceProject resolveProject(final Space space,
                                           final Branch branch); @Override WorkspaceProject resolveProject(final Space space,
                                           final Module module); @Override WorkspaceProject resolveProject(final Space space,
                                           final String name); @Override WorkspaceProject resolveProject(final Space space,
                                           final String projectName,
                                           final String branchName); @Override WorkspaceProject resolveProjectByRepositoryAlias(final Space space,
                                                            final String repositoryAlias); @Override WorkspaceProject resolveProject(final Space space,
                                           final Path path); @Override WorkspaceProject resolveProject(Path path); @Override void addBranch(final String newBranchName,
                          final String baseBranchName,
                          final WorkspaceProject project,
                          final String userIdentifier); @Override void removeBranch(final String branchName,
                             final WorkspaceProject project,
                             final String userIdentifier);  }
@Test public void removeBranchTest() { final Branch otherBranch = makeBranch("repo1-branch1", "repo1"); final org.uberfire.java.nio.file.Path baseBranchPath = mock(org.uberfire.java.nio.file.Path.class); final FileSystem fileSystem = mock(FileSystem.class); final FileSystemProvider fileSystemProvider = mock(FileSystemProvider.class); doReturn(fileSystemProvider).when(fileSystem).provider(); doReturn(fileSystem).when(baseBranchPath).getFileSystem(); doReturn(baseBranchPath).when(pathUtil).convert(any(Path.class)); final List<Branch> repo1Branches = Arrays.asList(makeBranch("repo1-branch1", repository1.getAlias()), makeBranch("repo1-branch2", repository1.getAlias())); when(repository1.getBranches()).thenReturn(repo1Branches); when(repository1.getBranch(anyString())).then(inv -> repo1Branches.stream().filter(b -> b.getName().equals(inv.getArgumentAt(0, String.class))).findFirst()); final WorkspaceProject project = mock(WorkspaceProject.class); doReturn(repository1).when(project).getRepository(); final Space space = new Space("my-space"); doReturn(space).when(project).getSpace(); doReturn(mock(SpaceConfigStorage.class)).when(spaceConfigStorageRegistry).get("my-space"); doReturn(repository1).when(repositoryService).getRepositoryFromSpace(space, "repository1"); workspaceProjectService.removeBranch(otherBranch.getName(), project, "user"); verify(ioService).startBatch(fileSystem); verify(ioService).delete(baseBranchPath); verify(ioService).endBatch(); verify(repositoryUpdatedEvent).fire(any()); }