incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r588674 - in /incubator/sling/whiteboard/microsling: ./ src/main/java/org/apache/sling/microsling/slingservlets/ src/test/java/org/apache/sling/microsling/integration/ src/test/java/org/apache/sling/microsling/integration/helpers/
Date Fri, 26 Oct 2007 14:52:18 GMT
Author: bdelacretaz
Date: Fri Oct 26 07:52:17 2007
New Revision: 588674

URL: http://svn.apache.org/viewvc?rev=588674&view=rev
Log:
SLING-82 - CreateNodeTest added, POSTs a new node and verifies its unformatted content

Added:
    incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/CreateNodeTest.java
  (with props)
Modified:
    incubator/sling/whiteboard/microsling/pom.xml
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java
    incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/helpers/MicroslingIntegrationTestClient.java

Modified: incubator/sling/whiteboard/microsling/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/pom.xml?rev=588674&r1=588673&r2=588674&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/pom.xml (original)
+++ incubator/sling/whiteboard/microsling/pom.xml Fri Oct 26 07:52:17 2007
@@ -157,7 +157,7 @@
             -->
             <property>
               <name>microsling.http.server.url</name>
-              <value>http://localhost:8080/</value>
+              <value>http://localhost:8080/microsling</value>
             </property>
             <property>
               <name>microsling.webdav.server.url</name>
@@ -212,7 +212,7 @@
                     -->
                     <property>
                       <name>microsling.http.server.url</name>
-                      <value>http://localhost:8080/microsling-1.0-SNAPSHOT</value>
+                      <value>http://localhost:8080/microsling-1.0-SNAPSHOT/microsling</value>
                     </property>
                     <property>
                       <name>microsling.webdav.server.url</name>

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java?rev=588674&r1=588673&r2=588674&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java
Fri Oct 26 07:52:17 2007
@@ -117,7 +117,7 @@
         // redirect to the created node, so that it is displayed using a user-supplied extension
         String redirectExtension = req.getParameter("slingDisplayExtension");
         final String redirectUrl =
-            req.getServletPath() + redirectPath
+            req.getContextPath() + req.getServletPath() + redirectPath
             + (redirectExtension == null ? "" : "." + redirectExtension)
         ;
         resp.sendRedirect(redirectUrl);

Added: incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/CreateNodeTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/CreateNodeTest.java?rev=588674&view=auto
==============================================================================
--- incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/CreateNodeTest.java
(added)
+++ incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/CreateNodeTest.java
Fri Oct 26 07:52:17 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/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/CreateNodeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Modified: incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/helpers/MicroslingIntegrationTestClient.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/helpers/MicroslingIntegrationTestClient.java?rev=588674&r1=588673&r2=588674&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/helpers/MicroslingIntegrationTestClient.java
(original)
+++ incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/helpers/MicroslingIntegrationTestClient.java
Fri Oct 26 07:52:17 2007
@@ -18,11 +18,13 @@
 
 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 */ 
@@ -60,5 +62,28 @@
                 throw new IOException("mkdir(" + url + ") failed, status code=" + status);
             }
         }
+    }
+    
+    /** 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;
     }
 }



Mime
View raw message