summaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2013-12-16 08:59:58 -0500
committerJames Moger <james.moger@gitblit.com>2013-12-16 09:36:57 -0500
commit206b4b09c872f3e9f078383c9a5c701b1549ff5c (patch)
tree7f837d3fa697ef541e5a3ae9d213aaf41514ebbd /src/test
parent0fe9792a9f194e68288c377810c33973d117923f (diff)
downloadgitblit-206b4b09c872f3e9f078383c9a5c701b1549ff5c.tar.gz
gitblit-206b4b09c872f3e9f078383c9a5c701b1549ff5c.zip
Sync bugtraq support for spec v0.3
Change-Id: I2c24d1201d4c36963a708b178e780c1828707269
Diffstat (limited to 'src/test')
-rw-r--r--src/test/bugtraq/com/syntevo/bugtraq/BugtraqFormatterTest.java51
-rw-r--r--src/test/bugtraq/com/syntevo/bugtraq/BugtraqParserTest.java49
2 files changed, 58 insertions, 42 deletions
diff --git a/src/test/bugtraq/com/syntevo/bugtraq/BugtraqFormatterTest.java b/src/test/bugtraq/com/syntevo/bugtraq/BugtraqFormatterTest.java
index 54f0e428..6bcf9870 100644
--- a/src/test/bugtraq/com/syntevo/bugtraq/BugtraqFormatterTest.java
+++ b/src/test/bugtraq/com/syntevo/bugtraq/BugtraqFormatterTest.java
@@ -29,34 +29,42 @@
*/
package com.syntevo.bugtraq;
-import junit.framework.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
-import java.util.*;
+import junit.framework.TestCase;
-import org.jetbrains.annotations.*;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
public class BugtraqFormatterTest extends TestCase {
// Accessing ==============================================================
- public void testSimple() throws BugtraqException {
- final BugtraqFormatter formatter = createFormatter(createEntry("https://jira.atlassian.com/browse/%BUGID%", "JRA-\\d+"));
+ public void testSimpleWithExtendedLink() throws BugtraqException {
+ final BugtraqFormatter formatter = createFormatter(createEntry("https://jira.atlassian.com/browse/JRA-%BUGID%", null, "JRA-\\d+", "\\d+", null));
doTest(formatter, "JRA-7399: Email subject formatting", l("JRA-7399", "https://jira.atlassian.com/browse/JRA-7399"), t(": Email subject formatting"));
doTest(formatter, " JRA-7399, JRA-7398: Email subject formatting", t(" "), l("JRA-7399", "https://jira.atlassian.com/browse/JRA-7399"), t(", "), l("JRA-7398", "https://jira.atlassian.com/browse/JRA-7398"), t(": Email subject formatting"));
doTest(formatter, "Fixed JRA-7399", t("Fixed "), l("JRA-7399", "https://jira.atlassian.com/browse/JRA-7399"));
}
+ public void testLinkText() throws BugtraqException {
+ final BugtraqFormatter formatter = createFormatter(createEntry("https://jira.atlassian.com/browse/JRA-%BUGID%", null, "JRA-\\d+", "\\d+", "JIRA-%BUGID%"));
+ doTest(formatter, " JRA-7399, JRA is text, JRA-7398: Email subject formatting", t(" "), l("JIRA-7399", "https://jira.atlassian.com/browse/JRA-7399"), t(", JRA is text, "), l("JIRA-7398", "https://jira.atlassian.com/browse/JRA-7398"), t(": Email subject formatting"));
+ }
+
public void testTwoNonIntersectingConfigurations() throws BugtraqException {
- final BugtraqFormatter formatter = createFormatter(createEntry("https://jira.atlassian.com/browse/%BUGID%", "JRA-\\d+"),
- createEntry("https://issues.apache.org/jira/browse/%BUGID%", "VELOCITY-\\d+"));
+ final BugtraqFormatter formatter = createFormatter(createEntry("https://jira.atlassian.com/browse/%BUGID%", null, null, "JRA-\\d+", null),
+ createEntry("https://issues.apache.org/jira/browse/%BUGID%", null, null, "VELOCITY-\\d+", null));
doTest(formatter, "JRA-7399, VELOCITY-847: fix", l("JRA-7399", "https://jira.atlassian.com/browse/JRA-7399"), t(", "), l("VELOCITY-847", "https://issues.apache.org/jira/browse/VELOCITY-847"), t(": fix"));
doTest(formatter, " JRA-7399: fix/VELOCITY-847", t(" "), l("JRA-7399", "https://jira.atlassian.com/browse/JRA-7399"), t(": fix/"), l("VELOCITY-847", "https://issues.apache.org/jira/browse/VELOCITY-847"));
doTest(formatter, "JRA-7399VELOCITY-847", l("JRA-7399", "https://jira.atlassian.com/browse/JRA-7399"), l("VELOCITY-847", "https://issues.apache.org/jira/browse/VELOCITY-847"));
}
public void testTwoIntersectingConfigurations() throws BugtraqException {
- final BugtraqFormatter formatter = createFormatter(createEntry("https://host1/%BUGID%", "A[AB]"),
- createEntry("https://host2/%BUGID%", "BA[A]?"));
+ final BugtraqFormatter formatter = createFormatter(createEntry("https://host1/%BUGID%", null, null, "A[AB]", null),
+ createEntry("https://host2/%BUGID%", null, null, "BA[A]?", null));
doTest(formatter, "AA: fix", l("AA", "https://host1/AA"), t(": fix"));
doTest(formatter, "AB: fix", l("AB", "https://host1/AB"), t(": fix"));
doTest(formatter, "BA: fix", l("BA", "https://host2/BA"), t(": fix"));
@@ -76,33 +84,36 @@ public class BugtraqFormatterTest extends TestCase {
private BugtraqFormatter createFormatter(BugtraqEntry ... entries) {
return new BugtraqFormatter(new BugtraqConfig(Arrays.asList(entries)));
}
-
- private BugtraqEntry createEntry(String url, String ... logRegexs) throws BugtraqException {
- return new BugtraqEntry(url, Arrays.asList(logRegexs));
+
+ private BugtraqEntry createEntry(String url, @Nullable String filterRegex, @Nullable String linkRegex, @NotNull String idRegex, @Nullable String linkText) throws BugtraqException {
+ return new BugtraqEntry(url, idRegex, linkRegex, filterRegex, linkText);
}
-
+
private Text t(String text) {
return new Text(text);
}
-
+
private Link l(String text, String url) {
return new Link(text, url);
}
-
+
private void doTest(BugtraqFormatter formatter, String message, Atom ... expectedAtoms) {
final List<Atom> actualAtoms = new ArrayList<Atom>();
+ final StringBuilder sb = new StringBuilder();
formatter.formatLogMessage(message, new BugtraqFormatter.OutputHandler() {
@Override
public void appendText(@NotNull String text) {
actualAtoms.add(t(text));
+ sb.append(text);
}
@Override
public void appendLink(@NotNull String name, @NotNull String target) {
actualAtoms.add(l(name, target));
+ sb.append(name);
}
});
-
+
assertEquals(Arrays.asList(expectedAtoms), actualAtoms);
}
@@ -110,7 +121,7 @@ public class BugtraqFormatterTest extends TestCase {
private static interface Atom {
}
-
+
private static class Text implements Atom {
private final String text;
@@ -133,11 +144,11 @@ public class BugtraqFormatterTest extends TestCase {
if (obj == null || obj.getClass() != getClass()) {
return false;
}
-
+
return text.equals(((Text)obj).text);
}
}
-
+
private static class Link implements Atom {
private final String text;
private final String url;
@@ -162,7 +173,7 @@ public class BugtraqFormatterTest extends TestCase {
if (obj == null || obj.getClass() != getClass()) {
return false;
}
-
+
return text.equals(((Link)obj).text)
&& url.equals(((Link)obj).url);
}
diff --git a/src/test/bugtraq/com/syntevo/bugtraq/BugtraqParserTest.java b/src/test/bugtraq/com/syntevo/bugtraq/BugtraqParserTest.java
index 424fd1c0..14b2a729 100644
--- a/src/test/bugtraq/com/syntevo/bugtraq/BugtraqParserTest.java
+++ b/src/test/bugtraq/com/syntevo/bugtraq/BugtraqParserTest.java
@@ -33,79 +33,84 @@ import junit.framework.*;
import java.util.*;
+import org.jetbrains.annotations.*;
+
public class BugtraqParserTest extends TestCase {
// Accessing ==============================================================
public void testSimple1() throws BugtraqException {
- final BugtraqParser parser = createParser("\\d");
- assertNull(parser.parse(""));
+ final BugtraqParser parser = createParser(null, null, "\\d+");
+ doTest("", parser);
doTest("1", parser, id(0, 0, "1"));
doTest("1 2 3", parser, id(0, 0, "1"), id(2, 2, "2"), id(4, 4, "3"));
}
public void testSimple2() throws BugtraqException {
- final BugtraqParser parser = createParser("(\\d)");
- assertNull(parser.parse(""));
+ final BugtraqParser parser = createParser(null, null, "(\\d+)");
doTest("1", parser, id(0, 0, "1"));
doTest("1 2 3", parser, id(0, 0, "1"), id(2, 2, "2"), id(4, 4, "3"));
}
public void testSimple3() throws BugtraqException {
- final BugtraqParser parser = createParser("(SG-\\d)");
- assertNull(parser.parse(""));
+ final BugtraqParser parser = createParser(null, null, "(SG-\\d+)");
doTest("SG-1", parser, id(0, 3, "SG-1"));
doTest("SG-1 SG-2 SG-3", parser, id(0, 3, "SG-1"), id(5, 8, "SG-2"), id(10, 13, "SG-3"));
}
public void testSimple4() throws BugtraqException {
- final BugtraqParser parser = createParser("SG-(\\d)");
- assertNull(parser.parse(""));
+ final BugtraqParser parser = createParser(null, null, "SG-(\\d+)");
doTest("SG-1", parser, id(3, 3, "1"));
doTest("SG-1 SG-2 SG-3", parser, id(3, 3, "1"), id(8, 8, "2"), id(13, 13, "3"));
}
- public void testTwoLevel1() throws BugtraqException {
- final BugtraqParser parser = createParser("(SG-\\d)", "\\d");
+ public void testFilter1() throws BugtraqException {
+ final BugtraqParser parser = createParser("(SG-\\d+)", null, "\\d+");
doTest("SG-1", parser, id(3, 3, "1"));
doTest("SG-1 SG-2 SG-3", parser, id(3, 3, "1"), id(8, 8, "2"), id(13, 13, "3"));
}
- public void testTwoLevel2() throws BugtraqException {
- final BugtraqParser parser = createParser("xSG-\\dx", "\\d");
+ public void testFilter2() throws BugtraqException {
+ final BugtraqParser parser = createParser("xSG-\\d+x", null, "\\d+");
doTest("SG-1 xSG-2x SG-3", parser, id(9, 9, "2"));
}
- public void testTwoLevel3() throws BugtraqException {
- final BugtraqParser parser = createParser("[Ii]ssues?:?((\\s*(,|and)?\\s*#\\d+)+)", "\\d");
+ public void testFilter3() throws BugtraqException {
+ final BugtraqParser parser = createParser("[Ii]ssues?:?((\\s*(,|and)?\\s*#\\d+)+)", null, "\\d+");
doTest("Issues #3, #4 and #5: Git Bugtraq Configuration options (see #12)", parser, id(8, 8, "3"), id(12, 12, "4"), id(19, 19, "5"));
}
- public void testThreeLevel() throws BugtraqException {
+ public void testLink() throws BugtraqException {
+ final BugtraqParser parser = createParser(null, "(SG-\\d+)", "\\d+");
+ doTest("SG-1", parser, id(0, 3, "1"));
+ doTest("SG-1 SG-2 SG-3", parser, id(0, 3, "1"), id(5, 8, "2"), id(10, 13, "3"));
+ }
+
+ public void testLinkAndFilter() throws BugtraqException {
final BugtraqParser parser = createParser("[ab]\\d[cd]", "a\\dc|b\\dd", "\\d");
- doTest("a1c a2d b3c b4d", parser, id(1, 1, "1"), id(13, 13, "4"));
+ doTest("a1c a2d b3c b4d", parser, id(0, 2, "1"), id(12, 14, "4"));
}
public void testFogBugz() throws BugtraqException {
- final BugtraqParser parser = createParser("(?:Bug[zs]?\\s*IDs?\\s*|Cases?)[#:; ]+((\\d+[ ,:;#]*)+)", "\\d");
- doTest("Bug IDs: 3, 4, 5", parser, id(9, 9, "3"), id(12, 12, "4"), id(15, 15, "5"));
+ final BugtraqParser parser = createParser("(?:Bug[zs]?\\s*IDs?\\s*|Cases?)[#:; ]+((\\d+[ ,:;#]*)+)", "[#]?\\d+", "\\d+");
+ doTest("Bug IDs: 3, #4, 5", parser, id(9, 9, "3"), id(12, 13, "4"), id(16, 16, "5"));
}
public void testFogBugzInvalid() throws BugtraqException {
- final BugtraqParser parser = createParser("Bug[zs]?\\s*IDs?\\s*|Cases?[#:; ]+((\\d+[ ,:;#]*)+)", "\\d");
+ final BugtraqParser parser = createParser("Bug[zs]?\\s*IDs?\\s*|Cases?[#:; ]+((\\d+[ ,:;#]*)+)", null, "\\d+");
doTest("Bug IDs: 3, 4, 5", parser);
}
// Utils ==================================================================
- private BugtraqParser createParser(String ... regexs) throws BugtraqException {
- return BugtraqParser.createInstance(Arrays.asList(regexs));
+ private BugtraqParser createParser(@Nullable String filterRegex, @Nullable String linkRegex, @NotNull String idRegex) throws BugtraqException {
+ return BugtraqParser.createInstance(idRegex, linkRegex, filterRegex);
}
private BugtraqParserIssueId id(int from, int to, String id) {
return new BugtraqParserIssueId(from, to, id);
}
-
+
private void doTest(String message, BugtraqParser parser, BugtraqParserIssueId... expectedIds) {
final List<BugtraqParserIssueId> actualIds = parser.parse(message);
assertEquals(expectedIds.length, actualIds.size());