Enhance filteredJson to clean up JSON strings.
* Simplify test code in IncludeIT and future ConfigIT.
Change-Id: Idf0dfde91c468e795e4be0b7d44fa95516ee6708
diff --git a/src/test/java/com/googlesource/gerrit/plugins/findowners/FindOwners.java b/src/test/java/com/googlesource/gerrit/plugins/findowners/FindOwners.java
index d414755..872cda4 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/findowners/FindOwners.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/findowners/FindOwners.java
@@ -182,12 +182,21 @@
return c.findApproval(accountCache, db);
}
- // Remove '"' and space; replace '\n' with ' '; ignore "owner_revision" and "HostName:*".
+ // To simplify test case code, the REST API returned JSON string is filtered to
+ // remove '\t', ' ' and '"', but replace "\\\"" with '"',
+ // replace '\n' with space, remove "owner_revision:*" and "HostName:*",
+ // and replace some unicode with simple characters.
protected static String filteredJson(String json) {
- return json.replaceAll("[\" ]*", "")
+ return json.replaceAll("[\t ]", "")
+ .replace("\\\"", "\t")
+ .replace("\"", "")
+ .replace('\t', '"')
.replace('\n', ' ')
.replaceAll("owner_revision:[^ ]* ", "")
- .replaceAll("HostName:[^ ]*, ", "");
+ .replaceAll("HostName:[^ ]*, ", "")
+ .replace("\\u0027", "'")
+ .replace("\\u003d", "=")
+ .replace("\\u003e", ">");
}
protected static String filteredJson(RestResponse response) throws Exception {
diff --git a/src/test/java/com/googlesource/gerrit/plugins/findowners/IncludeIT.java b/src/test/java/com/googlesource/gerrit/plugins/findowners/IncludeIT.java
index be64ad3..192fbf6 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/findowners/IncludeIT.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/findowners/IncludeIT.java
@@ -63,7 +63,7 @@
+ getRepoFileLog(projectName + ":refs/heads/master:./OWNERS", "OWNERS:(...)")
+ "parseLine:include:P1/P2:f1, "
+ "getRepoFile:P1/P2:refs/heads/master:f1, "
- + "hasReadAccessException:project\\u0027P1/P2\\u0027isunavailable, " // cannot read
+ + "hasReadAccessException:project'P1/P2'isunavailable, " // cannot read
+ "parseLine:include:(), " // missing file is treated as empty
+ concat("parseLine:include:", projectName, ":./d1/d2/../../f2, ")
+ getRepoFileLog(projectName + ":refs/heads/master:f2", "f2(NOTFOUND)")
@@ -114,7 +114,7 @@
+ getRepoFileLog(projectName + ":refs/heads/master:./OWNERS", "OWNERS:(...)")
+ "parseLine:include:P1/P2:f1, "
+ "getRepoFile:P1/P2:refs/heads/master:f1, "
- + "hasReadAccessException:project\\u0027P1/P2\\u0027isunavailable, "
+ + "hasReadAccessException:project'P1/P2'isunavailable, "
+ "parseLine:include:(), " // P1/P2 is still not found
+ concat("parseLine:include:", projectName, ":./d1/d2/../../f2, ")
+ getRepoFileLog(projectName + ":refs/heads/master:f2", "f2:(...)")