Return-Path: Delivered-To: apmail-incubator-sling-commits-archive@locus.apache.org Received: (qmail 39066 invoked from network); 23 Dec 2008 13:37:13 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 23 Dec 2008 13:37:13 -0000 Received: (qmail 62313 invoked by uid 500); 23 Dec 2008 13:37:13 -0000 Delivered-To: apmail-incubator-sling-commits-archive@incubator.apache.org Received: (qmail 62284 invoked by uid 500); 23 Dec 2008 13:37:12 -0000 Mailing-List: contact sling-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: sling-dev@incubator.apache.org Delivered-To: mailing list sling-commits@incubator.apache.org Received: (qmail 62275 invoked by uid 99); 23 Dec 2008 13:37:12 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 23 Dec 2008 05:37:12 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 23 Dec 2008 13:37:11 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id C99412388892; Tue, 23 Dec 2008 05:36:51 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r728952 - /incubator/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/JsonRenderingTest.java Date: Tue, 23 Dec 2008 13:36:51 -0000 To: sling-commits@incubator.apache.org From: bdelacretaz@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20081223133651.C99412388892@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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