incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r918519 - in /sling/trunk/launchpad: builder/ test-services/src/main/java/org/apache/sling/launchpad/testservices/scripting/ testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/scripting/ testing/src/test/resources/integ...
Date Wed, 03 Mar 2010 15:36:56 GMT
Author: bdelacretaz
Date: Wed Mar  3 15:36:56 2010
New Revision: 918519

URL: http://svn.apache.org/viewvc?rev=918519&view=rev
Log:
SLING-1423 - integration tests for standalone script execution

Added:
    sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/scripting/StandaloneScriptExecutionServlet.java
  (with props)
    sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/scripting/
    sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/scripting/StandaloneScriptExecutionTest.java
  (with props)
    sling/trunk/launchpad/testing/src/test/resources/integration-test/standalone-test.js 
 (with props)
Modified:
    sling/trunk/launchpad/builder/   (props changed)

Propchange: sling/trunk/launchpad/builder/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Wed Mar  3 15:36:56 2010
@@ -3,3 +3,4 @@
 target
 sling
 .settings
+derby.log

Added: sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/scripting/StandaloneScriptExecutionServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/scripting/StandaloneScriptExecutionServlet.java?rev=918519&view=auto
==============================================================================
--- sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/scripting/StandaloneScriptExecutionServlet.java
(added)
+++ sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/scripting/StandaloneScriptExecutionServlet.java
Wed Mar  3 15:36:56 2010
@@ -0,0 +1,72 @@
+/*
+ * 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.launchpad.testservices.scripting;
+
+import java.io.IOException;
+import java.io.StringWriter;
+
+import javax.servlet.ServletException;
+
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.api.scripting.SlingBindings;
+import org.apache.sling.api.scripting.SlingScript;
+import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
+
+/**
+ * Test Servlet that executes a named script in standalone mode, i.e.
+ * without a request or response. 
+ *
+ * @scr.component immediate="true" metatype="no"
+ * @scr.service interface="javax.servlet.Servlet"
+ *
+ * @scr.property name="service.description"
+ *               value="StandaloneScriptExecutionServlet Test Servlet"
+ * @scr.property name="service.vendor" value="The Apache Software Foundation"
+ *
+ * @scr.property name="sling.servlet.resourceTypes"
+ *               value="sling/servlet/default"
+ *               
+ * @scr.property name="sling.servlet.selectors"
+ *               value = "StandaloneScriptExecutionServlet"
+ *                
+ * @scr.property name="sling.servlet.extensions"
+ *               value = "txt"
+ *
+ */
+@SuppressWarnings("serial")
+
+public class StandaloneScriptExecutionServlet extends SlingSafeMethodsServlet {
+
+	@Override
+	protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)

+	throws ServletException, IOException {
+		final SlingScript script = request.getResource().adaptTo(SlingScript.class);
+		if(script == null) {
+			throw new ServletException("Resource does not adapt to a SlingScript:" + request.getResource().getPath());
+		}
+		
+		// Execute the script without providing a request or response, in the simplest possible
way
+		final SlingBindings bindings = new SlingBindings();
+		final StringWriter sw = new StringWriter();
+		bindings.put("StandaloneScriptExecutionServletOutput", sw);
+		script.eval(bindings);
+		
+		response.setContentType("text/plain");
+		response.getWriter().write(sw.toString());
+	}
+}

Propchange: sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/scripting/StandaloneScriptExecutionServlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/scripting/StandaloneScriptExecutionServlet.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/scripting/StandaloneScriptExecutionTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/scripting/StandaloneScriptExecutionTest.java?rev=918519&view=auto
==============================================================================
--- sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/scripting/StandaloneScriptExecutionTest.java
(added)
+++ sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/scripting/StandaloneScriptExecutionTest.java
Wed Mar  3 15:36:56 2010
@@ -0,0 +1,47 @@
+/*
+ * 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.launchpad.webapp.integrationtest.scripting;
+
+import org.apache.sling.commons.testing.integration.HttpTestBase;
+
+public class StandaloneScriptExecutionTest extends HttpTestBase {
+	/** Use the StandaloneScriptExecutionServlet to verify that scripts
+	 * 	can be executed in the simplest way from java code (SLING-1423)
+	 */
+	public void testScriptExecution() throws Exception {
+		final String scriptPath = TEST_PATH + "/" + getClass().getSimpleName();
+		final String script = "standalone-test.js";
+		testClient.mkdirs(WEBDAV_BASE_URL, scriptPath);
+		final String scriptUrl = uploadTestScript(scriptPath, script, script);
+		
+		{
+			final String content = getContent(scriptUrl, "application/javascript");
+			assertTrue("Expecting script URL to return raw script contents (" + content + ")", 
+					content.contains("TEST_SCRIPT"));
+		}
+		
+		{
+			final String execSuffix = ".StandaloneScriptExecutionServlet.txt";
+			final String expect = "2+2=4";
+			final String content = getContent(scriptUrl + execSuffix, CONTENT_TYPE_PLAIN);
+			assertTrue("Expecting execution URL to return " + expect + " (returns '" + content + "')",

+					content.contains(expect));
+		}
+		
+		testClient.delete(scriptUrl);
+	}
+}

Propchange: sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/scripting/StandaloneScriptExecutionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/scripting/StandaloneScriptExecutionTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: sling/trunk/launchpad/testing/src/test/resources/integration-test/standalone-test.js
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/testing/src/test/resources/integration-test/standalone-test.js?rev=918519&view=auto
==============================================================================
--- sling/trunk/launchpad/testing/src/test/resources/integration-test/standalone-test.js (added)
+++ sling/trunk/launchpad/testing/src/test/resources/integration-test/standalone-test.js Wed
Mar  3 15:36:56 2010
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+ 
+// TEST_SCRIPT for standalone script execution test
+StandaloneScriptExecutionServletOutput.write("2+2=" + (2 + 2));
\ No newline at end of file

Propchange: sling/trunk/launchpad/testing/src/test/resources/integration-test/standalone-test.js
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message