summaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2013-11-25 13:02:20 -0500
committerJames Moger <james.moger@gitblit.com>2013-12-03 10:36:19 -0500
commitc6f3d01c29bb67156b8154bfe5780537b0ef43ac (patch)
tree9af2cdf8bc2137d937d48ef78ecd0971e9f7e7a6 /src/test
parentb6976fc0a4b1fd07e1e72fdd06597a0ffb9d48ef (diff)
downloadgitblit-c6f3d01c29bb67156b8154bfe5780537b0ef43ac.tar.gz
gitblit-c6f3d01c29bb67156b8154bfe5780537b0ef43ac.zip
Add support for per-repository bugtraq configuration
Imported the reference implementation contributed by syntevo which is used in their SmartGit product. You may create a bugtraq config section inf your .git/config file OR you may add a .gitbugtraq file to the root of your repository. Example: [bugtraq "issues"] url = http://code.google.com/p/gitblit/issues/detail?id=%BUGID% logRegex = "[Ii]ssue[-#:\\s]{1}\\d+" logRegex1 = "\\d+" [bugtraq "[pullrequests"] url = "https://github.com/gitblit/gitblit/pull/%BUGID%" logRegex = "(?:pull request|pull|pr)\\s*[-#]?([0-9]+)" Change-Id: Iaba305bf4280d08cc4d1abf533c2f1365470a43f
Diffstat (limited to 'src/test')
-rw-r--r--src/test/bugtraq/com/syntevo/bugtraq/BugtraqFormatterTest.java170
-rw-r--r--src/test/bugtraq/com/syntevo/bugtraq/BugtraqParserTest.java121
2 files changed, 291 insertions, 0 deletions
diff --git a/src/test/bugtraq/com/syntevo/bugtraq/BugtraqFormatterTest.java b/src/test/bugtraq/com/syntevo/bugtraq/BugtraqFormatterTest.java
new file mode 100644
index 00000000..54f0e428
--- /dev/null
+++ b/src/test/bugtraq/com/syntevo/bugtraq/BugtraqFormatterTest.java
@@ -0,0 +1,170 @@
+/*
+ * Copyright (c) 2013 by syntevo GmbH. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * o Neither the name of syntevo GmbH nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.syntevo.bugtraq;
+
+import junit.framework.*;
+
+import java.util.*;
+
+import org.jetbrains.annotations.*;
+
+public class BugtraqFormatterTest extends TestCase {
+
+ // Accessing ==============================================================
+
+ public void testSimple() throws BugtraqException {
+ final BugtraqFormatter formatter = createFormatter(createEntry("https://jira.atlassian.com/browse/%BUGID%", "JRA-\\d+"));
+ 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 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+"));
+ 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]?"));
+ 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"));
+ doTest(formatter, "BAA: fix", l("BAA", "https://host2/BAA"), t(": fix"));
+ doTest(formatter, "BAAA: fix", l("BAA", "https://host2/BAA"), t("A: fix"));
+ doTest(formatter, "BAAAA: fix", l("BAA", "https://host2/BAA"), l("AA", "https://host1/AA"), t(": fix"));
+ doTest(formatter, "BAAAAA: fix", l("BAA", "https://host2/BAA"), l("AA", "https://host1/AA"), t("A: fix"));
+ doTest(formatter, "BAAABA: fix", l("BAA", "https://host2/BAA"), l("AB", "https://host1/AB"), t("A: fix"));
+ doTest(formatter, "BAAABAA: fix", l("BAA", "https://host2/BAA"), l("AB", "https://host1/AB"), l("AA", "https://host1/AA"), t(": fix"));
+ doTest(formatter, "BAAB: fix", l("BAA", "https://host2/BAA"), t("B: fix"));
+ doTest(formatter, "BAAAB: fix", l("BAA", "https://host2/BAA"), l("AB", "https://host1/AB"), t(": fix"));
+ doTest(formatter, "BAABBA: fix", l("BAA", "https://host2/BAA"), t("B"), l("BA", "https://host2/BA"), t(": fix"));
+ }
+
+ // Utils ==================================================================
+
+ 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 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>();
+ formatter.formatLogMessage(message, new BugtraqFormatter.OutputHandler() {
+ @Override
+ public void appendText(@NotNull String text) {
+ actualAtoms.add(t(text));
+ }
+
+ @Override
+ public void appendLink(@NotNull String name, @NotNull String target) {
+ actualAtoms.add(l(name, target));
+ }
+ });
+
+ assertEquals(Arrays.asList(expectedAtoms), actualAtoms);
+ }
+
+ // Inner Classes ==========================================================
+
+ private static interface Atom {
+ }
+
+ private static class Text implements Atom {
+ private final String text;
+
+ private Text(String text) {
+ this.text = text;
+ }
+
+ @Override
+ public String toString() {
+ return text;
+ }
+
+ @Override
+ public int hashCode() {
+ return text.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ 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;
+
+ private Link(String text, String url) {
+ this.text = text;
+ this.url = url;
+ }
+
+ @Override
+ public String toString() {
+ return "(" + text + "," + url + ")";
+ }
+
+ @Override
+ public int hashCode() {
+ return text.hashCode() ^ url.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null || obj.getClass() != getClass()) {
+ return false;
+ }
+
+ return text.equals(((Link)obj).text)
+ && url.equals(((Link)obj).url);
+ }
+ }
+} \ No newline at end of file
diff --git a/src/test/bugtraq/com/syntevo/bugtraq/BugtraqParserTest.java b/src/test/bugtraq/com/syntevo/bugtraq/BugtraqParserTest.java
new file mode 100644
index 00000000..424fd1c0
--- /dev/null
+++ b/src/test/bugtraq/com/syntevo/bugtraq/BugtraqParserTest.java
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 2013 by syntevo GmbH. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * o Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * o Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * o Neither the name of syntevo GmbH nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.syntevo.bugtraq;
+
+import junit.framework.*;
+
+import java.util.*;
+
+public class BugtraqParserTest extends TestCase {
+
+ // Accessing ==============================================================
+
+ public void testSimple1() throws BugtraqException {
+ final BugtraqParser parser = createParser("\\d");
+ assertNull(parser.parse(""));
+ 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(""));
+ 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(""));
+ 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(""));
+ 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");
+ 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");
+ 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");
+ 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 {
+ 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"));
+ }
+
+ 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"));
+ }
+
+ public void testFogBugzInvalid() throws BugtraqException {
+ final BugtraqParser parser = createParser("Bug[zs]?\\s*IDs?\\s*|Cases?[#:; ]+((\\d+[ ,:;#]*)+)", "\\d");
+ doTest("Bug IDs: 3, 4, 5", parser);
+ }
+
+ // Utils ==================================================================
+
+ private BugtraqParser createParser(String ... regexs) throws BugtraqException {
+ return BugtraqParser.createInstance(Arrays.asList(regexs));
+ }
+
+ 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());
+
+ for (int index = 0; index < expectedIds.length; index++) {
+ final BugtraqParserIssueId expectedId = expectedIds[index];
+ final BugtraqParserIssueId actualId = actualIds.get(index);
+ assertEquals(expectedId.getFrom(), actualId.getFrom());
+ assertEquals(expectedId.getTo(), actualId.getTo());
+ assertEquals(expectedId.getId(), actualId.getId());
+ }
+ }
+} \ No newline at end of file