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 2008/12/23 14:36:51 UTC
svn commit: r728952 -
/incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/JsonRenderingTest.java
Author: bdelacretaz
Date: Tue Dec 23 05:36:51 2008
New Revision: 728952
URL: http://svn.apache.org/viewvc?rev=728952&view=rev
Log:
SLING-620 - order of properties in json output changed, make that irrelevant in json tidying tests
Modified:
incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/JsonRenderingTest.java
Modified: incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/JsonRenderingTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/JsonRenderingTest.java?rev=728952&r1=728951&r2=728952&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/JsonRenderingTest.java (original)
+++ incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/JsonRenderingTest.java Tue Dec 23 05:36:51 2008
@@ -23,7 +23,6 @@
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 */
@@ -176,22 +175,26 @@
}
}
+ protected static int countOccurences(String str, char toCount) {
+ int result = 0;
+ for(char c : str.toCharArray()) {
+ if(c == toCount) {
+ result++;
+ }
+ }
+ return result;
+ }
+
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));
- }
+ // Count end-of-line chars, there must be more in the tidy form
+ int noTidyCount = countOccurences(getContent(createdNodeUrl + ".json", CONTENT_TYPE_JSON), '\n');
+ int tidyCount = countOccurences(getContent(createdNodeUrl + ".tidy.json", CONTENT_TYPE_JSON), '\n');
+ int delta = tidyCount - noTidyCount;
+
+ // Output contains two properties so at least two EOL chars
+ int min = 2;
+
+ assertTrue("The .tidy selector should add at least 2 EOL chars to json output (delta=" + delta + ")", delta > min);
}
public void testTidyRecursive() throws IOException {
@@ -200,26 +203,13 @@
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));
- }
-
+ int noTidyCount = countOccurences(getContent(url + ".infinity.json", CONTENT_TYPE_JSON), '\n');
+ int tidyCount = countOccurences(getContent(url + ".tidy.infinity.json", CONTENT_TYPE_JSON), '\n');
+ int delta = tidyCount - noTidyCount;
+
+ // Output contains 3 properties and a subnode with one, so at least 5 EOL chars
+ int min = 5;
+
+ assertTrue("The .tidy selector should add at least 2 EOL chars to json output (delta=" + delta + ")", delta > min);
}
}
\ No newline at end of file