Skip to content

Commit

Permalink
[JENKINS-18574] Add log parsing test
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-beck committed May 3, 2014
1 parent 3626e90 commit 8a1e46f
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 2 deletions.
58 changes: 56 additions & 2 deletions src/test/java/hudson/scm/SubversionChangeLogParserTest.java
Expand Up @@ -26,16 +26,46 @@ public class SubversionChangeLogParserTest extends AbstractSubversionTest {
@Test
@Bug(10324)
public void testPathsSortedAlphabetically() throws URISyntaxException, IOException, SAXException {
givenAChangelogFileWithUnsortedPaths();
givenAChangelogFileWithUnsortedPathsInLegacyFormat();
whenChangelogFileIsParsed();
thenAffectedPathsMustBeSortedAlphabetically();
}

@Test
@Bug(18574)
public void testPathsEqualToValues() throws URISyntaxException, IOException, SAXException {
givenAChangelogFileWithUnsortedPathsInLegacyFormat();
whenChangelogFileIsParsed();
thenPathsMustBeEqualToValues();
}

private void givenAChangelogFileWithUnsortedPaths() throws URISyntaxException {
@Test
@Bug(18574)
public void testValueIsRepoPath() throws URISyntaxException, IOException, SAXException {
givenAChangelogFileWithUnsortedPathsInLegacyFormat();
whenChangelogFileIsParsed();
thenValuesMustStartWithSlash();
}

@Test
@Bug(18574)
public void testNewChangelogFileForDifferentPathAndValue() throws URISyntaxException, IOException, SAXException {
givenAChangelogFileWithRelativePathAttributes();
whenChangelogFileIsParsed();
thenValuesMustStartWithSlash();
andPathsMustNotStartWithSlash();
}

private void givenAChangelogFileWithUnsortedPathsInLegacyFormat() throws URISyntaxException {
URL url = SubversionChangeLogParserTest.class.getResource("changelog_unsorted.xml");
this.changelogFile = new File(url.toURI().getSchemeSpecificPart());
}

private void givenAChangelogFileWithRelativePathAttributes() throws URISyntaxException {
URL url = SubversionChangeLogParserTest.class.getResource("changelog_relativepath.xml");
this.changelogFile = new File(url.toURI().getSchemeSpecificPart());
}

private void whenChangelogFileIsParsed() throws IOException, SAXException {
this.changeLogSet = new SubversionChangeLogParser(false).parse(null, this.changelogFile);
}
Expand All @@ -49,4 +79,28 @@ private void thenAffectedPathsMustBeSortedAlphabetically() {
}
}
}

private void thenPathsMustBeEqualToValues() {
for(LogEntry entry : changeLogSet.getLogs()) {
for(Path path : entry.getPaths()) {
Assert.assertEquals(path.getPath(), path.getValue());
}
}
}

private void thenValuesMustStartWithSlash() {
for(LogEntry entry : changeLogSet.getLogs()) {
for(Path path : entry.getPaths()) {
Assert.assertTrue(path.getValue().startsWith("/"));
}
}
}

private void andPathsMustNotStartWithSlash() {
for(LogEntry entry : changeLogSet.getLogs()) {
for(Path path : entry.getPaths()) {
Assert.assertFalse(path.getPath().startsWith("/"));
}
}
}
}
19 changes: 19 additions & 0 deletions src/test/resources/hudson/scm/changelog_relativepath.xml
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<log>
<logentry revision="39">
<author>user</author>
<date>2014-05-03T12:45:33.664887Z</date>
<paths>
<path action="M" kind="file" localPath="foo/bar/wc1-pX/trunk/foo">/projectX/trunk/foo</path>
</paths>
<msg>changed foo</msg>
</logentry>
<logentry revision="39">
<author>user</author>
<date>2014-05-03T12:45:33.664887Z</date>
<paths>
<path action="M" kind="file" localPath="wc2-t/baz/foo">/projectX/trunk/foo</path>
</paths>
<msg>changed foo</msg>
</logentry>
</log>

0 comments on commit 8a1e46f

Please sign in to comment.