You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2018/09/11 16:13:29 UTC
[sling-org-apache-sling-servlets-get] branch master updated:
SLING-7890 - investigating tidy booleans weirdness
This is an automated email from the ASF dual-hosted git repository.
bdelacretaz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-servlets-get.git
The following commit(s) were added to refs/heads/master by this push:
new 79e861f SLING-7890 - investigating tidy booleans weirdness
79e861f is described below
commit 79e861f1e2e19a2dca71fbab55e9c1c01d01c5ee
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Tue Sep 11 18:13:18 2018 +0200
SLING-7890 - investigating tidy booleans weirdness
---
.../get/impl/helpers/JsonRendererTest.java | 37 +++++++++++++++++++---
src/test/resources/data.json | 6 ++++
2 files changed, 39 insertions(+), 4 deletions(-)
diff --git a/src/test/java/org/apache/sling/servlets/get/impl/helpers/JsonRendererTest.java b/src/test/java/org/apache/sling/servlets/get/impl/helpers/JsonRendererTest.java
index 2ad1cd7..720b483 100644
--- a/src/test/java/org/apache/sling/servlets/get/impl/helpers/JsonRendererTest.java
+++ b/src/test/java/org/apache/sling/servlets/get/impl/helpers/JsonRendererTest.java
@@ -109,7 +109,7 @@ public class JsonRendererTest {
@Test
public void testISO8601() throws IOException {
context.requestPathInfo().setSelectorString("1");
- String created = responseToJSON().getString("created");
+ String created = getJsonFromReader().getString("created");
Calendar cal = ISO8601.parse(created);
// at the time of the test the offset it not preserved
// if we did direct string comparison the time would be different
@@ -131,21 +131,50 @@ public class JsonRendererTest {
@Test
public void testBoolean() throws IOException {
context.requestPathInfo().setSelectorString("1");
- assertTrue(responseToJSON().getBoolean("active"));
+ assertTrue(getJsonFromReader().getBoolean("active"));
}
@Test
// JSON impl only support Integers, JCR only supports Long values.
public void testNumber() throws IOException {
context.requestPathInfo().setSelectorString("1");
- assertTrue(responseToJSON().getInt("number") == 2);
+ assertTrue(getJsonFromReader().getInt("number") == 2);
}
- private JsonObject responseToJSON() throws IOException {
+ @Test
+ // TODO investigating SLING-7890 - needs cleanup once we find out exactly what's going on
+ public void testBooleansNoTidy() throws IOException {
+ context.currentResource("/content/booleans");
+ final String expected = "{\"b2\":false,\"jcr:primaryType\":\"nt:unstructured\",\"s1\":\"true\",\"b1\":true,\"s2\":\"false\"}";
+ assertEquals(expected, getJsonFromRequestResponse());
+ }
+
+ @Test
+ // TODO investigating SLING-7890 - needs cleanup once we find out exactly what's going on
+ public void testBooleansWithTidy() throws IOException {
+ context.currentResource("/content/booleans");
+ context.requestPathInfo().setSelectorString(".tidy");
+ final String expected = "{\n" +
+ " \"b2\": false,\n" +
+ " \"jcr:primaryType\": \"nt:unstructured\",\n" +
+ " \"s1\": \"true\",\n" +
+ " \"b1\": true,\n" +
+ " \"s2\": \"false\"\n" +
+ " }";
+ assertEquals(expected, getJsonFromRequestResponse());
+ }
+
+ private JsonObject getJsonFromReader() throws IOException {
jrs.render(request, response);
String out = response.getOutputAsString();
JsonObject job = Json.createReader(new StringReader(out)).readObject();
return job;
}
+ private String getJsonFromRequestResponse() throws IOException {
+ final JsonRenderer renderer = new JsonRenderer(1000, true);
+ renderer.render(request, response);
+ return response.getOutputAsString();
+ }
+
}
\ No newline at end of file
diff --git a/src/test/resources/data.json b/src/test/resources/data.json
index 8f2baea..1be684c 100644
--- a/src/test/resources/data.json
+++ b/src/test/resources/data.json
@@ -17,5 +17,11 @@
"tags" : {
"resourceType" : "tags"
}
+ },
+ "booleans" : {
+ "b1" : true,
+ "b2" : false,
+ "s1" : "true",
+ "s2" : "false"
}
}
\ No newline at end of file