Return-Path: Delivered-To: apmail-incubator-sling-commits-archive@locus.apache.org Received: (qmail 70433 invoked from network); 17 Jan 2008 14:43:39 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 17 Jan 2008 14:43:39 -0000 Received: (qmail 77110 invoked by uid 500); 17 Jan 2008 14:43:25 -0000 Delivered-To: apmail-incubator-sling-commits-archive@incubator.apache.org Received: (qmail 77078 invoked by uid 500); 17 Jan 2008 14:43:25 -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 77056 invoked by uid 99); 17 Jan 2008 14:43:25 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 Jan 2008 06:43:25 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 Jan 2008 14:43:07 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 493741A9832; Thu, 17 Jan 2008 06:43:12 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r612830 [2/2] - in /incubator/sling/trunk/usling/usling-webapp: ./ src/test/java/org/apache/sling/usling/webapp/integrationtest/ src/test/java/org/apache/sling/usling/webapp/integrationtest/ujax/ src/test/resources/integration-test/ Date: Thu, 17 Jan 2008 14:42:32 -0000 To: sling-commits@incubator.apache.org From: bdelacretaz@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080117144313.493741A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ValueFromTest.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ValueFromTest.java?rev=612830&view=auto ============================================================================== --- incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ValueFromTest.java (added) +++ incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ValueFromTest.java Thu Jan 17 06:41:57 2008 @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.sling.usling.webapp.integrationtest; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +/** Test the @ValueFrom field name suffix, SLING-130 */ +public class ValueFromTest extends UslingHttpTestBase { + + private String postUrl; + private String testText; + + @Override + protected void setUp() throws Exception { + super.setUp(); + + // set test values + testText = "This is a test " + System.currentTimeMillis(); + + // create the test node, under a path that's specific to this class to allow collisions + postUrl = HTTP_BASE_URL + "/" + getClass().getSimpleName() + "/" + System.currentTimeMillis() + "/UJAX_create"; + final Map props = new HashMap(); + props.put("text", testText); + } + + public void testWithoutValueFrom() throws IOException { + final Map props = new HashMap(); + props.put("./text", testText); + final String jsonUrl = testClient.createNode(postUrl, props) + ".json"; + final String json = getContent(jsonUrl, CONTENT_TYPE_JSON); + assertJavascript(testText, json, "out.println(data.text)"); + + } + + public void testWithValueFrom() throws IOException { + final Map props = new HashMap(); + props.put("./text@ValueFrom", "fulltext"); + props.put("fulltext", testText); + final String jsonUrl = testClient.createNode(postUrl, props) + ".json"; + final String json = getContent(jsonUrl, CONTENT_TYPE_JSON); + assertJavascript("string", json, "out.println(typeof data.text)"); + assertJavascript(testText, json, "out.println(data.text)"); + assertJavascript("undefined", json, "out.println(typeof data.fulltext)"); + } + + public void testWithValueFromAndMissingField() throws IOException { + final Map props = new HashMap(); + props.put("./text@ValueFrom", "fulltext"); + // no fulltext field on purpose, field must be ignored + + final String jsonUrl = testClient.createNode(postUrl, props) + ".json"; + final String json = getContent(jsonUrl, CONTENT_TYPE_JSON); + assertJavascript("undefined", json, "out.println(typeof data.text)"); + assertJavascript("undefined", json, "out.println(typeof data['text@ValueFrom'])"); + } + + + + } \ No newline at end of file Propchange: incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ValueFromTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ValueFromTest.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Rev URL Added: incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/package.html URL: http://svn.apache.org/viewvc/incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/package.html?rev=612830&view=auto ============================================================================== --- incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/package.html (added) +++ incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/package.html Thu Jan 17 06:41:57 2008 @@ -0,0 +1,20 @@ + + +

+ The tests found in and under this package are used in the + "integration-test" build phase (SLING-82), they are not run + as part of the normal "test" build phase. +

+

+ To debug the integration tests, however, it is useful to run + them as part of the normal test phase, after starting a separate + Sling instance that they can talk to. +

+

+ This is implemented using Maven profiles: to run the integration + tests during the normal test phase, disable the "disableIntegrationTestsInTestPhase" + Maven profile, for example using mvn -P nullUslingProfile test. + See pom.xml for more details. +

+ + \ No newline at end of file Propchange: incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/package.html ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ujax/PostServletCreateTest.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ujax/PostServletCreateTest.java?rev=612830&view=auto ============================================================================== --- incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ujax/PostServletCreateTest.java (added) +++ incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ujax/PostServletCreateTest.java Thu Jan 17 06:41:57 2008 @@ -0,0 +1,110 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.sling.usling.webapp.integrationtest.ujax; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.http.HttpServletResponse; + +import org.apache.sling.usling.webapp.integrationtest.UslingHttpTestBase; + +/** Test node creation via the MicrojaxPostServlet */ +public class PostServletCreateTest extends UslingHttpTestBase { + public static final String TEST_BASE_PATH = "/ujax-tests"; + private String postUrl; + + @Override + protected void setUp() throws Exception { + super.setUp(); + postUrl = HTTP_BASE_URL + TEST_BASE_PATH + "/" + System.currentTimeMillis(); + } + + public void TODO_FAILS_testPostPathIsUnique() throws IOException { + assertHttpStatus(postUrl, HttpServletResponse.SC_NOT_FOUND, + "Path must not exist before test: " + postUrl); + } + + public void testCreateNode() throws IOException { + final String location = testClient.createNode(postUrl + "/UJAX_create", null); + assertHttpStatus(location, HttpServletResponse.SC_OK, + "POST must redirect to created resource (" + location + ")"); + assertTrue("Node (" + location + ") must have generated name", + !location.endsWith("/*")); + assertTrue("Node (" + location + ") must created be under POST URL (" + postUrl + ")", + location.contains(postUrl + "/")); + } + + public void testCreateNodeAtSpecificUrl() throws IOException { + final String specifiedLocation = postUrl + "/specified-location"; + final String location = testClient.createNode(specifiedLocation, null); + assertHttpStatus(location, HttpServletResponse.SC_OK, + "POST must redirect to created resource (" + location + ")"); + assertTrue("Node (" + location + ") must be created at given URL (" + specifiedLocation + ")", + location.equals(specifiedLocation)); + } + + public void testCreateNodeAtDeepUrl() throws IOException { + final long id = System.currentTimeMillis(); + final String specifiedLocation = postUrl + "/specified-location" + id + "/deepA/deepB/" + id; + final String location = testClient.createNode(specifiedLocation, null); + assertHttpStatus(location, HttpServletResponse.SC_OK, + "POST must redirect to created resource (" + location + ")"); + assertTrue("Node (" + location + ") must be created (deep) at given URL (" + specifiedLocation + ")", + location.equals(specifiedLocation)); + } + + /** Create a node with some data, and check that data */ + public void testCreateWithData() throws IOException { + final Map props = new HashMap (); + props.put("a","123"); + props.put("b","456"); + final String createdNodeUrl = testClient.createNode(postUrl + "/UJAX_create", props); + final String content = getContent(createdNodeUrl + ".json", CONTENT_TYPE_JSON); + assertJavascript("123456", content, "out.println(data.a + data.b)"); + } + + /** Use the default "save prefix" on some parameters, and check that only those + * who have the prefix are saved. + */ + public void testDefaultSavePrefix() throws IOException { + final Map props = new HashMap (); + props.put("./a","123"); + props.put("./b","456"); + props.put("c","not saved"); + final String createdNodeUrl = testClient.createNode(postUrl + "/UJAX_create", props); + final String content = getContent(createdNodeUrl + ".json", CONTENT_TYPE_JSON); + assertJavascript("123456", content, "out.println(data.a + data.b)"); + assertJavascript("undefined", content, "out.println(typeof data.c)"); + } + + /** Use a custom "save prefix" on some parameters, and check that only those + * who have the prefix are saved. + */ + public void TODO_FAILS_testCustomSavePrefix() throws IOException { + final Map props = new HashMap (); + props.put("++a","123"); + props.put("++b","456"); + props.put("c","not saved"); + props.put("ujax:saveParamPrefix","++"); + final String createdNodeUrl = testClient.createNode(postUrl + "/UJAX_create", props); + final String content = getContent(createdNodeUrl + ".json", CONTENT_TYPE_JSON); + assertJavascript("123456", content, "out.println(data.a + data.b)"); + assertJavascript("undefined", content, "out.println(typeof data.c)"); + } + } \ No newline at end of file Propchange: incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ujax/PostServletCreateTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ujax/PostServletCreateTest.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Rev URL Added: incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ujax/PostServletDeleteTest.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ujax/PostServletDeleteTest.java?rev=612830&view=auto ============================================================================== --- incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ujax/PostServletDeleteTest.java (added) +++ incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ujax/PostServletDeleteTest.java Thu Jan 17 06:41:57 2008 @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.sling.usling.webapp.integrationtest.ujax; + +import java.io.IOException; +import java.util.LinkedList; +import java.util.List; + +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.httpclient.NameValuePair; +import org.apache.sling.usling.webapp.integrationtest.UslingHttpTestBase; + +/** Test node deletion via the MicrojaxPostServlet */ +public class PostServletDeleteTest extends UslingHttpTestBase { + public static final String TEST_BASE_PATH = "/ujax-tests"; + private String postUrl; + + @Override + protected void setUp() throws Exception { + super.setUp(); + postUrl = HTTP_BASE_URL + TEST_BASE_PATH + "/" + getClass().getSimpleName() + "/" + System.currentTimeMillis(); + + // TODO_FAILS: the Sling resource renderer currently goes up the path for GETs + //assertHttpStatus(postUrl, HttpServletResponse.SC_NOT_FOUND, + // "Path must not exist before test: " + postUrl); + } + + public void testNothing() { + // TODO remove this all TODO_FAILS_ are gone + } + + public void TODO_FAILS_testDelete() throws IOException { + final String urlA = testClient.createNode(postUrl + "/UJAX_create", null); + final String urlB = testClient.createNode(postUrl + "/UJAX_create", null); + final String urlC = testClient.createNode(postUrl + "/UJAX_create", null); + final String urlD = testClient.createNode(postUrl + "/specific-location/for-delete", null); + + // initially all nodes must be found + assertHttpStatus(urlA, HttpServletResponse.SC_OK, "A must initially exist"); + assertHttpStatus(urlB, HttpServletResponse.SC_OK, "B must initially exist"); + assertHttpStatus(urlC, HttpServletResponse.SC_OK, "C must initially exist"); + assertHttpStatus(urlD, HttpServletResponse.SC_OK, "D must initially exist"); + + // delete one and check + final List params = new LinkedList (); + final String deleteCmd = "ujax:delete"; + params.add(new NameValuePair(deleteCmd,urlToNodePath(urlA))); + assertPostStatus(postUrl,HttpServletResponse.SC_OK,params,"Delete must return status OK (1)"); + assertHttpStatus(urlA, HttpServletResponse.SC_NOT_FOUND, "A must be deleted (1)"); + assertHttpStatus(urlB, HttpServletResponse.SC_OK, "B must still exist"); + assertHttpStatus(urlC, HttpServletResponse.SC_OK, "C must still exist"); + assertHttpStatus(urlD, HttpServletResponse.SC_OK, "D must still exist"); + + // delete the others with one request and check + params.clear(); + params.add(new NameValuePair(deleteCmd,urlToNodePath(urlB))); + params.add(new NameValuePair(deleteCmd,urlToNodePath(urlC))); + params.add(new NameValuePair(deleteCmd,urlToNodePath(urlD))); + assertPostStatus(postUrl,HttpServletResponse.SC_OK,params,"Delete must return status OK (2)"); + assertHttpStatus(urlA, HttpServletResponse.SC_NOT_FOUND, "A must be deleted (2)"); + assertHttpStatus(urlB, HttpServletResponse.SC_NOT_FOUND, "B must be deleted (2)"); + assertHttpStatus(urlC, HttpServletResponse.SC_NOT_FOUND, "C must be deleted (2)"); + assertHttpStatus(urlD, HttpServletResponse.SC_NOT_FOUND, "D must be deleted (2)"); + + // attempting to delete non-existing nodes is ok + assertPostStatus(postUrl,HttpServletResponse.SC_OK,params,"Repeated delete must return status OK (3)"); + } + + private String urlToNodePath(String url) { + return url.substring(HTTP_BASE_URL.length()); + } +} \ No newline at end of file Propchange: incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ujax/PostServletDeleteTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ujax/PostServletDeleteTest.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Rev URL Added: incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ujax/PostServletOrderTest.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ujax/PostServletOrderTest.java?rev=612830&view=auto ============================================================================== --- incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ujax/PostServletOrderTest.java (added) +++ incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ujax/PostServletOrderTest.java Thu Jan 17 06:41:57 2008 @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.sling.usling.webapp.integrationtest.ujax; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.http.HttpServletResponse; + +import org.apache.sling.usling.webapp.integrationtest.UslingHttpTestBase; + +/** Test the order option for node creation via the MicrojaxPostServlet */ +public class PostServletOrderTest extends UslingHttpTestBase { + public static final String TEST_BASE_PATH = "/ujax-tests"; + private String postUrl; + + @Override + protected void setUp() throws Exception { + super.setUp(); + postUrl = HTTP_BASE_URL + TEST_BASE_PATH + "/" + System.currentTimeMillis(); + } + + public void TODO_FAILS_testPostPathIsUnique() throws IOException { + assertHttpStatus(postUrl, HttpServletResponse.SC_NOT_FOUND, + "Path must not exist before test: " + postUrl); + } + + /** Create several nodes without the order option, and check ordering */ + public void testStandardOrder() throws IOException { + final String [] nodeUrl = new String[4]; + nodeUrl[0] = testClient.createNode(postUrl + "/UJAX_create", null); + nodeUrl[1] = testClient.createNode(postUrl + "/UJAX_create", null); + nodeUrl[2] = testClient.createNode(postUrl + "/UJAX_create", null); + nodeUrl[3] = testClient.createNode(postUrl + "/UJAX_create", null); + + final String [] nodeName = new String[nodeUrl.length]; + for(int i = 0; i < nodeUrl.length; i++) { + nodeName[i] = nodeUrl[i].substring(nodeUrl[i].lastIndexOf('/') + 1); + } + + // check that nodes appear in creation order in their parent's list of children + final String json = getContent(postUrl + ".json?maxlevels=1", CONTENT_TYPE_JSON); + for(int i = 0; i < nodeUrl.length - 1; i++) { + final int posA = json.indexOf(nodeName[i]); + final int posB = json.indexOf(nodeName[i + 1]); + if(posB <= posA) { + fail("Expected '" + nodeName[i] + " to come before " + nodeName[i + 1] + " in JSON data '" + json + "'"); + } + } + } + + /** Create several nodes with the order option, and check ordering */ + public void testZeroOrder() throws IOException { + final Map props = new HashMap (); + props.put("ujax:order","0"); + + final String [] nodeUrl = new String[4]; + nodeUrl[0] = testClient.createNode(postUrl + "/UJAX_create", props); + nodeUrl[1] = testClient.createNode(postUrl + "/UJAX_create", props); + nodeUrl[2] = testClient.createNode(postUrl + "/UJAX_create", props); + nodeUrl[3] = testClient.createNode(postUrl + "/UJAX_create", props); + + final String [] nodeName = new String[nodeUrl.length]; + for(int i = 0; i < nodeUrl.length; i++) { + nodeName[i] = nodeUrl[i].substring(nodeUrl[i].lastIndexOf('/') + 1); + } + + // check that nodes appear in reverse creation order in their parent's list of children + final String json = getContent(postUrl + ".json?maxlevels=1", CONTENT_TYPE_JSON); + for(int i = 0; i < nodeUrl.length - 1; i++) { + final int posA = json.indexOf(nodeName[i]); + final int posB = json.indexOf(nodeName[i + 1]); + if(posA <= posB) { + fail("Expected '" + nodeName[i] + " to come after " + nodeName[i + 1] + " in JSON data '" + json + "'"); + } + } + } + } \ No newline at end of file Propchange: incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ujax/PostServletOrderTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ujax/PostServletOrderTest.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Rev URL Added: incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ujax/PostServletUpdateTest.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ujax/PostServletUpdateTest.java?rev=612830&view=auto ============================================================================== --- incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ujax/PostServletUpdateTest.java (added) +++ incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ujax/PostServletUpdateTest.java Thu Jan 17 06:41:57 2008 @@ -0,0 +1,101 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.sling.usling.webapp.integrationtest.ujax; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.http.HttpServletResponse; + +import org.apache.sling.usling.webapp.integrationtest.UslingHttpTestBase; + +/** Test node updates via the MicrojaxPostServlet */ +public class PostServletUpdateTest extends UslingHttpTestBase { + public static final String TEST_BASE_PATH = "/ujax-tests"; + private String postUrl; + + @Override + protected void setUp() throws Exception { + super.setUp(); + postUrl = HTTP_BASE_URL + TEST_BASE_PATH + "/" + System.currentTimeMillis(); + } + + public void TODO_FAILS_testPostPathIsUnique() throws IOException { + assertHttpStatus(postUrl, HttpServletResponse.SC_NOT_FOUND, + "Path must not exist before test: " + postUrl); + } + + public void testUpdateWithChanges() throws IOException { + final Map props = new HashMap (); + props.put("./a","123"); + props.put("./b","456"); + + final String location = testClient.createNode(postUrl + "/UJAX_create", props); + String content = getContent(location + ".json", CONTENT_TYPE_JSON); + assertJavascript("123456", content, "out.println(data.a + data.b)"); + + props.put("./a","789"); + // the testClient method is called createNode but all it does is a POST, + // so it can be used for updates as well + final String newLocation = testClient.createNode(location, props); + assertEquals("Location must not changed after POST to existing node",location,newLocation); + content = getContent(location + ".json", CONTENT_TYPE_JSON); + assertJavascript("789456", content, "out.println(data.a + data.b)"); + } + + public void testUpdateNoChanges() throws IOException { + final Map props = new HashMap (); + props.put("./a","123"); + props.put("./b","456"); + + final String location = testClient.createNode(postUrl + "/UJAX_create", props); + String content = getContent(location + ".json", CONTENT_TYPE_JSON); + assertJavascript("123456", content, "out.println(data.a + data.b)"); + + props.clear(); + // the testClient method is called createNode but all it does is a POST, + // so it can be used for updates as well + final String newLocation = testClient.createNode(location, props); + assertEquals("Location must not changed after POST to existing node",location,newLocation); + content = getContent(location + ".json", CONTENT_TYPE_JSON); + assertJavascript("123456", content, "out.println(data.a + data.b)"); + } + + public void testUpdateSomeChanges() throws IOException { + final Map props = new HashMap (); + props.put("./a","123"); + props.put("./b","456"); + props.put("C","not stored"); + + final String location = testClient.createNode(postUrl + "/UJAX_create", props); + String content = getContent(location + ".json", CONTENT_TYPE_JSON); + assertJavascript("123456", content, "out.println(data.a + data.b)"); + + props.clear(); + props.put("./b","457"); + props.put("C","still not stored"); + + // the testClient method is called createNode but all it does is a POST, + // so it can be used for updates as well + final String newLocation = testClient.createNode(location, props); + assertEquals("Location must not changed after POST to existing node",location,newLocation); + content = getContent(location + ".json", CONTENT_TYPE_JSON); + assertJavascript("123457", content, "out.println(data.a + data.b)"); + } + + } \ No newline at end of file Propchange: incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ujax/PostServletUpdateTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ujax/PostServletUpdateTest.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Rev URL Added: incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ujax/UjaxAutoPropertiesTest.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ujax/UjaxAutoPropertiesTest.java?rev=612830&view=auto ============================================================================== --- incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ujax/UjaxAutoPropertiesTest.java (added) +++ incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ujax/UjaxAutoPropertiesTest.java Thu Jan 17 06:41:57 2008 @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.sling.usling.webapp.integrationtest.ujax; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.http.HttpServletResponse; + +import org.apache.sling.usling.webapp.integrationtest.UslingHttpTestBase; + +/** {#link MicrojaxPropertyValueSetter} sets the value of some properties + * automatically if they are empty. This is tested here with various cases. + */ + +public class UjaxAutoPropertiesTest extends UslingHttpTestBase { + + public static final String TEST_BASE_PATH = "/ujax-tests"; + private String postUrl; + + @Override + protected void setUp() throws Exception { + super.setUp(); + postUrl = HTTP_BASE_URL + TEST_BASE_PATH + "/" + System.currentTimeMillis(); + } + + public void TODO_FAILS_testPostPathIsUnique() throws IOException { + assertHttpStatus(postUrl, HttpServletResponse.SC_NOT_FOUND, + "Path must not exist before test: " + postUrl); + } + + public void testCreatedAndModified() throws IOException { + final Map props = new HashMap (); + props.put("a","123"); + + props.put("created",""); + props.put("createdBy",""); + props.put("lastModified",""); + props.put("lastModifiedBy",""); + + final String createdNodeUrl = testClient.createNode(postUrl + "/UJAX_create", props); + String content = getContent(createdNodeUrl + ".json", CONTENT_TYPE_JSON); + + assertJavascript("123", content, "out.println(data.a)"); + assertJavascript("admin", content, "out.println(data.createdBy)"); + assertJavascript("admin", content, "out.println(data.lastModifiedBy)"); + assertJavascript("true", content, "out.println(data.created.length > 0)"); + assertJavascript("true", content, "out.println(data.lastModified.length > 0)"); + assertJavascript("true", content, "out.println(data.lastModified == data.created)"); + + // update node and check that "last modified" has changed + try { + Thread.sleep(1000L); + } catch(InterruptedException ignored) { + // ignore + } + + testClient.createNode(createdNodeUrl, props); + content = getContent(createdNodeUrl + ".json", CONTENT_TYPE_JSON); + + assertJavascript("123", content, "out.println(data.a)"); + assertJavascript("admin", content, "out.println(data.createdBy)"); + assertJavascript("admin", content, "out.println(data.lastModifiedBy)"); + assertJavascript("true", content, "out.println(data.created.length > 0)"); + assertJavascript("true", content, "out.println(data.lastModified.length > 0)"); + assertJavascript("true", content, "out.println(data.lastModified > data.created)"); + } + + public void testWithSpecificValues() throws IOException { + final Map props = new HashMap (); + props.put("a","123"); + + props.put("created","a"); + props.put("createdBy","b"); + props.put("lastModified","c"); + props.put("lastModifiedBy","d"); + + final String createdNodeUrl = testClient.createNode(postUrl + "/UJAX_create", props); + final String content = getContent(createdNodeUrl + ".json", CONTENT_TYPE_JSON); + + assertJavascript("123", content, "out.println(data.a)"); + assertJavascript("a", content, "out.println(data.created)"); + assertJavascript("b", content, "out.println(data.createdBy)"); + assertJavascript("c", content, "out.println(data.lastModified)"); + assertJavascript("d", content, "out.println(data.lastModifiedBy)"); + } +} Propchange: incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ujax/UjaxAutoPropertiesTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ujax/UjaxAutoPropertiesTest.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Rev URL Added: incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ujax/UjaxSessionInfoTest.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ujax/UjaxSessionInfoTest.java?rev=612830&view=auto ============================================================================== --- incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ujax/UjaxSessionInfoTest.java (added) +++ incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ujax/UjaxSessionInfoTest.java Thu Jan 17 06:41:57 2008 @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.sling.usling.webapp.integrationtest.ujax; + +import java.io.IOException; + +import javax.servlet.http.HttpServletResponse; + +import org.apache.sling.usling.webapp.integrationtest.UslingHttpTestBase; + +/** Test the ujax:sessionInfo resource */ + +public class UjaxSessionInfoTest extends UslingHttpTestBase { + + public void testNothing() { + // TODO remove this all TODO_FAILS_ are gone + } + + public void TODO_FAILS_testSessionInfo() throws IOException { + final String content = getContent(HTTP_BASE_URL + "/ujax:sessionInfo.json", CONTENT_TYPE_JSON); + assertJavascript("admin.default", content, "out.println(data.userID + '.' + data.workspace)"); + } + + public void TODO_FAILS_testNonexistentUjaxUrl() throws IOException { + assertHttpStatus(HTTP_BASE_URL + "/ujax:nothing", HttpServletResponse.SC_NOT_FOUND); + } +} Propchange: incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ujax/UjaxSessionInfoTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/ujax/UjaxSessionInfoTest.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Rev URL Added: incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/builtin-objects.esp URL: http://svn.apache.org/viewvc/incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/builtin-objects.esp?rev=612830&view=auto ============================================================================== --- incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/builtin-objects.esp (added) +++ incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/builtin-objects.esp Thu Jan 17 06:41:57 2008 @@ -0,0 +1,20 @@ +<%-- used by ScriptBuiltinObjectsTest --%> + + + ESP template +

<%= resource.node.text %>

+ + + + <% + var scClass = Packages.javax.servlet.ServletContext; + var sc = request.getServiceLocator().getService(scClass); + %> +

ServletContext:<%= sc.getMimeType('foo.txt') %>

+ + +

SlingHttpServletResponse:<%= response.containsHeader('NOT_A_HEADER') %>

+ + + + Added: incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/include-test.esp URL: http://svn.apache.org/viewvc/incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/include-test.esp?rev=612830&view=auto ============================================================================== --- incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/include-test.esp (added) +++ incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/include-test.esp Thu Jan 17 06:41:57 2008 @@ -0,0 +1,27 @@ +<%-- used by IncludeTest --%> + + +

ESP template

+

<%= resource.node.text %>

+ + <% + if(resource.node.pathToInclude) { + %> +

pathToInclude = <%= resource.node.pathToInclude %>

+

Including <%= resource.node.pathToInclude %>

+ <% + sling.include(resource.node.pathToInclude + ".html"); + } + %> + + <% + if(resource.node.testInfiniteLoop) { + %> +

testInfiniteLoop = <%= resource.node.testInfiniteLoop %>

+ <% + // try to include the item itself, to cause an infinite loop + sling.include(resource.getPath() + ".html"); + } + %> + + Added: incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/post-test.esp URL: http://svn.apache.org/viewvc/incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/post-test.esp?rev=612830&view=auto ============================================================================== --- incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/post-test.esp (added) +++ incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/post-test.esp Thu Jan 17 06:41:57 2008 @@ -0,0 +1,19 @@ +<% +var length = 0; +if (request.getRequestParameter("file") != null) { + var file = null; + // store file + var reqPara = request.getRequestParameter("file"); + var is = reqPara.getInputStream(); + file = Packages.java.io.File.createTempFile("posttest", ".txt"); + var fout = new Packages.java.io.FileOutputStream(file); + var c; + while ((c = is.read()) != -1) { + fout.write(c); + } + fout.close(); + + // read length + length = file.length(); +} +%><%= Packages.java.lang.String.valueOf(length) %> \ No newline at end of file Added: incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/rendering-test-2.esp URL: http://svn.apache.org/viewvc/incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/rendering-test-2.esp?rev=612830&view=auto ============================================================================== --- incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/rendering-test-2.esp (added) +++ incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/rendering-test-2.esp Thu Jan 17 06:41:57 2008 @@ -0,0 +1,7 @@ +<%-- used by ScriptedRenderingTest --%> + + + Template #2 for ESP tests +

<%= resource.node.text %>

+ + Added: incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/rendering-test-3.esp URL: http://svn.apache.org/viewvc/incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/rendering-test-3.esp?rev=612830&view=auto ============================================================================== --- incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/rendering-test-3.esp (added) +++ incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/rendering-test-3.esp Thu Jan 17 06:41:57 2008 @@ -0,0 +1,7 @@ +<%-- used by ScriptedRenderingTest --%> + + + Template #3 for ESP tests +

<%= resource.node.text %>

+ + Added: incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/rendering-test.erb URL: http://svn.apache.org/viewvc/incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/rendering-test.erb?rev=612830&view=auto ============================================================================== --- incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/rendering-test.erb (added) +++ incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/rendering-test.erb Thu Jan 17 06:41:57 2008 @@ -0,0 +1,15 @@ +!-- used by ScriptedRenderingTest --> + + +

Ruby template <%= Time.now %>

+

<%= resource.getNode().getProperty("text").getString() %>

+ <% unless props.nil? or props.empty? %> + + <% for prop, val in props %> + + <% end %> +
<%= prop %>:<%= val %>
+ <% end %> + + + Added: incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/rendering-test.esp URL: http://svn.apache.org/viewvc/incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/rendering-test.esp?rev=612830&view=auto ============================================================================== --- incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/rendering-test.esp (added) +++ incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/rendering-test.esp Thu Jan 17 06:41:57 2008 @@ -0,0 +1,18 @@ +<%-- used by ScriptedRenderingTest --%> + + + ESP template +

<%= resource.node.text %>

+ + +
+ + + <% + var list = new Packages.java.util.LinkedList(); + list.add("LinkedListTest"); + %> +

Test<%= list.get(0) %>

+ + + Added: incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/rendering-test.ftl URL: http://svn.apache.org/viewvc/incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/rendering-test.ftl?rev=612830&view=auto ============================================================================== --- incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/rendering-test.ftl (added) +++ incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/rendering-test.ftl Thu Jan 17 06:41:57 2008 @@ -0,0 +1,7 @@ +<%-- used by ScriptedRenderingTest --%> + + + FreeMarker template +

${resource.getNode().getProperty("text").getString()}

+ + Added: incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/rendering-test.js URL: http://svn.apache.org/viewvc/incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/rendering-test.js?rev=612830&view=auto ============================================================================== --- incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/rendering-test.js (added) +++ incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/rendering-test.js Thu Jan 17 06:41:57 2008 @@ -0,0 +1,5 @@ +// Used by ScriptedRenderingTest +out.println(""); +out.println("Raw javascript template"); +out.println("

" + resource.node.text + "

"); +out.print(""); Propchange: incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/rendering-test.js ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/rendering-test.jst URL: http://svn.apache.org/viewvc/incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/rendering-test.jst?rev=612830&view=auto ============================================================================== --- incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/rendering-test.jst (added) +++ incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/rendering-test.jst Thu Jan 17 06:41:57 2008 @@ -0,0 +1,21 @@ +<%-- used by ScriptedRenderingTest --%> +

+ JST template. +

+ +

+ <%= currentNode.title %> +

+ +

+ <%= currentNode.text %> +

+ + + + + + +<% for(i=0; i< 10; i++) { +} %><% for(i=0; i< 10; i++) { +} %> \ No newline at end of file Added: incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/rendering-test.vlt URL: http://svn.apache.org/viewvc/incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/rendering-test.vlt?rev=612830&view=auto ============================================================================== --- incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/rendering-test.vlt (added) +++ incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/rendering-test.vlt Thu Jan 17 06:41:57 2008 @@ -0,0 +1,7 @@ + + + + Velocity template +

$resource.getNode().getProperty("text").getString()

+ + Added: incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/testfile.html URL: http://svn.apache.org/viewvc/incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/testfile.html?rev=612830&view=auto ============================================================================== --- incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/testfile.html (added) +++ incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/testfile.html Thu Jan 17 06:41:57 2008 @@ -0,0 +1,5 @@ + + +This is testfile.html. + + \ No newline at end of file Propchange: incubator/sling/trunk/usling/usling-webapp/src/test/resources/integration-test/testfile.html ------------------------------------------------------------------------------ svn:eol-style = native