private Map<Partition, List<Module>> getModulesByRootDirAndSpace(final OrganizationalUnit ou, final Repository legacyRepository) { final Map<Partition, List<Module>> modulesByDirectory = new HashMap<>(); legacyRepository.getBranches() .stream() .flatMap(branch -> moduleService.getAllModules(branch).stream()) .forEach(module -> { final String fullURI = pathUtil.normalizePath(module.getRootPath()).toURI(); final String branchlessPath = fullURI.replaceFirst("^[A-Za-z]+://([^@]+@)?", ""); final Partition partition = new Partition(branchlessPath, ou); final List<Module> modules = modulesByDirectory.computeIfAbsent(partition, ignore -> new ArrayList<>()); modules.add(module); }); return modulesByDirectory; }
private Map<Partition, List<Module>> getModulesByRootDirAndSpace(final OrganizationalUnit ou, final Repository legacyRepository) { final Map<Partition, List<Module>> modulesByDirectory = new HashMap<>(); legacyRepository.getBranches() .stream() .flatMap(branch -> moduleService.getAllModules(branch).stream()) .forEach(module -> { final String fullURI = pathUtil.normalizePath(module.getRootPath()).toURI(); final String branchlessPath = fullURI.replaceFirst("^[A-Za-z]+://([^@]+@)?", ""); final Partition partition = new Partition(branchlessPath, ou); final List<Module> modules = modulesByDirectory.computeIfAbsent(partition, ignore -> new ArrayList<>()); modules.add(module); }); return modulesByDirectory; }
@Override public Collection<Module> getModules(final Space space, final String repositoryAlias, final String branchName) { checkNotNull("repositoryAlias", repositoryAlias); checkNotNull("branchName", branchName); final Repository repository = repositoryService.getRepositoryFromSpace(space, repositoryAlias); if (repository == null) { return new ArrayList<>(); } else { final Optional<Branch> branch = repository.getBranch(branchName); if (branch.isPresent()) { return moduleService.getAllModules(branch.get()); } else { return new ArrayList<>(); } } }
private void setUpDevBranch() { final HashSet<Module> devBranchModules = new HashSet<>(); final Module mockModule = mockModule("legacyProject1", legacyDevBranchProject1RootPath); devBranchModules.add(mockModule); final Module mockModule2 = mockModule("legacyProject2", legacyDevBranchProject2RootPath); devBranchModules.add(mockModule2); doReturn(devBranchModules).when(moduleService).getAllModules(legacyDevBranch); }
private void setUpMasterBranch() { final HashSet<Module> masterBranchModules = new HashSet<>(); final Module mockModule = mockModule("legacyProject1", legacyMasterBranchProject1RootPath); masterBranchModules.add(mockModule); doReturn(masterBranchModules).when(moduleService).getAllModules(legacyMasterBranch); final Path masterRoot = mock(Path.class); when(legacyMasterBranch.getPath()).thenReturn(masterRoot); }
private void setUpMasterBranch() { final HashSet<Module> masterBranchModules = new HashSet<>(); final Module mockModule = mockModule("legacyProject1", legacyMasterBranchProject1RootPath); masterBranchModules.add(mockModule); doReturn(masterBranchModules).when(moduleService).getAllModules(legacyMasterBranch); final Path masterRoot = mock(Path.class); when(legacyMasterBranch.getPath()).thenReturn(masterRoot); }
private void setUpDevBranch() { final HashSet<Module> devBranchModules = new HashSet<>(); final Module mockModule = mockModule("legacyProject1", legacyDevBranchProject1RootPath); devBranchModules.add(mockModule); final Module mockModule2 = mockModule("legacyProject2", legacyDevBranchProject2RootPath); devBranchModules.add(mockModule2); doReturn(devBranchModules).when(moduleService).getAllModules(legacyDevBranch); }
@Test public void testProjects() { final Repository repository = mock(Repository.class); final Branch branch = new Branch(BRANCH_NAME, mock(Path.class)); doReturn(Optional.of(branch)).when(repository).getBranch(eq(BRANCH_NAME)); @SuppressWarnings("unchecked") final Set<Module> modules = mock(Set.class); when(repositoryService.getRepositoryFromSpace(SPACE, REPO_NAME)).thenReturn(repository); when(moduleService.getAllModules(branch)).thenReturn(modules); final Collection<Module> result = service.getModules(SPACE, REPO_NAME, BRANCH_NAME); assertEquals(modules, result); }