Author: bdelacretaz
Date: Tue Apr 28 12:16:18 2009
New Revision: 769356

URL: http://svn.apache.org/viewvc?rev=769356&view=rev
Log:
SLING-928 - Integration tests for Scala scripting engine, contributed by 
Michael Duerig, thanks!

Added:
    
incubator/sling/trunk/contrib/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/scala/
    
incubator/sling/trunk/contrib/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/scala/ScalaScriptingTest.java
   (with props)
    
incubator/sling/trunk/contrib/launchpad/testing/src/test/resources/integration-test/scala/
    
incubator/sling/trunk/contrib/launchpad/testing/src/test/resources/integration-test/scala/rendering-test.scs
Modified:
    incubator/sling/trunk/contrib/launchpad/testing/pom.xml
    
incubator/sling/trunk/contrib/scripting/scala/interpreter/src/main/scala/org/apache/sling/scripting/scala/interpreter/BundleFS.scala

Modified: incubator/sling/trunk/contrib/launchpad/testing/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/contrib/launchpad/testing/pom.xml?rev=769356&r1=769355&r2=769356&view=diff
==============================================================================
--- incubator/sling/trunk/contrib/launchpad/testing/pom.xml (original)
+++ incubator/sling/trunk/contrib/launchpad/testing/pom.xml Tue Apr 28 12:16:18 
2009
@@ -235,7 +235,7 @@
                             </outputDirectory>
                             <excludeTransitive>true</excludeTransitive>
                             <includeArtifactIds>
-                                
org.apache.sling.scripting.python,org.apache.sling.scripting.xproc,org.apache.sling.extensions.apt.parser,org.apache.sling.extensions.apt.servlet,org.apache.sling.samples.path-based.rtp
+                                
org.apache.sling.scripting.python,org.apache.sling.scripting.xproc,org.apache.sling.extensions.apt.parser,org.apache.sling.extensions.apt.servlet,org.apache.sling.samples.path-based.rtp,org.apache.sling.scripting.scala
                             </includeArtifactIds>
                             <includeScope>
                                 provided
@@ -631,6 +631,12 @@
             <version>2.0.3-incubator-SNAPSHOT</version>
             <scope>provided</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.scripting.scala</artifactId>
+            <version>0.9.0-incubator-SNAPSHOT</version>
+            <scope>provided</scope>
+        </dependency>
 
         <!-- JCR Install - needs to be in a profile -->
         <dependency>

Added: 
incubator/sling/trunk/contrib/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/scala/ScalaScriptingTest.java
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/contrib/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/scala/ScalaScriptingTest.java?rev=769356&view=auto
==============================================================================
--- 
incubator/sling/trunk/contrib/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/scala/ScalaScriptingTest.java
 (added)
+++ 
incubator/sling/trunk/contrib/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/scala/ScalaScriptingTest.java
 Tue Apr 28 12:16:18 2009
@@ -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.webapp.integrationtest.scala;
+
+import org.apache.sling.commons.testing.integration.HttpTestBase;
+import org.apache.sling.servlets.post.SlingPostConstants;
+
+public class ScalaScriptingTest extends HttpTestBase {
+    private String testRootUrl;
+    private TestNode testNode;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        final String testRootPath = HTTP_BASE_URL + "/" + 
getClass().getSimpleName() + "/" + System.currentTimeMillis();
+        testRootUrl = testClient.createNode(testRootPath + 
SlingPostConstants.DEFAULT_CREATE_SUFFIX, null);
+        testNode = new TestNode(testRootPath + "/test", null);
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        testClient.delete(testRootUrl);
+        super.tearDown();
+    }
+
+    public void testNoScript() throws Exception {
+        final String content = getContent(testNode.nodeUrl + ".txt", 
CONTENT_TYPE_PLAIN);
+        assertTrue(content.contains("PlainTextRendererServlet"));
+        assertTrue("Content contains " + testNode.testText + " (" + content + 
")", content.contains(testNode.testText));
+    }
+
+    public void testScala() throws Exception {
+        final String toDelete = uploadTestScript(testNode.scriptPath, 
"scala/rendering-test.scs", "html.scs");
+        try {
+            checkContent(testNode);
+        }
+        finally {
+            if(toDelete != null) {
+                testClient.delete(toDelete);
+            }
+        }
+    }
+
+    private void checkContent(TestNode node) throws Exception {
+        final String content = getContent(node.nodeUrl + ".html", 
CONTENT_TYPE_HTML);
+        assertTrue("Scala script executed as expected (" + content + ")", 
content.contains("<h1>Scala rendering result</h1>"));
+
+        final String [] expected = {
+                "using resource.adaptTo:" + node.testText,
+                "using currentNode:" + node.testText,
+        };
+        for(String exp : expected) {
+            assertTrue("Content contains " + exp + "(" + content + ")", 
content.contains(exp));
+        }
+    }
+
+}

