SLING-562 - pretty-print the json dump if the tidy selector is used. Contributed by Tobias Bocanegra, thanks!

git-svn-id: https://svn.apache.org/repos/asf/incubator/sling/trunk@681080 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/JsonRenderingTest.java b/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/JsonRenderingTest.java
index f862723..5e99eea 100644
--- a/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/JsonRenderingTest.java
+++ b/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/JsonRenderingTest.java
@@ -23,6 +23,7 @@
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.sling.commons.testing.integration.HttpTestBase;
+import org.apache.sling.commons.testing.util.TestStringUtil;
 import org.apache.sling.servlets.post.SlingPostConstants;
 
 /** Test creating Nodes and rendering them in JSON */
@@ -174,4 +175,51 @@
                 + ")");
         }
     }
+    
+    public void testTidyNonRecursive() throws IOException {
+        {
+            final String json = getContent(createdNodeUrl + ".json", CONTENT_TYPE_JSON);
+            final String expected =
+                "{\"jcr:primaryType\":\"nt:unstructured\",\"text\":\"" + testText + "\"}";
+            assertEquals("Without .tidy selector, json should be flat", 
+                    expected, TestStringUtil.flatten(json));
+        }
+        
+        {
+            final String json = getContent(createdNodeUrl + ".tidy.json", CONTENT_TYPE_JSON);
+            final String expected = 
+                "{.  \"jcr:primaryType\": \"nt:unstructured\",.  \"text\": \"" + testText + "\".}";
+            assertEquals("With .tidy selector, json should be pretty-printed", 
+                    expected, TestStringUtil.flatten(json));
+        }
+    }
+    
+    public void testTidyRecursive() throws IOException {
+        final Map<String, String> props = new HashMap<String, String>();
+        props.put("text", testText);
+        props.put("a/b", "yes");
+        final String url = testClient.createNode(postUrl, props);
+        
+        {
+            final String json = getContent(url + ".tidy.infinity.json", CONTENT_TYPE_JSON);
+            final String expected = 
+                "{.  \"jcr:primaryType\": \"nt:unstructured\",.  \"text\": \"" + testText 
+                + "\",.  \"a\": {.    \"jcr:primaryType\": \"nt:unstructured\",.    \"b\": \"yes\".  }"
+                + ".}";
+            assertEquals("With .tidy.infinity selector, json should be pretty-printed", 
+                    expected, TestStringUtil.flatten(json));
+        }
+        
+        {
+            final String json = getContent(url + ".infinity.json", CONTENT_TYPE_JSON);
+            final String expected = 
+                "{\"jcr:primaryType\":\"nt:unstructured\",\"text\":"
+                + "\"" + testText + "\",\"a\":{\"jcr:primaryType\":"
+                + "\"nt:unstructured\",\"b\":\"yes\"}}"
+            ;
+            assertEquals("With .infinity selector only, json should be flat", 
+                    expected, TestStringUtil.flatten(json));
+        }
+        
+    }
 }
\ No newline at end of file