private BuildCommand repoUrlUnchanged(String workingDir) { return test("-in", material.getUrl(), info(workingDir)); }
private BuildCommand repoUrlChanged(String workingDir) { return test("-nin", material.getUrl(), info(workingDir)); }
private SvnMaterial buildMockSvnMaterial(String url, String username, String password) { final SvnMaterial svnMaterial = mock(SvnMaterial.class); when(svnMaterial.getUrl()).thenReturn(url); when(svnMaterial.getUserName()).thenReturn(username); when(svnMaterial.getPassword()).thenReturn(password); return svnMaterial; } }
@Test public void shouldGetSvnInfoForMultipleMaterialsAndReturnMapOfUrlToUUID() { final SvnMaterial svnMaterial1 = mock(SvnMaterial.class); when(svnMaterial1.getUrl()).thenReturn("http://localhost/svn/project1"); final SvnMaterial svnMaterial2 = mock(SvnMaterial.class); when(svnMaterial2.getUrl()).thenReturn("http://foo.bar"); final HashSet<SvnMaterial> svnMaterials = new HashSet<>(); svnMaterials.add(svnMaterial1);
@Test public void shouldLogRepoInfoToConsoleOutWithOutFolder() throws Exception { final File workingCopy = new File("xyz"); updateMaterial(svnMaterial, revision, workingCopy); String stdout = outputStreamConsumer.getStdOut(); assertThat(stdout, containsString( String.format("Start updating %s at revision %s from %s", "files", revision.getRevision(), svnMaterial.getUrl()))); verify(subversion).checkoutTo(outputStreamConsumer, workingCopy, revision); }
public HashMap<String, String> createUrlToRemoteUUIDMap(Set<SvnMaterial> svnMaterials) { HashMap<String, String> urlToUUIDMap = new HashMap<>(); for (SvnMaterial svnMaterial : svnMaterials) { CommandLine command = svnExecutable().withArgs("info", "--xml"); addCredentials(command, new StringArgument(svnMaterial.getUserName()), new PasswordArgument(svnMaterial.getPassword())); final String queryUrl = svnMaterial.getUrl(); command.withArg(queryUrl); ConsoleResult consoleResult = null; try { consoleResult = executeCommand(command); urlToUUIDMap.putAll(svnLogXmlParser.parseInfoToGetUUID(consoleResult.outputAsString(), queryUrl, getBuilder())); } catch (RuntimeException e) { LOG.warn("Failed to map UUID to URL. SVN post-commit will not work for materials with URL {}", queryUrl, e); } } return urlToUUIDMap; }
@Test public void shouldBeAbleToConvertToJson() { SvnMaterial material = MaterialsMother.svnMaterial("url"); Map<String, Object> json = new LinkedHashMap<>(); material.toJson(json, revision); JsonValue jsonValue = from(json); assertThat(jsonValue.getString("scmType"), is("Subversion")); assertThat(new File(jsonValue.getString("location")), is(new File(material.getUrl()))); assertThat(jsonValue.getString("action"), is("Modified")); }
+ "</info>"; final SvnMaterial svnMaterial = mock(SvnMaterial.class); when(svnMaterial.getUrl()).thenReturn("http://localhost/svn/project1"); when(svnMaterial.getUserName()).thenReturn("user"); when(svnMaterial.getPassword()).thenReturn("password");
@Test public void shouldDoFreshCheckoutIfUrlChanges() throws Exception { updateTo(svnMaterial, new RevisionContext(revision), JobResult.Passed); console.clear(); File shouldBeRemoved = new File(workingDir, "svnDir/shouldBeRemoved"); shouldBeRemoved.createNewFile(); assertThat(shouldBeRemoved.exists(), is(true)); String repositoryUrl = new SvnTestRepo(temporaryFolder).projectRepositoryUrl(); assertNotEquals(svnTestRepo.projectRepositoryUrl(), repositoryUrl); SvnMaterial material = MaterialsMother.svnMaterial(repositoryUrl); updateTo(material, new RevisionContext(revision), JobResult.Passed); assertThat(material.getUrl(), is(repositoryUrl)); assertThat(console.output(), containsString("Checked out revision")); assertThat(console.output(), not(containsString("Updating"))); assertThat(shouldBeRemoved.exists(), is(false)); }
@Test @RunIf(value = EnhancedOSChecker.class, arguments = {DO_NOT_RUN_ON, WINDOWS}) public void shouldRecogniseSvnAsTheSameIfURLContainsChineseCharacters() throws Exception { File working = temporaryFolder.newFolder("shouldRecogniseSvnAsTheSameIfURLContainsSpaces"); SvnTestRepo repo = new SvnTestRepo(temporaryFolder, "a directory with 司徒空在此"); SvnMaterial material = repo.material(); assertThat(material.getUrl(), containsString("%20")); InMemoryStreamConsumer output = new InMemoryStreamConsumer(); material.freshCheckout(output, new SubversionRevision("3"), working); assertThat(output.getAllOutput(), containsString("Checked out revision 3")); InMemoryStreamConsumer output2 = new InMemoryStreamConsumer(); updateMaterial(material, new SubversionRevision("4"), working, output2); assertThat(output2.getAllOutput(), containsString("Updated to revision 4")); }
@Test @RunIf(value = EnhancedOSChecker.class, arguments = {DO_NOT_RUN_ON, WINDOWS}) public void shouldRecogniseSvnAsTheSameIfURLContainsSpaces() throws Exception { File working = temporaryFolder.newFolder("shouldRecogniseSvnAsTheSameIfURLContainsSpaces"); SvnTestRepo repo = new SvnTestRepo(temporaryFolder, "a directory with spaces"); SvnMaterial material = repo.material(); assertThat(material.getUrl(), containsString("%20")); InMemoryStreamConsumer output = new InMemoryStreamConsumer(); material.freshCheckout(output, new SubversionRevision("3"), working); assertThat(output.getAllOutput(), containsString("Checked out revision 3")); InMemoryStreamConsumer output2 = new InMemoryStreamConsumer(); material.updateTo(output2, working, new RevisionContext(new SubversionRevision("4")), new TestSubprocessExecutionContext()); assertThat(output2.getAllOutput(), containsString("Updated to revision 4")); }