You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2008/01/15 13:56:32 UTC
svn commit: r612110 - in /incubator/sling/trunk/usling/usling-webapp: ./
src/test/java/org/apache/sling/usling/webapp/integrationtest/
src/test/java/org/apache/sling/usling/webapp/integrationtest/helpers/
Author: bdelacretaz
Date: Tue Jan 15 04:56:29 2008
New Revision: 612110
URL: http://svn.apache.org/viewvc?rev=612110&view=rev
Log:
SLING-149 - merge usling into Sling - CreateNodeTest passes, with both multipart and x-www-form-urlencoded POST requests
Added:
incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/CreateNodeTest.java (with props)
Modified:
incubator/sling/trunk/usling/usling-webapp/pom.xml
incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/UslingHttpTestBase.java
incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/helpers/UslingIntegrationTestClient.java
Modified: incubator/sling/trunk/usling/usling-webapp/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/usling/usling-webapp/pom.xml?rev=612110&r1=612109&r2=612110&view=diff
==============================================================================
--- incubator/sling/trunk/usling/usling-webapp/pom.xml (original)
+++ incubator/sling/trunk/usling/usling-webapp/pom.xml Tue Jan 15 04:56:29 2008
@@ -252,11 +252,11 @@
-->
<property>
<name>usling.http.server.url</name>
- <value>http://localhost:8080/usling-webapp-2.0.0-incubator-SNAPSHOT</value>
+ <value>http://localhost:8080/${project.build.finalName}</value>
</property>
<property>
<name>usling.webdav.server.url</name>
- <value>http://localhost:8080/usling-webapp-2.0.0-incubator-SNAPSHOT/repository/default</value>
+ <value>http://localhost:8080/${project.build.finalName}/repository/default</value>
</property>
</systemProperties>
</configuration>
Added: incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/CreateNodeTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/CreateNodeTest.java?rev=612110&view=auto
==============================================================================
--- incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/CreateNodeTest.java (added)
+++ incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/CreateNodeTest.java Tue Jan 15 04:56:29 2008
@@ -0,0 +1,88 @@
+/*
+ * 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.usling.webapp.integrationtest;
+
+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 UslingHttpTestBase {
+
+ public void testCreateNode() throws IOException {
+ final String url = HTTP_BASE_URL + "/CreateNodeTest_1_" + System.currentTimeMillis();
+
+ // 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"));
+
+ // test default txt and html renderings
+ getContent(urlOfNewNode, CONTENT_TYPE_PLAIN);
+ getContent(urlOfNewNode + ".txt", CONTENT_TYPE_PLAIN);
+ getContent(urlOfNewNode + ".html", CONTENT_TYPE_HTML);
+ getContent(urlOfNewNode + ".json", CONTENT_TYPE_JSON);
+
+ // And extensions for which we have no renderer fail
+ assertHttpStatus(urlOfNewNode + ".xml", 500);
+ assertHttpStatus(urlOfNewNode + ".pdf", 500);
+ assertHttpStatus(urlOfNewNode + ".someWeirdExtension", 500);
+ }
+
+ public void testCreateNodeMultipart() throws IOException {
+ final String url = HTTP_BASE_URL + "/CreateNodeTest_2_" + System.currentTimeMillis();
+
+ // add some properties to the node
+ final Map<String,String> props = new HashMap<String,String>();
+ props.put("name1","value1B");
+ props.put("name2","value2B");
+
+ // POST and get URL of created node
+ String urlOfNewNode = null;
+ try {
+ urlOfNewNode = testClient.createNode(url, props, null, true);
+ } catch(IOException ioe) {
+ fail("createNode failed: " + ioe);
+ }
+
+ // check node contents (not all renderings - those are tested above)
+ 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("value1B"));
+ assertTrue(responseBodyStr.contains("value2B"));
+ }
+}
\ No newline at end of file
Propchange: incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/CreateNodeTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/CreateNodeTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Modified: incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/UslingHttpTestBase.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/UslingHttpTestBase.java?rev=612110&r1=612109&r2=612110&view=diff
==============================================================================
--- incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/UslingHttpTestBase.java (original)
+++ incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/UslingHttpTestBase.java Tue Jan 15 04:56:29 2008
@@ -57,6 +57,8 @@
protected UslingIntegrationTestClient testClient;
protected HttpClient httpClient;
+ private static long startupTime = System.currentTimeMillis();
+
@Override
protected void setUp() throws Exception {
super.setUp();
@@ -77,6 +79,18 @@
httpClient.getState().setCredentials(new AuthScope(url.getHost(), url.getPort(), AuthScope.ANY_REALM), defaultcreds);
testClient = new UslingIntegrationTestClient(httpClient);
+
+ waitForSlingStartup();
+ }
+
+ protected void waitForSlingStartup() throws Exception {
+ // TODO we'll need a better way to make sure integration tests
+ // wait for all bundles to be started!!!
+ final long delta = System.currentTimeMillis() - startupTime;
+ final long minWait = 5000L;
+ if(minWait > delta) {
+ Thread.sleep(minWait - delta);
+ }
}
/** Verify that given URL returns expectedStatusCode
Modified: incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/helpers/UslingIntegrationTestClient.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/helpers/UslingIntegrationTestClient.java?rev=612110&r1=612109&r2=612110&view=diff
==============================================================================
--- incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/helpers/UslingIntegrationTestClient.java (original)
+++ incubator/sling/trunk/usling/usling-webapp/src/test/java/org/apache/sling/usling/webapp/integrationtest/helpers/UslingIntegrationTestClient.java Tue Jan 15 04:56:29 2008
@@ -26,6 +26,9 @@
import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.PutMethod;
+import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
+import org.apache.commons.httpclient.methods.multipart.Part;
+import org.apache.commons.httpclient.methods.multipart.StringPart;
/** Client functions to interact with microsling in integration tests */
public class UslingIntegrationTestClient {
@@ -89,21 +92,31 @@
/** Call the other createNode method with headers==null */
public String createNode(String url, Map<String,String> nodeProperties) throws IOException {
- return createNode(url, nodeProperties, null);
+ return createNode(url, nodeProperties, null, false);
}
/** Create a node under given path, using a POST to microsling
- * @param url under which node is created
+ * @param url under which node is created
+ * @param multiPart if true, does a multipart POST
* @return the URL that microsling provides to display the node
*/
- public String createNode(String url, Map<String,String> nodeProperties, Map<String,String> requestHeaders)
+ public String createNode(String url, Map<String,String> nodeProperties, Map<String,String> requestHeaders,boolean multiPart)
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());
+ if(nodeProperties != null && nodeProperties.size() > 0) {
+ if(multiPart) {
+ final Part [] parts = new Part[nodeProperties.size()];
+ int index = 0;
+ for(Map.Entry<String,String> e : nodeProperties.entrySet()) {
+ parts[index++] = new StringPart(e.getKey().toString(), e.getValue().toString());
+ }
+ post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));
+ } else {
+ for(Map.Entry<String,String> e : nodeProperties.entrySet()) {
+ post.addParameter(e.getKey(),e.getValue());
+ }
}
}