summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorHan-Wen Nienhuys <hanwen@google.com>2017-04-06 13:44:10 +0900
committerMatthias Sohn <matthias.sohn@sap.com>2017-04-10 15:08:32 +0200
commit84d855cda7fc3f061778ea54b4f7ea569a75d7c3 (patch)
tree995dc4f9aa01e010d4fe61a9a6f06ffdcd935f95 /org.eclipse.jgit.test
parent52be84aea5f39d07e855a8d3dd8a1b8e97bd1de8 (diff)
downloadjgit-84d855cda7fc3f061778ea54b4f7ea569a75d7c3.tar.gz
jgit-84d855cda7fc3f061778ea54b4f7ea569a75d7c3.zip
ManifestParser: Throw exception if remote does not have fetch attribute
In the repo manifest documentation [1] the fetch attribute is marked as "#REQUIRED". If the fetch attribute is not specified, this would previously result in NullPointerException. Throw a SAXException instead. [1] https://gerrit.googlesource.com/git-repo/+/master/docs/manifest-format.txt Change-Id: Ib8ed8cee6074fe6bf8f9ac6fc7a1664a547d2d49 Signed-off-by: Han-Wen Nienhuys <hanwen@google.com> Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/ManifestParserTest.java33
1 files changed, 33 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/ManifestParserTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/ManifestParserTest.java
index c97b318800..4cd89e0aa9 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/ManifestParserTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/ManifestParserTest.java
@@ -44,12 +44,15 @@ package org.eclipse.jgit.gitrepo;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream;
+import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import org.junit.Test;
+import org.xml.sax.SAXException;
public class ManifestParserTest {
@@ -110,4 +113,34 @@ public class ManifestParserTest {
"Filtered projects shouldn't contain any unexpected results",
results.isEmpty());
}
+
+ @Test
+ public void testManifestParserWithMissingFetchOnRemote() throws Exception {
+ String baseUrl = "https://git.google.com/";
+ StringBuilder xmlContent = new StringBuilder();
+ xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
+ .append("<manifest>")
+ .append("<remote name=\"remote1\" />")
+ .append("<default revision=\"master\" remote=\"remote1\" />")
+ .append("<project path=\"foo\" name=\"").append("foo")
+ .append("\" groups=\"a,test\" />")
+ .append("<project path=\"bar\" name=\"").append("bar")
+ .append("\" groups=\"notdefault\" />")
+ .append("<project path=\"foo/a\" name=\"").append("a")
+ .append("\" groups=\"a\" />")
+ .append("<project path=\"b\" name=\"").append("b")
+ .append("\" groups=\"b\" />").append("</manifest>");
+
+ ManifestParser parser = new ManifestParser(null, null, "master",
+ baseUrl, null, null);
+ try {
+ parser.read(new ByteArrayInputStream(
+ xmlContent.toString().getBytes(UTF_8)));
+ fail("ManifestParser did not throw exception for missing fetch");
+ } catch (IOException e) {
+ assertTrue(e.getCause() instanceof SAXException);
+ assertTrue(e.getCause().getMessage()
+ .contains("is missing fetch attribute"));
+ }
+ }
}