incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vram...@apache.org
Subject svn commit: r765630 - in /incubator/sling/trunk/bundles/commons/json/src: main/java/org/apache/sling/commons/json/jcr/JsonItemWriter.java test/java/org/apache/sling/commons/json/jcr/JsonItemWriterTest.java
Date Thu, 16 Apr 2009 13:29:31 GMT
Author: vramdal
Date: Thu Apr 16 13:29:31 2009
New Revision: 765630

URL: http://svn.apache.org/viewvc?rev=765630&view=rev
Log:
SLING-924 Fixes JsonItemWriter.dump(NodeIterator, Writer) + test

Modified:
    incubator/sling/trunk/bundles/commons/json/src/main/java/org/apache/sling/commons/json/jcr/JsonItemWriter.java
    incubator/sling/trunk/bundles/commons/json/src/test/java/org/apache/sling/commons/json/jcr/JsonItemWriterTest.java

Modified: incubator/sling/trunk/bundles/commons/json/src/main/java/org/apache/sling/commons/json/jcr/JsonItemWriter.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/commons/json/src/main/java/org/apache/sling/commons/json/jcr/JsonItemWriter.java?rev=765630&r1=765629&r2=765630&view=diff
==============================================================================
--- incubator/sling/trunk/bundles/commons/json/src/main/java/org/apache/sling/commons/json/jcr/JsonItemWriter.java
(original)
+++ incubator/sling/trunk/bundles/commons/json/src/main/java/org/apache/sling/commons/json/jcr/JsonItemWriter.java
Thu Apr 16 13:29:31 2009
@@ -73,7 +73,7 @@
         final JSONWriter w = new JSONWriter(out);
         w.array();
         while (it.hasNext()) {
-            dumpSingleNode(it.nextNode(), w, 1, 0);
+            dump(it.nextNode(), w, 1, 1);
         }
         w.endArray();
     }

Modified: incubator/sling/trunk/bundles/commons/json/src/test/java/org/apache/sling/commons/json/jcr/JsonItemWriterTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/commons/json/src/test/java/org/apache/sling/commons/json/jcr/JsonItemWriterTest.java?rev=765630&r1=765629&r2=765630&view=diff
==============================================================================
--- incubator/sling/trunk/bundles/commons/json/src/test/java/org/apache/sling/commons/json/jcr/JsonItemWriterTest.java
(original)
+++ incubator/sling/trunk/bundles/commons/json/src/test/java/org/apache/sling/commons/json/jcr/JsonItemWriterTest.java
Thu Apr 16 13:29:31 2009
@@ -19,12 +19,17 @@
 import java.io.StringWriter;
 
 import javax.jcr.Node;
+import javax.jcr.NodeIterator;
 import javax.jcr.RepositoryException;
 
 import junit.framework.TestCase;
 
 import org.apache.sling.commons.json.JSONException;
 import org.apache.sling.commons.testing.jcr.MockNode;
+import org.apache.sling.commons.testing.jcr.MockNodeIterator;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 /** Test the JsonItemWriter */
 public class JsonItemWriterTest extends TestCase {
@@ -49,4 +54,23 @@
         n.setProperty("testprop", values);
         assertEquals("{\"testprop\":[\"1234\",\"yes\"]}",getJson(n, 0));
     }
+
+    /**
+     * See <a href="https://issues.apache.org/jira/browse/SLING-924">SLING-924</a>
+     */
+    public void testOutputIterator() throws JSONException, RepositoryException {
+        MockNode node1 = new MockNode("/node1");
+        MockNode node2 = new MockNode("/node2");
+        node1.addNode("node3");
+        node1.setProperty("name", "node1");
+        node2.setProperty("name", "node2");
+        final NodeIterator it = new MockNodeIterator(new Node[]{node1, node2});
+        final StringWriter sw = new StringWriter();
+        writer.dump(it, sw);
+        Pattern testPattern = Pattern.compile("\\{(.[^\\}]*)\\}"); // Pattern to look for
a {...}
+        Matcher matcher = testPattern.matcher(sw.toString());
+        assertTrue("Did not produce a JSON object", matcher.find()); // Find first JSON object
+        assertTrue("Did not produce a 2nd JSON object", matcher.find()); // Find second JSON
object
+        assertFalse("Produced a JSON object for a child node", matcher.find()); // Assert
no child node has been created
+    }
 }



Mime
View raw message