You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2007/11/01 14:30:08 UTC
svn commit: r590999 [4/5] - in /incubator/sling/trunk/microsling: ./
microsling-core/ microsling-core/src/ microsling-core/src/main/
microsling-core/src/main/java/ microsling-core/src/main/java/org/
microsling-core/src/main/java/org/apache/ microsling-...
Added: incubator/sling/trunk/microsling/microsling-core/src/main/webapp/index.html
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/webapp/index.html?rev=590999&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/webapp/index.html (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/webapp/index.html Thu Nov 1 06:30:00 2007
@@ -0,0 +1,147 @@
+<html>
+<head>
+ <title>microsling homepage</title>
+ <link rel="stylesheet" href="microsling.css"/>
+</head>
+<body>
+ <h1>microsling homepage</h1>
+
+ <p>
+ <em>Sling request processing, reduced to the max!</em>
+ </p>
+
+ <h2>Overview</h2>
+ <p>
+ The goal of microsling is to demonstrate the Sling HTTP
+ request processing in the simplest possible way, to help the
+ community converge on the goals and architecture of this
+ module.
+ </p>
+
+ <h2>microsling test links</h2>
+ <ul>
+ <li>
+ <a href="content-creation-forms.html">
+ Content creation forms
+ </a>: use this page to create content and test the rendering mechanisms.
+ </li>
+ <li>
+ <a href="velocity-scripts.html">
+ Velocity templates
+ </a>: explains how to use Velocity templates to render content.
+ </li>
+ <li>
+ <a href="server-side-javascript.html">
+ Server-side javascript and ESP templates
+ </a>: explains how to use server-side javascript and javascript-based ESP templates to process requests.
+ </li>
+ <li>
+ <a href="freemarker-scripts.html">
+ FreeMarker templates
+ </a>: explains how to use FreeMarker templates to render content.
+ </li>
+ </ul>
+
+ <h2>Show me the code</h2>
+ <p>
+ Here's a brief description of how microsling processes HTTP requests. Follow the links to the source code
+ for more details.
+ <ul>
+ <li>
+ The main <a href="http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/servlet/MicroSlingServlet.java?view=markup">MicroSlingServlet</a>
+ handles HTTP requests. That's probably where you want to
+ start studying the code.
+ </li>
+ <li>
+ <a href="http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/RequestFilter.java?view=markup">RequestFilter</a>
+ objects process the incoming requests before passing them on to SlingServlet objects
+ which do the actual processing.
+ <ul>
+ <li>
+ The
+ <a href="http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/resource/ResourceResolverFilter.java?view=markup">ResourceResolverFilter</a>
+ selects the <a href="http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/Resource.java?view=markup">Resource</a> (currently a JCR Node, OCM is not used yet) to process.
+ </li>
+ <li>
+ The <a href="http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/contenttype/ResponseContentTypeResolverFilter.java?view=markup">ResponseContentTypeResolverFilter</a>
+ computes the desired <em>Content-Type</em> for the response, so that rendering scripts or SlingServlets know what output format to generate.
+ </li>
+ </ul>
+ Other filters would include
+ Locale selection, client capabilities analysis, etc.
+
+ </li>
+ <li>
+ After applying the RequestFilters, the MicroSlingServlet selects a
+ <a href="http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/SlingServlet.java?view=markup">SlingServlet</a> to process the request.
+ The first SlingServlet where canProcess(...) returns true is used.
+ </li>
+ <li>
+ The <a href="http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/requestcontext/SlingRequestContext.java?view=markup">SlingRequestContext</a> is
+ stored as a request attribute, and gives access to Sling-specific objects (Resource, repository Session, etc.) used for request processing.
+ </li>
+ <li>
+ A few SlingServlet classes are implemented (source code <a href="http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/">here</a>):
+ <ul>
+ <li>
+ The SlingPostServlet allows Nodes to be created by POSTing to URLs ending
+ with ".sling".
+ </li>
+ <li>
+ The VelocityTemplatesServlet and RhinoJavascriptServlet execute server-side scripts in those
+ languages to process requests.
+ </li>
+ <li>
+ The DefaultSlingServlet is used when no other SlingServlet wants the request.
+ </li>
+ </ul>
+ </li>
+ <li>
+ The <a href="http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/SlingScriptResolver.java?view=markup">SlingScriptResolver</a>
+ is used by the scripting SlingServlet classes to locate scripts in the repository.
+ See comments in that class for how script paths are computed based on the Resource's resourceType and the
+ request method and extension.
+ </li>
+ <li>
+ Rendering scripts can generate various output formats, for example a Velocity script named "get.xml.vlt" will
+ cause a page with <em>Content-Type=text/xml</em> to be generated by the VelocityTemplatesServlet.
+ </li>
+ <li>
+ The microsling architecture allows
+ additional scripting engines (JSP, JRuby, BSF,...) to be plugged in easily - and this would
+ of course be much easier with OSGi.
+ </li>
+ <li>
+ We'll probably need a ResponseFilter interface at some point, but for now it's not needed. It could be useful
+ to apply "rendering standards" to the output, adding header/footers/glitter to HTML pages for example.
+ </li>
+ </ul>
+ <p>
+ If you have followed the links to source code in the above descriptions, you've seen most or all of the interesting
+ microsling source code. What's remaining are a few simple support classes.
+ </p>
+ </p>
+
+ <h2>No OSGi</h2>
+ <p>
+ To keep things simple, microsling does <em>not</em> use OSGi.
+ We will of course continue to use OSGi in the real Sling, and there are many
+ places in the code which say <em>TODO - use OSGi plugins here</em>. Keeping things
+ "static" for this example makes it easier to concentrate on the basics.
+ </p>
+
+ <h2>More test links</h2>
+ <p>
+ <ul>
+ <li>
+ <a href="repository-info">repository-info</a>, dumps the JCR repository
+ properties.
+ </li>
+ <li>
+ <a href="repository/default">WebDAV mount point</a>: use this URL to mount
+ the repository via WebDAV (login = admin/admin).
+ </li>
+ </ul>
+ </p>
+</body>
+</html>
\ No newline at end of file
Propchange: incubator/sling/trunk/microsling/microsling-core/src/main/webapp/index.html
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/sling/trunk/microsling/microsling-core/src/main/webapp/microsling.css
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/webapp/microsling.css?rev=590999&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/webapp/microsling.css (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/webapp/microsling.css Thu Nov 1 06:30:00 2007
@@ -0,0 +1,58 @@
+body {
+ font-family: Verdana,Helvetica,Arial,sans-serif;
+}
+
+h1,h2,h3,h4 {
+ color:#869900;
+}
+
+h1 {
+ border-color:#999999;
+ border-style:solid solid dotted;
+ border-width:0px 0px 1px;
+ color:#869900;
+ font-size:x-large;
+ font-weight:900;
+ padding:20px 4px 4px 0px;
+}
+
+h2 {
+ font-size: large;
+ font-weight:900;
+}
+
+h3 {
+ font-weight:900;
+ font-size:100%;
+}
+
+.testbox {
+ border: solid gray 1px;
+ margin: 1em;
+ padding: 0.5em;
+}
+
+form h1 {
+ padding: 1px;
+ margin: 1px;
+ font-size: 100%;
+}
+
+p {
+ margin-bottom: 0.5em;
+}
+
+li {
+ margin-bottom: 0.2em;
+}
+
+pre {
+ font-size: 120%;
+ background-color: #FFFFCC;
+ border: solid #FF9900 1px;
+ padding: 0.5em;
+}
+
+.note {
+ font-size:80%;
+}
Propchange: incubator/sling/trunk/microsling/microsling-core/src/main/webapp/microsling.css
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/sling/trunk/microsling/microsling-core/src/main/webapp/server-side-javascript.html
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/webapp/server-side-javascript.html?rev=590999&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/webapp/server-side-javascript.html (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/webapp/server-side-javascript.html Thu Nov 1 06:30:00 2007
@@ -0,0 +1,137 @@
+<html>
+<head>
+ <title>microsling server-side javascript and ESP templates</title>
+ <link rel="stylesheet" href="microsling.css"/>
+</head>
+<body>
+ <h1>microsling server-side javascript and ESP templates</h1>
+
+ <div class="note">
+ <a href="../">back to homepage</a>
+ </div>
+
+ <p>
+ Server-side javascript code and javascript-based ESP templates can be used by microsling to process requests.
+ The scripts are located by the
+ <a href="http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/scripting/SlingScriptResolver.java?view=markup">SlingScriptResolver</a>
+ , as for the <a href="velocity-scripts.html">Velocity templates</a> (see that
+ page for more details about how this resolution works).
+ </p>
+ <p>
+ Scripts can either:
+ <ul>
+ <li>
+ Have the <em>.esp</em> extension to use the microsling <em>ECMAscript Server Pages</em> syntax
+ described below.
+ </li>
+ <li>
+ Have the <em>.js</em> extension to use "raw" javascript.
+ </li>
+ </ul>
+ </p>
+ <p>
+ Server-side javascript support is implemented by the
+ <a href="http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/RhinoJavascriptServlet.java?revision=585096&view=markup">RhinoJavascriptServlet</a>.
+ </p>
+ <p>
+ To test this, remove or rename <a href="velocity-scripts.html">Velocity templates</a>
+ if you played with them before (Velocity has priority due to the order in which the SlingServlet classes
+ are setup), and store one of the scripts shown
+ below under <em>/sling/scripts/microsling/example/</em>, using the filenames shown in comments in the scripts below.
+ </p>
+ <p>
+ Content nodes created with the <a href="content-creation-forms.html">Content creation forms</a>
+ should then be displayed in HTML, with a layout defined by the example scripts.
+ </p>
+ <p>
+ As for the Velocity templates, other output formats can be generated, for example by renaming the ESP template
+ to <em>plain.esp</em> (as the Content-type for text is <em>text/plain</em>), modifying it to output plain text
+ and using a <em>.txt</em> extension in the request.
+ </p>
+
+ <h2>ECMAscript Server Pages (ESP)</h2>
+ <p>
+ <em>ECMAscript Server Pages</em> work much like JSP:
+ <ul>
+ <li>
+ A template mixes javascript code with litteral text that is copied to the output.
+ </li>
+ <li>
+ <em><% ... %></em> tags enclose code blocks.
+ </li>
+ <li>
+ <em><%= ... %></em> tags include the result of a javascript expression in the output.
+ </li>
+ <li>
+ Several standard objects are available in javascript to access microsling data
+ (TODO: document these objects - for now see the RhinoJavascriptServlet source code)
+ </li>
+ </ul>
+ </p>
+ <h3>ESP template example</h3>
+ <pre>
+<%-- microsling ESP template example, store this as html.esp --%>
+<html>
+<body>
+<p>This page is generated from an ESP template!</p>
+<h1><%= resource.getURI() %></h1>
+<%
+ for (var prop in resource.item) {
+ %>
+ <p>
+ <%= resource.item[prop] %>
+ </p>
+ <%
+ }
+%>
+</body>
+</html></pre>
+ <h2>Raw javascript</h2>
+ <p>
+ Raw javascript is probably more useful to handle the POST, PUT or DELETE methods.
+ </p>
+
+ <h3>Javascript example</h3>
+ <pre>
+// store this as html.js in the repository
+// TODO this is not very useful, rewrite this example
+out.println("<html><body>");
+out.println("<p>This page is generated from a rhino script</p>");
+out.println("<h1>" + resource.getURI() + "</h1>");
+out.println("<p>Title: " + resource.getItem().getProperty('title').getString() + "</p>");
+out.println("<p>Text: " + resource.getItem().getProperty('text').getString() + "</p>");
+out.println("</body></html>");</pre>
+ </p>
+ </div>
+
+ <h2>Directory listing example</h2>
+ <p>
+ Store the following template under
+ <code>sling/scripts/NODETYPES/nt/unstructured/html.esp</code> to render a simple
+ directory listing for <em>nt:unstructured</em> nodes which do not have a
+ <code>slingComponentId</code> property.
+ </p>
+ <pre>
+<%-- microsling ESP directory listing example -%>
+<html>
+<body>
+<p>This HTML directory listing is generated from an ESP template!</p>
+<h1><%= resource.uri %></h1>
+<ol>
+<%
+for (var prop in resource.item) {
+ if (resource.item[prop]["text"]) {
+ %><li><a href="/microsling<%= resource.item[prop] %>.html"><%= resource.item[prop] %></a></li><%
+ }
+}
+%>
+</ol>
+</body>
+</html></pre>
+ <p>
+ If you have created some content with the test form, and activated the above template,
+ <a href="microsling/content/testing.sling.html">microsling/content/testing.sling.html</a> should
+ display an HTML directory listing.
+ </p>
+</body>
+</html>
\ No newline at end of file
Propchange: incubator/sling/trunk/microsling/microsling-core/src/main/webapp/server-side-javascript.html
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/sling/trunk/microsling/microsling-core/src/main/webapp/velocity-scripts.html
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/webapp/velocity-scripts.html?rev=590999&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/webapp/velocity-scripts.html (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/webapp/velocity-scripts.html Thu Nov 1 06:30:00 2007
@@ -0,0 +1,65 @@
+<html>
+<head>
+ <title>microsling Velocity templates</title>
+ <link rel="stylesheet" href="microsling.css"/>
+</head>
+<body>
+ <h1>microsling Velocity templates</h1>
+
+ <div class="note">
+ <a href="../">back to homepage</a>
+ </div>
+ <p>
+ When processing requests, the <em>VelocityTemplatesServlet</em> ask the <em>SlingScriptResolver</em>
+ for scripts with the <em>.vlt</em> extension.
+ </p>
+ <p>
+ If a script
+ is found, it used as a Velocity template to render the content.
+ </p>
+ <p>
+ To test this, try storing (via WebDAV, see mount point URL on the microsling homepage) the following script in your
+ repository under <em> /sling/scripts/microsling/example/html.vlt</em> .
+ Doing so will cause microsling to use that script
+ to render nodes having <em>slingResourceType=microsling/example</em>.
+ </p>
+ <p>
+ To try that rendering, use the <a href="content-creation-forms.html">content creation</a> page to create
+ and node and display it.
+ </p>
+ <p>
+ The name <em>html.vlt</em> indicates that this script is meant to process HTTP GET requests with
+ expect a <em>text/html</em> response.
+ </p>
+ <p>
+ For other HTTP methods the script would have the method name,
+ for example POST.vlt for a POST. But
+ GET is probably the only request method that makes sense to process with Velocity templates.
+ </p>
+ <p>
+ To generate XML instead, rename the script to <em>xml.vlt</em>, modify it to generate
+ the XML of your choice, and replace <em>.html</em> with <em>.xml</em> at the end of the request URL.
+ </p>
+ <p>
+ Here's the example HTML template. See the <a href="http://velocity.apache.org">Velocity website</a> for
+ more info about the syntax.
+ <pre><html>
+<body>
+<h1>This is generated from a Velocity template</h1>
+<p>
+ The current resource URI is <b>$resource.URI</b>
+</p>
+
+<h2>$resource.getItem().getProperty("title").getString()</h2>
+<p>
+ $resource.getItem().getProperty("text").getString()
+</p>
+
+</body>
+</html></pre> </p>
+ <p>
+ To deactivate the Velocity-based rendering of nodes, rename or delete the corresponding rendering
+ scripts.
+ </p>
+</body>
+</html>
\ No newline at end of file
Propchange: incubator/sling/trunk/microsling/microsling-core/src/main/webapp/velocity-scripts.html
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/CreateNodeTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/CreateNodeTest.java?rev=590999&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/CreateNodeTest.java (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/CreateNodeTest.java Thu Nov 1 06:30:00 2007
@@ -0,0 +1,52 @@
+/*
+ * 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;
+
+import org.apache.commons.httpclient.methods.GetMethod;
+
+/** Test creating a Node using the MicroslingIntegrationTestClient */
+public class CreateNodeTest extends MicroslingHttpTestBase {
+
+ public void testCreateNode() throws IOException {
+ final String url = HTTP_BASE_URL + TEST_PATH + ".sling";
+
+ // add some properties to the node
+ final Map<String,String> props = new HashMap<String,String>();
+ props.put("name1","value1");
+ props.put("name2","value2");
+
+ // POST and get URL of created node
+ String urlOfNewNode = null;
+ try {
+ urlOfNewNode = testClient.createNode(url, props);
+ } catch(IOException ioe) {
+ fail("createNode failed: " + ioe);
+ }
+
+ // get and check URL of created node
+ final GetMethod get = new GetMethod(urlOfNewNode);
+ final int status = httpClient.executeMethod(get);
+ assertEquals(urlOfNewNode + " must be accessible after createNode",200,status);
+ final String responseBodyStr = get.getResponseBodyAsString();
+ assertTrue(responseBodyStr.contains("value1"));
+ assertTrue(responseBodyStr.contains("value2"));
+ }
+}
\ No newline at end of file
Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/CreateNodeTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/FileUploadTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/FileUploadTest.java?rev=590999&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/FileUploadTest.java (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/FileUploadTest.java Thu Nov 1 06:30:00 2007
@@ -0,0 +1,52 @@
+/*
+ * 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;
+
+/** Test uploading files to the microsling repository
+ * via WebDAV, as a first step towards testing the
+ * complete content creation and rendering scenario.
+ */
+public class FileUploadTest extends MicroslingHttpTestBase {
+
+ /** This only tests the WebDAV interface. We know it works, so
+ * we're mostly testing our test code here ;-)
+ */
+ public void testUploadAndDelete() throws IOException {
+ final String testFile = "/integration-test/testfile.txt";
+ final InputStream data = getClass().getResourceAsStream(testFile);
+ 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();
+ }
+ }
+ }
+}
Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/FileUploadTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/HttpPingTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/HttpPingTest.java?rev=590999&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/HttpPingTest.java (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/HttpPingTest.java Thu Nov 1 06:30:00 2007
@@ -0,0 +1,34 @@
+/*
+ * 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;
+
+
+/** Ping the microsling server to verify that our integration test
+ * setup is ok (SLING-82).
+ */
+public class HttpPingTest extends MicroslingHttpTestBase {
+ public void testWebServerRoot() throws Exception
+ {
+ assertHttpStatus(HTTP_BASE_URL + "/", 200);
+ }
+
+ public void test404() throws Exception
+ {
+ assertHttpStatus(HTTP_BASE_URL + "/someNonExistentUrl", 404);
+ }
+
+}
\ No newline at end of file
Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/HttpPingTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/MicroslingHttpTestBase.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/MicroslingHttpTestBase.java?rev=590999&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/MicroslingHttpTestBase.java (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/MicroslingHttpTestBase.java Thu Nov 1 06:30:00 2007
@@ -0,0 +1,85 @@
+/*
+ * 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.net.MalformedURLException;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.httpclient.Credentials;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.commons.httpclient.auth.AuthScope;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.sling.microsling.integration.helpers.MicroslingIntegrationTestClient;
+
+/** Base class for HTTP-based microsling integration tests */
+class MicroslingHttpTestBase extends TestCase {
+ public static final String HTTP_BASE_URL = System.getProperty("microsling.http.server.url");
+ public static final String WEBDAV_BASE_URL = System.getProperty("microsling.webdav.server.url");
+
+ /** 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;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ // assume http and webdav are on the same host + port
+ URL url = null;
+ try {
+ url = new URL(HTTP_BASE_URL);
+ } catch(MalformedURLException mfe) {
+ // MalformedURLException doesn't tell us the URL by default
+ throw new IOException("MalformedURLException: " + HTTP_BASE_URL);
+ }
+
+ // setup HTTP client, with authentication (using default Jackrabbit credentials)
+ httpClient = new HttpClient();
+ httpClient.getParams().setAuthenticationPreemptive(true);
+ Credentials defaultcreds = new UsernamePasswordCredentials("admin", "admin");
+ httpClient.getState().setCredentials(new AuthScope(url.getHost(), url.getPort(), AuthScope.ANY_REALM), defaultcreds);
+
+ testClient = new MicroslingIntegrationTestClient(httpClient);
+ }
+
+ /** Verify that given URL returns expectedStatusCode
+ * @throws IOException */
+ protected void assertHttpStatus(String urlString, int expectedStatusCode, String assertMessage) throws IOException {
+ final int status = httpClient.executeMethod(new GetMethod(urlString));
+ if(assertMessage == null) {
+ assertEquals(expectedStatusCode, status);
+ } else {
+ assertEquals(assertMessage, expectedStatusCode, status);
+ }
+ }
+
+ /** Verify that given URL returns expectedStatusCode
+ * @throws IOException */
+ protected void assertHttpStatus(String urlString, int expectedStatusCode) throws IOException {
+ assertHttpStatus(urlString, expectedStatusCode, null);
+ }
+}
\ No newline at end of file
Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/MicroslingHttpTestBase.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/MkdirTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/MkdirTest.java?rev=590999&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/MkdirTest.java (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/MkdirTest.java Thu Nov 1 06:30:00 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;
+
+/** Test the MicroslingIntegrationTestClient's mkdir functions */
+public class MkdirTest extends MicroslingHttpTestBase {
+
+ /** Try creating a directory via WebDAV */
+ public void testMkdir() throws IOException {
+ final String testDirUrl = WEBDAV_BASE_URL + TEST_PATH + System.currentTimeMillis();
+
+ assertHttpStatus(testDirUrl, 404, testDirUrl);
+
+ try {
+ testClient.mkdir(testDirUrl);
+ } catch(IOException ioe) {
+ fail(ioe.getMessage());
+ }
+
+ assertHttpStatus(testDirUrl, 200, testDirUrl);
+
+ try {
+ testClient.mkdir(testDirUrl);
+ } catch(IOException ioe) {
+ fail("mkdir must succeed on an existing directory, got IOException:" + ioe);
+ }
+
+ assertHttpStatus(testDirUrl, 200, testDirUrl);
+
+ testClient.delete(testDirUrl);
+ assertHttpStatus(testDirUrl, 404, testDirUrl + " must be gone after DELETE");
+ }
+
+ /** Try creating a deep directory structure */
+ public void testMkdirDeep() throws IOException {
+ final String path = TEST_PATH + "/mkdir-test-" + System.currentTimeMillis() + "/something";
+ final String url = WEBDAV_BASE_URL + path;
+ assertHttpStatus(url,404,url + " must not exist before test");
+ try {
+ testClient.mkdirs(WEBDAV_BASE_URL, path);
+ } catch(IOException ioe) {
+ fail("mkdirs failed:" + ioe);
+ }
+ assertHttpStatus(url,200,url + " must exist after test");
+ }
+}
Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/MkdirTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/NodetypeRenderingTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/NodetypeRenderingTest.java?rev=590999&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/NodetypeRenderingTest.java (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/NodetypeRenderingTest.java Thu Nov 1 06:30:00 2007
@@ -0,0 +1,117 @@
+/*
+ * 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);
+ }
+ }
+
+ public void testFtlHtml() throws IOException {
+ final String toDelete = uploadTestScript("rendering-test.ftl","html.ftl");
+ try {
+ final String content = getContent(displayUrl + ".html", CONTENT_TYPE_HTML);
+ assertTrue("Content includes FreeMarker marker",content.contains("FreeMarker template"));
+ assertTrue("Content contains formatted test text",content.contains("<p><span>" + testText + "</span></p>"));
+ } finally {
+ testClient.delete(toDelete);
+ }
+ }
+}
\ No newline at end of file
Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/NodetypeRenderingTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/RenderingTestBase.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/RenderingTestBase.java?rev=590999&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/RenderingTestBase.java (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/RenderingTestBase.java Thu Nov 1 06:30:00 2007
@@ -0,0 +1,76 @@
+/*
+ * 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.Header;
+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 {
+ System.out.println();
+ System.out.println();
+ System.out.println("Path " + testFile);
+ System.out.println("Loader " + getClass().getClassLoader());
+ System.out.println("Uploading " + data);
+ System.out.println();
+ System.out.println();
+ 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);
+ final Header h = get.getResponseHeader("Content-Type");
+ if(expectedContentType == null) {
+ if(h!=null) {
+ fail("Expected null Content-Type, got " + h.getValue());
+ }
+ } else {
+ assertTrue(
+ "Expected Content-Type '" + expectedContentType + "' for " + url,
+ h.getValue().startsWith(expectedContentType)
+ );
+ }
+ return get.getResponseBodyAsString();
+ }
+
+}
\ No newline at end of file
Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/RenderingTestBase.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/SlingResourceTypeRenderingTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/SlingResourceTypeRenderingTest.java?rev=590999&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/SlingResourceTypeRenderingTest.java (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/SlingResourceTypeRenderingTest.java Thu Nov 1 06:30:00 2007
@@ -0,0 +1,121 @@
+/*
+ * 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);
+ }
+ }
+
+ public void testFtlHtml() throws IOException {
+ final String toDelete = uploadTestScript("rendering-test.ftl","html.ftl");
+ try {
+ final String content = getContent(displayUrl + ".html", CONTENT_TYPE_HTML);
+ assertTrue("Content includes FreeMarker marker",content.contains("FreeMarker template"));
+ assertTrue("Content contains formatted test text",content.contains("<p><span>" + testText + "</span></p>"));
+ } finally {
+ testClient.delete(toDelete);
+ }
+ }
+}
\ No newline at end of file
Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/SlingResourceTypeRenderingTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/StreamServletTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/StreamServletTest.java?rev=590999&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/StreamServletTest.java (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/StreamServletTest.java Thu Nov 1 06:30:00 2007
@@ -0,0 +1,64 @@
+/*
+ * 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;
+
+
+/** Test the StreamServlet by reading an uploaded file with a GET
+ */
+public class StreamServletTest extends RenderingTestBase {
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ scriptPath = TEST_PATH + "/StreamServletTest." + System.currentTimeMillis();
+ displayUrl = HTTP_BASE_URL + scriptPath;
+ testClient.mkdirs(WEBDAV_BASE_URL, scriptPath);
+ }
+
+ public void testPlainTextFile() throws Exception {
+ final String filename = "testfile.txt";
+ final String toDelete = uploadTestScript(filename,filename);
+ try {
+ final String url = displayUrl + "/" + filename;
+ // TODO why don't we get a content-type here?
+ final String content = getContent(url, null);
+ assertTrue(
+ "Content at " + url + " must include expected marker, got " + content,
+ content.contains("This is just some text in an ASCII file.")
+ );
+ } finally {
+ // TODO testClient.delete(toDelete);
+ }
+ }
+
+ public void testHtmlTextFile() throws Exception {
+ final String filename = "testfile.html";
+ final String toDelete = uploadTestScript(filename,filename);
+ try {
+ // TODO this should really be text/html, not sure why it is not
+ final String url = displayUrl + "/" + filename;
+ // TODO why don't we get a content-type here?
+ final String content = getContent(url, null);
+ assertTrue(
+ "Content at " + url + " must include expected marker, got " + content,
+ content.contains("This is <em>testfile.html</em>.")
+ );
+ } finally {
+ // TODO testClient.delete(toDelete);
+ }
+ }
+}
Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/StreamServletTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/helpers/HttpAnyMethod.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/helpers/HttpAnyMethod.java?rev=590999&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/helpers/HttpAnyMethod.java (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/helpers/HttpAnyMethod.java Thu Nov 1 06:30:00 2007
@@ -0,0 +1,34 @@
+/*
+ * 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.helpers;
+
+import org.apache.commons.httpclient.HttpMethodBase;
+
+/** Allows any HTTP method for HtttpClient */
+public class HttpAnyMethod extends HttpMethodBase {
+ private final String methodName;
+
+ public HttpAnyMethod(String methodName, String uri) {
+ super(uri);
+ this.methodName = methodName;
+ }
+
+ @Override
+ public String getName() {
+ return methodName;
+ }
+}
Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/helpers/HttpAnyMethod.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/helpers/MicroslingIntegrationTestClient.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/helpers/MicroslingIntegrationTestClient.java?rev=590999&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/helpers/MicroslingIntegrationTestClient.java (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/helpers/MicroslingIntegrationTestClient.java Thu Nov 1 06:30:00 2007
@@ -0,0 +1,112 @@
+/*
+ * 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.helpers;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.DeleteMethod;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.PutMethod;
+
+/** Client functions to interact with microsling in integration tests */
+public class MicroslingIntegrationTestClient {
+ private final HttpClient httpClient;
+
+ public MicroslingIntegrationTestClient(HttpClient client) {
+ this.httpClient = client;
+ }
+
+ /** Upload a file to the microsling repository
+ * @return the HTTP status code
+ */
+ public int upload(String toUrl, InputStream is) throws IOException {
+ final PutMethod put = new PutMethod(toUrl);
+ put.setRequestEntity(new InputStreamRequestEntity(is));
+ return httpClient.executeMethod(put);
+ }
+
+ /** Delete a file from the microsling repository
+ * @return the HTTP status code
+ */
+ public int delete(String url) throws IOException {
+ final DeleteMethod delete = new DeleteMethod(url);
+ return httpClient.executeMethod(delete);
+ }
+
+ /** Create the given directory via WebDAV, if needed, under given URL */
+ public void mkdir(String url) throws IOException {
+ int status = 0;
+ status = httpClient.executeMethod(new GetMethod(url));
+ if(status != 200) {
+ status = httpClient.executeMethod(new HttpAnyMethod("MKCOL",url));
+ if(status!=201) {
+ throw new IOException("mkdir(" + url + ") failed, status code=" + status);
+ }
+ }
+ }
+
+ /** Create the given directory via WebDAV, including parent directories */
+ public void mkdirs(String baseUrl,String path) throws IOException {
+ final String [] paths = path.split("/");
+ if(baseUrl.endsWith("/")) {
+ baseUrl = baseUrl.substring(0,baseUrl.length() - 1);
+ }
+
+ String currentPath = baseUrl;
+ for(String pathElement : paths) {
+ if(pathElement.length() == 0) {
+ continue;
+ }
+ currentPath += "/" + pathElement;
+ mkdir(currentPath);
+ }
+
+ final String url = baseUrl + path;
+ final int status = httpClient.executeMethod(new GetMethod(url));
+ if(status!=200) {
+ throw new IOException("Expected status 200, got " + status + " for URL=" + url);
+ }
+ }
+
+ /** Create a node under given path, using a POST to microsling
+ * @param url must end with ".sling" to use the microsling's default
+ * servlet POST behaviour.
+ * @return the URL that microsling provides to display the node
+ */
+ public String createNode(String url, Map<String,String> nodeProperties) throws IOException {
+ final PostMethod post = new PostMethod(url);
+ post.setFollowRedirects(false);
+
+ if(nodeProperties!=null) {
+ for(Map.Entry<String,String> e : nodeProperties.entrySet()) {
+ post.addParameter(e.getKey(),e.getValue());
+ }
+ }
+
+ final int status = httpClient.executeMethod(post);
+ if(status!=302) {
+ throw new IOException("Expected status code 302 for POST, got " + status + ", URL=" + url);
+ }
+ final String location = post.getResponseHeader("Location").getValue();
+ return location;
+ }
+}
Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/helpers/MicroslingIntegrationTestClient.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/package.html
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/package.html?rev=590999&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/package.html (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/package.html Thu Nov 1 06:30:00 2007
@@ -0,0 +1,20 @@
+<html>
+<body>
+ <p>
+ 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.
+ </p>
+ <p>
+ To debug the integration tests, however, it is useful to run
+ them as part of the normal test phase, after starting a separate
+ microsling instance that they can talk to.
+ </p>
+ <p>
+ This is implemented using Maven profiles: to run the integration
+ tests during the normal test phase, disable the "disableIntegrationTestsInTestPhase"
+ Maven profile, for example using <code>mvn -P nullMicroslingProfile test</code>.
+ See pom.xml for more details.
+ </p>
+</body>
+</html>
\ No newline at end of file
Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/package.html
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/request/helpers/MicroslingRequestPathInfoTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/request/helpers/MicroslingRequestPathInfoTest.java?rev=590999&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/request/helpers/MicroslingRequestPathInfoTest.java (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/request/helpers/MicroslingRequestPathInfoTest.java Thu Nov 1 06:30:00 2007
@@ -0,0 +1,202 @@
+/*
+ * 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.request.helpers;
+
+import java.util.HashMap;
+
+import junit.framework.TestCase;
+
+import org.apache.sling.api.request.RequestPathInfo;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceMetadata;
+
+/** Test the MicroslingRequestPathInfo */
+public class MicroslingRequestPathInfoTest extends TestCase {
+
+ public void testSimplePath() {
+ RequestPathInfo p = new MicroslingRequestPathInfo(
+ new MockResource("/"), "/some/path.print.a4.html/some/suffix");
+ assertEquals("/", p.getResourcePath());
+ assertEquals("", p.getSelectorString());
+ assertEquals("", p.getExtension());
+ assertEquals("/some/path.print.a4.html/some/suffix", p.getSuffix());
+ }
+
+ public void testNullResource() {
+ try {
+ new MicroslingRequestPathInfo(null, "dontcare");
+ fail("Expected NullPointerException");
+ } catch (NullPointerException npe) {
+ // required for a null resource
+ }
+ }
+
+ public void testSimpleSuffix() {
+ RequestPathInfo p = new MicroslingRequestPathInfo(
+ new MockResource("/"), "/some/path.print.a4.html/some/suffix");
+ assertEquals("/", p.getResourcePath());
+ assertEquals("", p.getSelectorString());
+ assertEquals("", p.getExtension());
+ assertEquals("/some/path.print.a4.html/some/suffix", p.getSuffix());
+ }
+
+ public void testAllOptions() {
+ RequestPathInfo p = new MicroslingRequestPathInfo(
+ new MockResource("/some/path"), "/some/path.print.a4.html/some/suffix");
+ assertEquals("/some/path", p.getResourcePath());
+ assertEquals("print.a4", p.getSelectorString());
+ assertEquals("html", p.getExtension());
+ assertEquals("/some/suffix", p.getSuffix());
+ }
+
+ public void testAllEmpty() {
+ RequestPathInfo p = new MicroslingRequestPathInfo(
+ new MockResource("/"), null);
+ assertEquals("/", p.getResourcePath());
+ assertEquals("", p.getSelectorString());
+ assertEquals("", p.getExtension());
+ assertEquals("", p.getSuffix());
+ }
+
+ public void testPathOnly() {
+ RequestPathInfo p = new MicroslingRequestPathInfo(new MockResource(
+ "/some/path/here"), "/some/path/here");
+ assertEquals("/some/path/here", p.getResourcePath());
+ assertEquals("", p.getSelectorString());
+ assertEquals("", p.getExtension());
+ assertEquals("", p.getSuffix());
+ }
+
+ public void testPathAndExtensionOnly() {
+ RequestPathInfo p = new MicroslingRequestPathInfo(new MockResource(
+ "/some/path/here"), "/some/path/here.html");
+ assertEquals("/some/path/here", p.getResourcePath());
+ assertEquals("", p.getSelectorString());
+ assertEquals("html", p.getExtension());
+ assertEquals("", p.getSuffix());
+ }
+
+ public void testPathAndOneSelectorOnly() {
+ RequestPathInfo p = new MicroslingRequestPathInfo(new MockResource(
+ "/some/path/here"), "/some/path/here.print.html");
+ assertEquals("/some/path/here", p.getResourcePath());
+ assertEquals("print", p.getSelectorString());
+ assertEquals("html", p.getExtension());
+ assertEquals("", p.getSuffix());
+ }
+
+ public void testPathExtAndSuffix() {
+ RequestPathInfo p = new MicroslingRequestPathInfo(new MockResource(
+ "/some/path/here"), "/some/path/here.html/something");
+ assertEquals("/some/path/here", p.getResourcePath());
+ assertEquals("", p.getSelectorString());
+ assertEquals("html", p.getExtension());
+ assertEquals("/something", p.getSuffix());
+ }
+
+ public void testSelectorsSplit() {
+ RequestPathInfo p = new MicroslingRequestPathInfo(new MockResource(
+ "/some/path"), "/some/path.print.a4.html/some/suffix");
+ assertEquals("/some/path", p.getResourcePath());
+ assertEquals(2, p.getSelectors().length);
+ assertEquals("print", p.getSelectors()[0]);
+ assertEquals("a4", p.getSelectors()[1]);
+ assertEquals("html", p.getExtension());
+ assertEquals("/some/suffix", p.getSuffix());
+ }
+
+ public void testPartialResolutionA() {
+ RequestPathInfo p = new MicroslingRequestPathInfo(new MockResource(
+ "/some"), "/some/path.print.a4.html/some/suffix");
+ assertEquals("/some", p.getResourcePath());
+ assertEquals("", p.getSelectorString());
+ assertEquals("", p.getExtension());
+ assertEquals("/path.print.a4.html/some/suffix", p.getSuffix());
+ }
+
+ public void testPartialResolutionB() {
+ RequestPathInfo p = new MicroslingRequestPathInfo(new MockResource(
+ "/some/path"), "/some/path.print.a4.html/some/suffix");
+ assertEquals("/some/path", p.getResourcePath());
+ assertEquals("print.a4", p.getSelectorString());
+ assertEquals("html", p.getExtension());
+ assertEquals("/some/suffix", p.getSuffix());
+ }
+
+ public void testPartialResolutionC() {
+ RequestPathInfo p = new MicroslingRequestPathInfo(new MockResource(
+ "/some/path.print"), "/some/path.print.a4.html/some/suffix");
+ assertEquals("/some/path.print", p.getResourcePath());
+ assertEquals("a4", p.getSelectorString());
+ assertEquals("html", p.getExtension());
+ assertEquals("/some/suffix", p.getSuffix());
+ }
+
+ public void testPartialResolutionD() {
+ RequestPathInfo p = new MicroslingRequestPathInfo(new MockResource(
+ "/some/path.print.a4"), "/some/path.print.a4.html/some/suffix");
+ assertEquals("/some/path.print.a4", p.getResourcePath());
+ assertEquals("", p.getSelectorString());
+ assertEquals("html", p.getExtension());
+ assertEquals("/some/suffix", p.getSuffix());
+ }
+
+ public void testPartialResolutionE() {
+ RequestPathInfo p = new MicroslingRequestPathInfo(new MockResource(
+ "/some/path.print.a4.html"), "/some/path.print.a4.html/some/suffix");
+ assertEquals("/some/path.print.a4.html", p.getResourcePath());
+ assertEquals("", p.getSelectorString());
+ assertEquals("", p.getExtension());
+ assertEquals("/some/suffix", p.getSuffix());
+ }
+
+ static class MockResource implements Resource {
+
+ private final ResourceMetadata metadata;
+
+ MockResource(String resolutionPath) {
+ metadata = new MockResourceMetadata();
+ metadata.put(ResourceMetadata.RESOLUTION_PATH, resolutionPath);
+ }
+
+ public Object getObject() {
+ throw new Error("MockResource does not implement this method");
+ }
+
+ public Object getRawData() {
+ throw new Error("MockResource does not implement this method");
+ }
+
+ public String getResourceType() {
+ throw new Error("MockResource does not implement this method");
+ }
+
+ public String getURI() {
+ throw new Error("MockResource does not implement this method");
+ }
+
+ public ResourceMetadata getResourceMetadata() {
+ return metadata;
+ }
+ }
+
+ private static class MockResourceMetadata extends HashMap<String, Object>
+ implements ResourceMetadata {
+
+ }
+
+}
Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/request/helpers/MicroslingRequestPathInfoTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/resource/ResourcePathIteratorTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/resource/ResourcePathIteratorTest.java?rev=590999&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/resource/ResourcePathIteratorTest.java (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/resource/ResourcePathIteratorTest.java Thu Nov 1 06:30:00 2007
@@ -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.microsling.resource;
+
+import java.util.Iterator;
+
+import junit.framework.TestCase;
+
+/** Test the ResourcePathIterator class */
+
+public class ResourcePathIteratorTest extends TestCase {
+
+ public void testNullInput() {
+ final Iterator<String> it = new ResourcePathIterator(null);
+ assertFalse(it.hasNext());
+ }
+
+ public void testEmptyInput() {
+ final Iterator<String> it = new ResourcePathIterator("");
+ assertFalse(it.hasNext());
+ }
+
+ public void testNoSeparators() {
+ final Iterator<String> it = new ResourcePathIterator("MickeyMouseWasHere");
+ assertTrue(it.hasNext());
+ assertEquals("MickeyMouseWasHere",it.next());
+ assertFalse(it.hasNext());
+ }
+
+ public void testSlashOnly() {
+ final Iterator<String> it = new ResourcePathIterator("/MickeyMouseWasHere/ok");
+ assertTrue(it.hasNext());
+ assertEquals("/MickeyMouseWasHere/ok",it.next());
+ assertTrue(it.hasNext());
+ assertEquals("/MickeyMouseWasHere",it.next());
+ assertFalse(it.hasNext());
+ }
+
+ public void testDotOnly() {
+ final Iterator<String> it = new ResourcePathIterator("MickeyMouseWasHere.ok");
+ assertTrue(it.hasNext());
+ assertEquals("MickeyMouseWasHere.ok",it.next());
+ assertTrue(it.hasNext());
+ assertEquals("MickeyMouseWasHere",it.next());
+ assertFalse(it.hasNext());
+ }
+
+ public void testRealisticPath() {
+ final Iterator<String> it = new ResourcePathIterator("/some/stuff.print.a4/more");
+ assertTrue(it.hasNext());
+ assertEquals("/some/stuff.print.a4/more",it.next());
+ assertTrue(it.hasNext());
+ assertEquals("/some/stuff.print.a4",it.next());
+ assertTrue(it.hasNext());
+ assertEquals("/some/stuff.print",it.next());
+ assertTrue(it.hasNext());
+ assertEquals("/some/stuff",it.next());
+ assertTrue(it.hasNext());
+ assertEquals("/some",it.next());
+ assertFalse(it.hasNext());
+ }
+
+ public void testRelativePath() {
+ final Iterator<String> it = new ResourcePathIterator("some/stuff.print");
+ assertTrue(it.hasNext());
+ assertEquals("some/stuff.print",it.next());
+ assertTrue(it.hasNext());
+ assertEquals("some/stuff",it.next());
+ assertTrue(it.hasNext());
+ assertEquals("some",it.next());
+ assertFalse(it.hasNext());
+ }
+}
Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/resource/ResourcePathIteratorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/scripting/helpers/EspReaderTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/scripting/helpers/EspReaderTest.java?rev=590999&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/scripting/helpers/EspReaderTest.java (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/scripting/helpers/EspReaderTest.java Thu Nov 1 06:30:00 2007
@@ -0,0 +1,119 @@
+/*
+ * $Url: $
+ * $Id: $
+ *
+ * Copyright 1997-2005 Day Management AG
+ * Barfuesserplatz 6, 4001 Basel, Switzerland
+ * All Rights Reserved.
+ *
+ * This software is the confidential and proprietary information of
+ * Day Management AG, ("Confidential Information"). You shall not
+ * disclose such Confidential Information and shall use it only in
+ * accordance with the terms of the license agreement you entered into
+ * with Day.
+ */
+package org.apache.sling.microsling.scripting.helpers;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
+
+import junit.framework.TestCase;
+
+import org.apache.sling.microsling.scripting.helpers.EspReader;
+
+/**
+ * The <code>EspReaderTest</code> contains some simple test cases for the
+ * <code>EspReader</code> class which processes ESP (ECMA Server Page) templated
+ * JavaScript and produces plain JavaScript.
+ */
+public class EspReaderTest extends TestCase {
+
+ /** Test read() method */
+ public void testReadSingle() throws IOException {
+ String src = "<%var%>"; // expect var on reader
+
+ Reader reader = new EspReader(new StringReader(src));
+
+ assertTrue("Character 1 must be 'v'", 'v' == reader.read());
+ assertTrue("Character 2 must be 'a'", 'a' == reader.read());
+ assertTrue("Character 3 must be 'r'", 'r' == reader.read());
+ assertTrue("Character 4 must be -1", -1 == reader.read());
+ }
+
+ /** Test read(char[], int, int) method */
+ public void testReadArrayAll() throws IOException {
+ String src = "<%var%>"; // expect var on reader
+
+ Reader reader = new EspReader(new StringReader(src));
+ char[] buf = new char[3];
+ int rd = reader.read(buf, 0, buf.length);
+
+ assertEquals(3, rd);
+ assertEquals("var", new String(buf, 0, rd));
+
+ // nothing more to read, expect EOF
+ rd = reader.read(buf, 0, buf.length);
+ assertEquals(-1, rd);
+ }
+
+ /** Test read(char[], int, int) method */
+ public void testReadArrayOffset() throws IOException {
+ String jsSrc = "var x = 0;";
+ String src = "<%" + jsSrc + "%>";
+
+ Reader reader = new EspReader(new StringReader(src));
+ char[] buf = new char[10];
+ int off = 2;
+ int len = 3;
+ int rd = reader.read(buf, off, len);
+ assertEquals(len, rd);
+ assertEquals("var", new String(buf, off, rd));
+
+ off = 2;
+ len = 7;
+ rd = reader.read(buf, off, len);
+ assertEquals(len, rd);
+ assertEquals(" x = 0;", new String(buf, off, rd));
+
+ // nothing more to read, expect EOF
+ rd = reader.read(buf, 0, buf.length);
+ assertEquals(-1, rd);
+ }
+
+ /** Test standard template text */
+ public void testTemplate() throws IOException {
+ assertEquals("out=response.writer;out.write(\"test\");", parse("test"));
+ assertEquals("out=response.writer;out.write(\"test\\n\");\nout.write(\"test2\");", parse("test\ntest2"));
+ }
+
+ /** Test plain JavaScript code */
+ public void testCode() throws IOException {
+ assertEquals(" test(); ", parse("<% test(); %>"));
+ assertEquals(" \ntest();\ntest2(); ", parse("<% \ntest();\ntest2(); %>"));
+ }
+
+ /** Test JavaScript expressions */
+ public void testExpr() throws IOException {
+ assertEquals("out=response.writer;out.write( x + 1 );", parse("<%= x + 1 %>"));
+ assertEquals("out=response.writer;out.write(\"<!-- \");out.write( x + 1 );out.write(\" -->\");", parse("<!-- <%= x + 1 %> -->"));
+ }
+
+ /** Test JavaScript comment */
+ public void testComment() throws IOException {
+ assertEquals("", parse("<%-- test(); --%>"));
+ }
+
+ /** Helper to pass an ESP text through the EspReader and return the result */
+ private String parse(String text) throws IOException {
+ StringBuffer buf = new StringBuffer();
+
+ Reader r = new EspReader(new StringReader(text));
+ int c;
+ while ( (c=r.read()) >= 0) {
+ buf.append( (char) c);
+ }
+
+ return buf.toString();
+ }
+}
Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/scripting/helpers/EspReaderTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/scripting/helpers/ScriptFilenameBuilderTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/scripting/helpers/ScriptFilenameBuilderTest.java?rev=590999&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/scripting/helpers/ScriptFilenameBuilderTest.java (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/scripting/helpers/ScriptFilenameBuilderTest.java Thu Nov 1 06:30:00 2007
@@ -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.microsling.scripting.helpers;
+
+import junit.framework.TestCase;
+
+/** Test the ScriptFilenameBuilder */
+public class ScriptFilenameBuilderTest extends TestCase {
+
+ private ScriptFilenameBuilder builder;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ builder = new ScriptFilenameBuilder();
+ }
+
+ public void testNull() {
+ assertEquals("NO_METHOD.NO_EXT",builder.buildScriptFilename(null,null,null,null));
+ }
+
+ public void testSimpleGet() {
+ assertEquals("html.js",builder.buildScriptFilename("GET",null,"text/html","js"));
+ }
+
+ public void testGetAndNulls() {
+ assertEquals("NO_CONTENT_TYPE.NO_EXT",builder.buildScriptFilename("GET",null,null,null));
+ }
+
+ public void testSimpleHead() {
+ assertEquals("HEAD.js",builder.buildScriptFilename("HEAD",null,"text/html","js"));
+ }
+
+ public void testGetOneSelector() {
+ assertEquals("print/html.js",builder.buildScriptFilename("GET","print","text/html","js"));
+ }
+
+ public void testGetTwoSelectors() {
+ assertEquals("print/a4/xml.vlt",builder.buildScriptFilename("GET","print.a4","text/xml","vlt"));
+ }
+
+ public void testSimplePost() {
+ assertEquals("POST.js",builder.buildScriptFilename("POST",null,"text/html","js"));
+ }
+
+ public void testSimplePut() {
+ assertEquals("PUT.js",builder.buildScriptFilename("PUT",null,"text/html","js"));
+ }
+
+ public void testSimpleDelete() {
+ assertEquals("DELETE.js",builder.buildScriptFilename("DELETE",null,"text/html","js"));
+ }
+
+ public void testGetTextMimeType() {
+ assertEquals("plain.js",builder.buildScriptFilename("GET",null,"text/plain","js"));
+ }
+
+ public void testGetWhateverMimeType() {
+ assertEquals("foo.js",builder.buildScriptFilename("GET",null,"whatever/Foo","js"));
+ }
+
+ public void testGetNoSlashMimeType() {
+ assertEquals("bar.js",builder.buildScriptFilename("GET",null,"bar","js"));
+ }
+
+ public void testCaseCleanupOne() {
+ assertEquals("POST.js",builder.buildScriptFilename("posT",null,"text/html","jS"));
+ }
+
+ public void testCaseCleanupTwo() {
+ assertEquals("html.js",builder.buildScriptFilename("get",null,"text/HTML","JS"));
+ }
+
+ public void testCaseCleanupThree() {
+ assertEquals("print/a4/html.js",builder.buildScriptFilename("get","PRInT.A4","text/HTML","JS"));
+ }
+}
Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/scripting/helpers/ScriptFilenameBuilderTest.java
------------------------------------------------------------------------------
svn:eol-style = native