1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 package org.eclipse.jgit.gitrepo;
44
45 import static java.nio.charset.StandardCharsets.UTF_8;
46 import static org.junit.Assert.assertTrue;
47
48 import java.io.ByteArrayInputStream;
49 import java.util.HashSet;
50 import java.util.Set;
51
52 import org.junit.Test;
53
54 public class ManifestParserTest {
55
56 @Test
57 public void testManifestParser() throws Exception {
58 String baseUrl = "https://git.google.com/";
59 StringBuilder xmlContent = new StringBuilder();
60 Set<String> results = new HashSet<String>();
61 xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
62 .append("<manifest>")
63 .append("<remote name=\"remote1\" fetch=\".\" />")
64 .append("<default revision=\"master\" remote=\"remote1\" />")
65 .append("<project path=\"foo\" name=\"")
66 .append("foo")
67 .append("\" groups=\"a,test\" />")
68 .append("<project path=\"bar\" name=\"")
69 .append("bar")
70 .append("\" groups=\"notdefault\" />")
71 .append("<project path=\"foo/a\" name=\"")
72 .append("a")
73 .append("\" groups=\"a\" />")
74 .append("<project path=\"b\" name=\"")
75 .append("b")
76 .append("\" groups=\"b\" />")
77 .append("</manifest>");
78
79 ManifestParser parser = new ManifestParser(
80 null, null, "master", baseUrl, null, null);
81 parser.read(new ByteArrayInputStream(xmlContent.toString().getBytes(UTF_8)));
82
83 results.clear();
84 results.add("foo");
85 results.add("bar");
86 results.add("foo/a");
87 results.add("b");
88 for (RepoProject proj : parser.getProjects()) {
89 String msg = String.format(
90 "project \"%s\" should be included in unfiltered projects",
91 proj.getPath());
92 assertTrue(msg, results.contains(proj.getPath()));
93 results.remove(proj.getPath());
94 }
95 assertTrue(
96 "Unfiltered projects shouldn't contain any unexpected results",
97 results.isEmpty());
98
99 results.clear();
100 results.add("foo");
101 results.add("b");
102 for (RepoProject proj : parser.getFilteredProjects()) {
103 String msg = String.format(
104 "project \"%s\" should be included in filtered projects",
105 proj.getPath());
106 assertTrue(msg, results.contains(proj.getPath()));
107 results.remove(proj.getPath());
108 }
109 assertTrue(
110 "Filtered projects shouldn't contain any unexpected results",
111 results.isEmpty());
112 }
113 }