Propchange: 
incubator/sling/trunk/contrib/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/scala/ScalaScriptingTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: 
incubator/sling/trunk/contrib/launchpad/testing/src/test/resources/integration-test/scala/rendering-test.scs
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/contrib/launchpad/testing/src/test/resources/integration-test/scala/rendering-test.scs?rev=769356&view=auto
==============================================================================
--- 
incubator/sling/trunk/contrib/launchpad/testing/src/test/resources/integration-test/scala/rendering-test.scs
 (added)
+++ 
incubator/sling/trunk/contrib/launchpad/testing/src/test/resources/integration-test/scala/rendering-test.scs
 Tue Apr 28 12:16:18 2009
@@ -0,0 +1,28 @@
+/*
+ * 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.
+ */
+
+val html = <h1>Scala rendering result</h1>
+<p>
+       text value using resource.adaptTo:{ 
resource.adaptTo(classOf[javax.jcr.Node]).getProperty("text").getValue().getString()
 }
+</p>
+<p>
+       text value using currentNode:{ 
currentNode.getProperty("text").getValue().getString() }
+</p>;
+
+println(html)

Modified: 
incubator/sling/trunk/contrib/scripting/scala/interpreter/src/main/scala/org/apache/sling/scripting/scala/interpreter/BundleFS.scala
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/contrib/scripting/scala/interpreter/src/main/scala/org/apache/sling/scripting/scala/interpreter/BundleFS.scala?rev=769356&r1=769355&r2=769356&view=diff
==============================================================================
--- 
incubator/sling/trunk/contrib/scripting/scala/interpreter/src/main/scala/org/apache/sling/scripting/scala/interpreter/BundleFS.scala
 (original)
+++ 
incubator/sling/trunk/contrib/scripting/scala/interpreter/src/main/scala/org/apache/sling/scripting/scala/interpreter/BundleFS.scala
 Tue Apr 28 12:16:18 2009
@@ -36,6 +36,7 @@
     require(bundle != null, "bundle must not be null")
 
     abstract class BundleEntry(url: URL, parent: DirEntry) extends 
AbstractFile {
+      require(url != null, "url must not be null")
       lazy val (path: String, name: String) = getPathAndName(url)
       lazy val fullName: String = 
(path::name::Nil).filter(!_.isEmpty).mkString("/")
 
@@ -96,12 +97,26 @@
           def hasNext = dirs.hasMoreElements
           def next = {
             val entry = dirs.nextElement.asInstanceOf[String]
-            val entryUrl = bundle.getResource("/" + entry)
-            if (entry.endsWith("/"))
-              new DirEntry(entryUrl, DirEntry.this)
-            else
+            var entryUrl = bundle.getResource("/" + entry)
+
+            // Bundle.getResource seems to be inconsistent with respect to 
requiring
+            // a trailing slash
+            if (entryUrl == null) 
+              entryUrl = bundle.getResource("/" + removeTralingSlash(entry))
+            
+            if (entry.endsWith(".class"))
               new FileEntry(entryUrl, DirEntry.this)
+            else
+              new DirEntry(entryUrl, DirEntry.this)
           }
+          
+          private def removeTralingSlash(s: String): String = 
+            if (s == null || s.length == 0)
+              s
+            else if (s.last == '/') 
+              removeTralingSlash(s.substring(0, s.length - 1))
+            else
+              s
         }
       }
 


Reply via email to