incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r603622 - in /incubator/sling/trunk/microsling/microsling-core/src: main/java/org/apache/sling/microsling/servlet/ test/java/org/apache/sling/microsling/integration/ test/resources/integration-test/
Date Wed, 12 Dec 2007 14:16:32 GMT
Author: bdelacretaz
Date: Wed Dec 12 06:16:31 2007
New Revision: 603622

URL: http://svn.apache.org/viewvc?rev=603622&view=rev
Log:
SLING-136 - make the ServletContext available to scripts

Added:
    incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/ScriptBuiltinObjectsTest.java
  (with props)
    incubator/sling/trunk/microsling/microsling-core/src/test/resources/integration-test/builtin-objects.esp
Modified:
    incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/servlet/MicroslingMainServlet.java

Modified: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/servlet/MicroslingMainServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/servlet/MicroslingMainServlet.java?rev=603622&r1=603621&r2=603622&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/servlet/MicroslingMainServlet.java
(original)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/servlet/MicroslingMainServlet.java
Wed Dec 12 06:16:31 2007
@@ -28,6 +28,7 @@
 import javax.servlet.Filter;
 import javax.servlet.GenericServlet;
 import javax.servlet.Servlet;
+import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
@@ -108,6 +109,7 @@
     /** init our serviceLocator */
     protected void initServiceLocator() throws ServletException {
         serviceLocator = new MicroslingServiceLocator();
+        serviceLocator.registerService(ServletContext.class, getServletContext());
     }
 
     /** init our scriptResolver */

Added: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/ScriptBuiltinObjectsTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/ScriptBuiltinObjectsTest.java?rev=603622&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/ScriptBuiltinObjectsTest.java
(added)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/ScriptBuiltinObjectsTest.java
Wed Dec 12 06:16:31 2007
@@ -0,0 +1,44 @@
+package org.apache.sling.microsling.integration;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+public class ScriptBuiltinObjectsTest extends RenderingTestBase {
+    
+    private String slingResourceType;
+    
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        // set test values
+        slingResourceType = "integration-test/srt." + System.currentTimeMillis();
+        testText = "This is a test " + System.currentTimeMillis();
+
+        // create the test node, under a path that's specific to this class to allow collisions
+        final String url = HTTP_BASE_URL + "/" + getClass().getSimpleName() + "/" + System.currentTimeMillis()
+ "/*";
+        final Map<String,String> props = new HashMap<String,String>();
+        props.put("sling:resourceType", slingResourceType);
+        props.put("text", testText);
+        displayUrl = testClient.createNode(url, props);
+
+        // the rendering script goes under /sling/scripts in the repository
+        scriptPath = "/sling/scripts/" + slingResourceType;
+        testClient.mkdirs(WEBDAV_BASE_URL, scriptPath);
+    }
+    
+    public void testEspBuiltinObjects() throws IOException {
+        final String toDelete = uploadTestScript("builtin-objects.esp","html.esp");
+        try {
+            final String content = getContent(displayUrl + ".html", CONTENT_TYPE_HTML);
+            assertTrue("Content includes ESP marker",content.contains("ESP template"));
+            assertTrue("Content includes test text", content.contains(testText));
+            assertTrue("Content includes ServletContext data",content.contains("ServletContext:text/plain"));
+            assertTrue("Content includes response data",content.contains("SlingHttpServletResponse:false"));
+        } finally {
+            testClient.delete(toDelete);
+        }
+    }
+    
+}

Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/ScriptBuiltinObjectsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/ScriptBuiltinObjectsTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/sling/trunk/microsling/microsling-core/src/test/resources/integration-test/builtin-objects.esp
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/resources/integration-test/builtin-objects.esp?rev=603622&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/resources/integration-test/builtin-objects.esp
(added)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/resources/integration-test/builtin-objects.esp
Wed Dec 12 06:16:31 2007
@@ -0,0 +1,20 @@
+<%-- used by ScriptBuiltinObjectsTest --%>
+<html>
+	<body>
+		ESP template
+		<p><%= resource.node.text %></p>
+	</body>
+	
+	<!-- test access request and to ServletContext -->
+	<%
+		var scClass = Packages.javax.servlet.ServletContext;
+		var sc = request.getServiceLocator().getService(scClass);
+	%>
+	<p>ServletContext:<%= sc.getMimeType('foo.txt') %></p>
+	
+	<!-- test access to Response -->
+	<p>SlingHttpServletResponse:<%= response.containsHeader('NOT_A_HEADER') %></p>
+	
+	<!-- sling object is tested elsewhere (IncludeTest) -->
+	
+</html>



Mime
View raw message