@Test public void cloneProject() throws Exception { doReturn(mock(OrganizationalUnit.class)).when(organizationalUnitService).getOrganizationalUnit("space"); final CloneProjectRequest cloneProjectRequest = new CloneProjectRequest(); cloneProjectRequest.setName("myName"); helper.cloneProject("jobId", "space", cloneProjectRequest); verify(repositoryService).createRepository( any(), eq("git"), eq("myName"), repositoryEnvironmentConfigurationsCaptor.capture() ); RepositoryEnvironmentConfigurations config = repositoryEnvironmentConfigurationsCaptor.getValue(); assertEquals(false, config.getMirror()); assertEquals(false, config.getInit()); }
@Test public void cloneProject() throws Exception { doReturn(mock(OrganizationalUnit.class)).when(organizationalUnitService).getOrganizationalUnit("space"); final CloneProjectRequest cloneProjectRequest = new CloneProjectRequest(); cloneProjectRequest.setName("myName"); helper.cloneProject("jobId", "space", cloneProjectRequest); verify(repositoryService).createRepository( any(), eq("git"), eq("myName"), repositoryEnvironmentConfigurationsCaptor.capture() ); RepositoryEnvironmentConfigurations config = repositoryEnvironmentConfigurationsCaptor.getValue(); assertEquals(false, config.getMirror()); assertEquals(false, config.getInit()); }
@Test public void createOnlyTwoRepositories() throws Exception { verify(repositoryService, times(2)).createRepository(any(OrganizationalUnit.class), eq(GitRepository.SCHEME.toString()), anyString(), configsCaptor.capture()); final List<RepositoryEnvironmentConfigurations> allValues = configsCaptor.getAllValues(); final Set<String> observedSubdirectories = new HashSet<>(); allValues.forEach(configs -> { assertEquals(NIOGIT_PATH, assertInstanceOf(configs.getOrigin(), String.class)); assertFalse(assertInstanceOf(configs.getInit(), Boolean.class)); assertFalse(assertInstanceOf(configs.getMirror(), Boolean.class)); final String subdirectory = assertInstanceOf(configs.getSubdirectory(), String.class); observedSubdirectories.add(subdirectory); @SuppressWarnings("unchecked") final List<String> branches = assertInstanceOf(configs.getBranches(), List.class); final List<String> expectedBranches; if (subdirectory.equals("legacyProject1")) { expectedBranches = Arrays.asList("legacyMasterBranch", "legacyDevBranch"); } else if (subdirectory.equals("legacyProject2")) { expectedBranches = Arrays.asList("legacyDevBranch"); } else { throw new AssertionError("Unrecognized subdirectory: " + subdirectory); } verify(service,times(2)).cleanupOrigin(any()); assertEquals("Unexpected branches for subdirectory " + subdirectory, new HashSet<>(expectedBranches), new HashSet<>(branches)); }); assertEquals(new HashSet<>(Arrays.asList("legacyProject1", "legacyProject2")), observedSubdirectories); }
@Test public void createOnlyTwoRepositories() throws Exception { verify(repositoryService, times(2)).createRepository(any(OrganizationalUnit.class), eq(GitRepository.SCHEME.toString()), anyString(), configsCaptor.capture()); final List<RepositoryEnvironmentConfigurations> allValues = configsCaptor.getAllValues(); final Set<String> observedSubdirectories = new HashSet<>(); allValues.forEach(configs -> { assertEquals(NIOGIT_PATH, assertInstanceOf(configs.getOrigin(), String.class)); assertFalse(assertInstanceOf(configs.getInit(), Boolean.class)); assertFalse(assertInstanceOf(configs.getMirror(), Boolean.class)); final String subdirectory = assertInstanceOf(configs.getSubdirectory(), String.class); observedSubdirectories.add(subdirectory); @SuppressWarnings("unchecked") final List<String> branches = assertInstanceOf(configs.getBranches(), List.class); final List<String> expectedBranches; if (subdirectory.equals("legacyProject1")) { expectedBranches = Arrays.asList("legacyMasterBranch", "legacyDevBranch"); } else if (subdirectory.equals("legacyProject2")) { expectedBranches = Arrays.asList("legacyDevBranch"); } else { throw new AssertionError("Unrecognized subdirectory: " + subdirectory); } verify(service,times(2)).cleanupOrigin(any()); assertEquals("Unexpected branches for subdirectory " + subdirectory, new HashSet<>(expectedBranches), new HashSet<>(branches)); }); assertEquals(new HashSet<>(Arrays.asList("legacyProject1", "legacyProject2")), observedSubdirectories); }