incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r588701 - in /incubator/sling/whiteboard/microsling/src/test: java/org/apache/sling/microsling/integration/ resources/integration-test/
Date Fri, 26 Oct 2007 16:22:29 GMT
Author: bdelacretaz
Date: Fri Oct 26 09:22:27 2007
New Revision: 588701

URL: http://svn.apache.org/viewvc?rev=588701&view=rev
Log:
SLING-82 - rendering tests implemented, create a node and test its rendering with esp, js
and vlt scripts

Added:
    incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/NodetypeRenderingTest.java
  (with props)
    incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/RenderingTestBase.java
  (with props)
    incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/SlingResourceTypeRenderingTest.java
  (with props)
    incubator/sling/whiteboard/microsling/src/test/resources/integration-test/rendering-test.esp
    incubator/sling/whiteboard/microsling/src/test/resources/integration-test/rendering-test.js
  (with props)
    incubator/sling/whiteboard/microsling/src/test/resources/integration-test/rendering-test.vlt
Modified:
    incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/FileUploadTest.java
    incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/MicroslingHttpTestBase.java

Modified: incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/FileUploadTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/FileUploadTest.java?rev=588701&r1=588700&r2=588701&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/FileUploadTest.java
(original)
+++ incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/FileUploadTest.java
Fri Oct 26 09:22:27 2007
@@ -31,16 +31,22 @@
     public void testUploadAndDelete() throws IOException {
         final String testFile = "/integration-test/testfile.txt";
         final InputStream data = getClass().getResourceAsStream(testFile);
-        assertNotNull("Local test file " + testFile + " must be found",data);
-        
-        final String webdavUrl = WEBDAV_BASE_URL + "/FileUploadTest." + System.currentTimeMillis()
+ ".txt";
-        
-        // Upload a file via WebDAV, verify, delete and verify
-        assertHttpStatus(webdavUrl, 404, "Resource " + webdavUrl + " must not exist before
test");
-        int status = testClient.upload(webdavUrl, data);
-        assertEquals("upload must return status code 201",201,status);
-        assertHttpStatus(webdavUrl, 200, "Resource " + webdavUrl + " must exist after upload");
-        testClient.delete(webdavUrl);
-        assertHttpStatus(webdavUrl, 404, "Resource " + webdavUrl + " must not exist anymore
after deleting");
+        try {
+            assertNotNull("Local test file " + testFile + " must be found",data);
+            
+            final String webdavUrl = WEBDAV_BASE_URL + "/FileUploadTest." + System.currentTimeMillis()
+ ".txt";
+            
+            // Upload a file via WebDAV, verify, delete and verify
+            assertHttpStatus(webdavUrl, 404, "Resource " + webdavUrl + " must not exist before
test");
+            int status = testClient.upload(webdavUrl, data);
+            assertEquals("upload must return status code 201",201,status);
+            assertHttpStatus(webdavUrl, 200, "Resource " + webdavUrl + " must exist after
upload");
+            testClient.delete(webdavUrl);
+            assertHttpStatus(webdavUrl, 404, "Resource " + webdavUrl + " must not exist anymore
after deleting");
+        } finally {
+            if(data!=null) {
+                data.close();
+            }
+        }
     }
 }

Modified: incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/MicroslingHttpTestBase.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/MicroslingHttpTestBase.java?rev=588701&r1=588700&r2=588701&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/MicroslingHttpTestBase.java
(original)
+++ incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/MicroslingHttpTestBase.java
Fri Oct 26 09:22:27 2007
@@ -37,6 +37,10 @@
     /** base path for test files */
     public static final String TEST_PATH = "/microsling-integration-tests";
     
+    public static final String CONTENT_TYPE_HTML = "text/html";
+    public static final String CONTENT_TYPE_XML = "text/xml";
+    public static final String CONTENT_TYPE_PLAIN = "text/plain";
+    
     protected MicroslingIntegrationTestClient testClient;
     protected HttpClient httpClient;
     

Added: incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/NodetypeRenderingTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/NodetypeRenderingTest.java?rev=588701&view=auto
==============================================================================
--- incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/NodetypeRenderingTest.java
(added)
+++ incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/NodetypeRenderingTest.java
Fri Oct 26 09:22:27 2007
@@ -0,0 +1,106 @@
+/*
+ * 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.microsling.integration;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+/** Test creating a Node and rendering it using scripts in 
+ *  various supported languages, using nodetype-based
+ *  script resolution
+ */
+public class NodetypeRenderingTest extends RenderingTestBase {
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        
+        // set test values
+        testText = "This is a test " + System.currentTimeMillis();
+        
+        // create the test node
+        final String url = HTTP_BASE_URL + TEST_PATH + ".sling";
+        final Map<String,String> props = new HashMap<String,String>();
+        props.put("text", testText);
+        displayUrl = testClient.createNode(url, props);
+        
+        // the rendering script goes under /sling/scripts in the repository
+        scriptPath = "/sling/scripts/NODETYPES/nt/unstructured";
+        testClient.mkdirs(WEBDAV_BASE_URL, scriptPath);
+    }
+    
+    public void testWithoutScript() throws IOException {
+        final String content = getContent(displayUrl + ".html", CONTENT_TYPE_PLAIN);
+        assertTrue("Content includes default servlet marker",content.contains("dumped by
DefaultSlingServlet"));
+    }
+    
+    public void testEspHtml() throws IOException {
+        final String toDelete = uploadTestScript("rendering-test.esp","html.esp");
+        try {
+            final String content = getContent(displayUrl + ".html", CONTENT_TYPE_HTML);
+            assertTrue("Content includes ESP marker",content.contains("ESP template"));
+            assertTrue("Content contains formatted test text",content.contains("<p>"
+ testText + "</p>"));
+        } finally {
+            testClient.delete(toDelete);
+        }
+    }
+    
+    public void testEspXml() throws IOException {
+        final String toDelete = uploadTestScript("rendering-test.esp","xml.esp");
+        try {
+            final String content = getContent(displayUrl + ".xml", CONTENT_TYPE_XML);
+            assertTrue("Content includes ESP marker",content.contains("ESP template"));
+            assertTrue("Content contains formatted test text",content.contains("<p>"
+ testText + "</p>"));
+        } finally {
+            testClient.delete(toDelete);
+        }
+    }
+    
+    public void testEspPlain() throws IOException {
+        final String toDelete = uploadTestScript("rendering-test.esp","plain.esp");
+        try {
+            final String content = getContent(displayUrl + ".txt", CONTENT_TYPE_PLAIN);
+            assertTrue("Content includes ESP marker",content.contains("ESP template"));
+            assertTrue("Content contains formatted test text",content.contains("<p>"
+ testText + "</p>"));
+        } finally {
+            testClient.delete(toDelete);
+        }
+    }
+    
+    public void testVltHtml() throws IOException {
+        final String toDelete = uploadTestScript("rendering-test.vlt","html.vlt");
+        try {
+            final String content = getContent(displayUrl + ".html", CONTENT_TYPE_HTML);
+            assertTrue("Content includes VLT marker",content.contains("Velocity template"));
+            assertTrue("Content contains formatted test text",content.contains("<p><b>"
+ testText + "</b></p>"));
+        } finally {
+            testClient.delete(toDelete);
+        }
+    }
+    
+    public void testJsHtml() throws IOException {
+        final String toDelete = uploadTestScript("rendering-test.js","html.js");
+        try {
+            final String content = getContent(displayUrl + ".html", CONTENT_TYPE_HTML);
+            assertTrue("Content includes JS marker",content.contains("Raw javascript template"));
+            assertTrue("Content contains formatted test text",content.contains("<p><em>"
+ testText + "</em></p>"));
+        } finally {
+            testClient.delete(toDelete);
+        }
+    }
+}
\ No newline at end of file

Propchange: incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/NodetypeRenderingTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/RenderingTestBase.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/RenderingTestBase.java?rev=588701&view=auto
==============================================================================
--- incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/RenderingTestBase.java
(added)
+++ incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/RenderingTestBase.java
Fri Oct 26 09:22:27 2007
@@ -0,0 +1,62 @@
+/*
+ * 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.microsling.integration;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.methods.GetMethod;
+
+/** Base class for rendering tests
+ */
+class RenderingTestBase extends MicroslingHttpTestBase {
+
+    protected String scriptPath;
+    protected String testText;
+    protected String displayUrl;
+    
+    /** upload rendering test script, and return its URL for future deletion */
+    protected String uploadTestScript(String localFilename,String filenameOnServer) throws
IOException {
+        final String url = WEBDAV_BASE_URL + scriptPath + "/" + filenameOnServer;
+        final String testFile = "/integration-test/" + localFilename;
+        final InputStream data = getClass().getResourceAsStream(testFile);
+        try {
+            testClient.upload(url, data);
+        } finally {
+            if(data!=null) {
+                data.close();
+            }
+        }
+        return url;
+    }
+    
+    /** retrieve the contents of given URL and assert its content type 
+     * @throws IOException 
+     * @throws HttpException */
+    protected String getContent(String url, String expectedContentType) throws IOException
{
+        final GetMethod get = new GetMethod(url);
+        final int status = httpClient.executeMethod(get);
+        assertEquals("Expected status 200 for " + url,200,status);
+        assertTrue(
+            "Expected Content-Type '" + expectedContentType + "' for " + url,
+            get.getResponseHeader("Content-Type").getValue().startsWith(expectedContentType)
+        );
+        return get.getResponseBodyAsString();
+    }
+    
+}
\ No newline at end of file

Propchange: incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/RenderingTestBase.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/SlingResourceTypeRenderingTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/SlingResourceTypeRenderingTest.java?rev=588701&view=auto
==============================================================================
--- incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/SlingResourceTypeRenderingTest.java
(added)
+++ incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/SlingResourceTypeRenderingTest.java
Fri Oct 26 09:22:27 2007
@@ -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.microsling.integration;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+/** Test creating a Node and rendering it using scripts in 
+ *  various supported languages, using slingResourceType-based
+ *  script resolution
+ */
+public class SlingResourceTypeRenderingTest 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
+        final String url = HTTP_BASE_URL + TEST_PATH + ".sling";
+        final Map<String,String> props = new HashMap<String,String>();
+        props.put("slingResourceType", 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 testWithoutScript() throws IOException {
+        final String content = getContent(displayUrl + ".html", CONTENT_TYPE_PLAIN);
+        assertTrue("Content includes default servlet marker",content.contains("dumped by
DefaultSlingServlet"));
+    }
+    
+    public void testEspHtml() throws IOException {
+        final String toDelete = uploadTestScript("rendering-test.esp","html.esp");
+        try {
+            final String content = getContent(displayUrl + ".html", CONTENT_TYPE_HTML);
+            assertTrue("Content includes ESP marker",content.contains("ESP template"));
+            assertTrue("Content contains formatted test text",content.contains("<p>"
+ testText + "</p>"));
+        } finally {
+            testClient.delete(toDelete);
+        }
+    }
+    
+    public void testEspXml() throws IOException {
+        final String toDelete = uploadTestScript("rendering-test.esp","xml.esp");
+        try {
+            final String content = getContent(displayUrl + ".xml", CONTENT_TYPE_XML);
+            assertTrue("Content includes ESP marker",content.contains("ESP template"));
+            assertTrue("Content contains formatted test text",content.contains("<p>"
+ testText + "</p>"));
+        } finally {
+            testClient.delete(toDelete);
+        }
+    }
+    
+    public void testEspPlain() throws IOException {
+        final String toDelete = uploadTestScript("rendering-test.esp","plain.esp");
+        try {
+            final String content = getContent(displayUrl + ".txt", CONTENT_TYPE_PLAIN);
+            assertTrue("Content includes ESP marker",content.contains("ESP template"));
+            assertTrue("Content contains formatted test text",content.contains("<p>"
+ testText + "</p>"));
+        } finally {
+            testClient.delete(toDelete);
+        }
+    }
+    
+    public void testVltHtml() throws IOException {
+        final String toDelete = uploadTestScript("rendering-test.vlt","html.vlt");
+        try {
+            final String content = getContent(displayUrl + ".html", CONTENT_TYPE_HTML);
+            assertTrue("Content includes VLT marker",content.contains("Velocity template"));
+            assertTrue("Content contains formatted test text",content.contains("<p><b>"
+ testText + "</b></p>"));
+        } finally {
+            testClient.delete(toDelete);
+        }
+    }
+    
+    public void testJsHtml() throws IOException {
+        final String toDelete = uploadTestScript("rendering-test.js","html.js");
+        try {
+            final String content = getContent(displayUrl + ".html", CONTENT_TYPE_HTML);
+            assertTrue("Content includes JS marker",content.contains("Raw javascript template"));
+            assertTrue("Content contains formatted test text",content.contains("<p><em>"
+ testText + "</em></p>"));
+        } finally {
+            testClient.delete(toDelete);
+        }
+    }
+}
\ No newline at end of file

Propchange: incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/SlingResourceTypeRenderingTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: incubator/sling/whiteboard/microsling/src/test/resources/integration-test/rendering-test.esp
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/test/resources/integration-test/rendering-test.esp?rev=588701&view=auto
==============================================================================
--- incubator/sling/whiteboard/microsling/src/test/resources/integration-test/rendering-test.esp
(added)
+++ incubator/sling/whiteboard/microsling/src/test/resources/integration-test/rendering-test.esp
Fri Oct 26 09:22:27 2007
@@ -0,0 +1,7 @@
+<%-- used by ScriptedRenderingTest --%>
+<html>
+	<body>
+		ESP template
+		<p><%= resource.item.text %></p>
+	</body>
+</html>

Added: incubator/sling/whiteboard/microsling/src/test/resources/integration-test/rendering-test.js
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/test/resources/integration-test/rendering-test.js?rev=588701&view=auto
==============================================================================
--- incubator/sling/whiteboard/microsling/src/test/resources/integration-test/rendering-test.js
(added)
+++ incubator/sling/whiteboard/microsling/src/test/resources/integration-test/rendering-test.js
Fri Oct 26 09:22:27 2007
@@ -0,0 +1,5 @@
+// Used by ScriptedRenderingTest
+out.println("<html><body>");
+out.println("Raw javascript template");
+out.println("<p><em>" + resource.item.text + "</em></p>");
+out.print("</body></html>");

Propchange: incubator/sling/whiteboard/microsling/src/test/resources/integration-test/rendering-test.js
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sling/whiteboard/microsling/src/test/resources/integration-test/rendering-test.vlt
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/test/resources/integration-test/rendering-test.vlt?rev=588701&view=auto
==============================================================================
--- incubator/sling/whiteboard/microsling/src/test/resources/integration-test/rendering-test.vlt
(added)
+++ incubator/sling/whiteboard/microsling/src/test/resources/integration-test/rendering-test.vlt
Fri Oct 26 09:22:27 2007
@@ -0,0 +1,7 @@
+<!-- Used by ScriptedRenderingTest -->
+<html>
+	<body>
+		Velocity template
+		<p><b>$resource.getItem().getProperty("text").getString()</b></p>
+	</body>
+</html>



Mime
View raw message