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 2007/10/25 18:20:14 UTC
svn commit: r588270 - in /incubator/sling/whiteboard/microsling: ./
src/test/java/org/apache/sling/microsling/integration/
src/test/java/org/apache/sling/microsling/integration/helpers/
src/test/resources/ src/test/resources/integration-test/
Author: bdelacretaz
Date: Thu Oct 25 09:20:13 2007
New Revision: 588270
URL: http://svn.apache.org/viewvc?rev=588270&view=rev
Log:
SLING-82 - work in progress, preparing for automated content creation/rendering test
Added:
incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/FileUploadTest.java (with props)
incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/MicroslingHttpTestBase.java (with props)
incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/helpers/
incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/helpers/MicroslingIntegrationTestClient.java (with props)
incubator/sling/whiteboard/microsling/src/test/resources/
incubator/sling/whiteboard/microsling/src/test/resources/integration-test/
incubator/sling/whiteboard/microsling/src/test/resources/integration-test/testfile.txt (with props)
Modified:
incubator/sling/whiteboard/microsling/pom.xml
incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/HttpPingTest.java
Modified: incubator/sling/whiteboard/microsling/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/pom.xml?rev=588270&r1=588269&r2=588270&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/pom.xml (original)
+++ incubator/sling/whiteboard/microsling/pom.xml Thu Oct 25 09:20:13 2007
@@ -45,7 +45,7 @@
<!--
Defines which tests are for the "integration-testing" phase
-->
- <integration.test.code.pattern>**/microsling/integration/**.java</integration.test.code.pattern>
+ <integration.test.code.path>**/microsling/integration</integration.test.code.path>
<!--
Set this to true to stop mvn once the integration test Jetty instance is
@@ -92,6 +92,12 @@
<artifactId>js</artifactId>
<version>1.6R7</version>
</dependency>
+ <dependency>
+ <groupId>commons-httpclient</groupId>
+ <artifactId>commons-httpclient</artifactId>
+ <version>3.1</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
@@ -142,7 +148,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
- <exclude>${integration.test.code.pattern}</exclude>
+ <exclude>${integration.test.code.path}/**.java</exclude>
</excludes>
</configuration>
</plugin>
@@ -180,17 +186,21 @@
<exclude>none</exclude>
</excludes>
<includes>
- <include>${integration.test.code.pattern}</include>
+ <include>${integration.test.code.path}/**Test.java</include>
</includes>
<systemProperties>
+ <!--
+ WARNING: make sure these URLs are consistent with the
+ cargo-maven2-plugin settings: AFAIK Maven does not
+ expand variables in the <value> element.
+ -->
<property>
<name>microsling.http.server.url</name>
- <!--
- WARNING: make sure this URL is consistent with the
- cargo-maven2-plugin settings: AFAIK Maven does not
- expand variables in the <value> element.
- -->
<value>http://localhost:8080/microsling-1.0-SNAPSHOT</value>
+ </property>
+ <property>
+ <name>microsling.webdav.server.url</name>
+ <value>http://admin:admin@localhost:8080/microsling-1.0-SNAPSHOT/repository/default</value>
</property>
</systemProperties>
</configuration>
Added: incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/FileUploadTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/FileUploadTest.java?rev=588270&view=auto
==============================================================================
--- incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/FileUploadTest.java (added)
+++ incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/FileUploadTest.java Thu Oct 25 09:20:13 2007
@@ -0,0 +1,42 @@
+/*
+ * 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 a file to the microsling repository */
+public class FileUploadTest extends MicroslingHttpTestBase {
+
+ public void testUploadAndDelete() throws IOException {
+ final String testFile = "/integration-test/testfile.txt";
+ final InputStream data = getClass().getResourceAsStream(testFile);
+ assertNotNull("Local test file " + testFile + " must be found",data);
+
+ // TODO should not use a path at the root, but for now we have no "mkdir" client
+ final String path = "/FileUploadTest." + System.currentTimeMillis() + ".txt";
+
+ assertHttpStatus(path, 404, "File " + path + " must not exist before test");
+ int status = testClient.upload(WEBDAV_URL + path, data);
+ assertEquals("upload must return status code 201",201,status);
+
+ // TODO verify/activate these tests
+ //assertHttpStatus(path, 200, "File " + path + " must exist after upload");
+ //testClient.delete(path);
+ //assertHttpStatus(path, 404, "File " + path + " must not be found after deleting");
+ }
+}
Propchange: incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/FileUploadTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/FileUploadTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Modified: incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/HttpPingTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/HttpPingTest.java?rev=588270&r1=588269&r2=588270&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/HttpPingTest.java (original)
+++ incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/HttpPingTest.java Thu Oct 25 09:20:13 2007
@@ -16,43 +16,19 @@
*/
package org.apache.sling.microsling.integration;
-import java.net.HttpURLConnection;
-import java.net.URL;
-
-import junit.framework.TestCase;
/** Ping the microsling server to verify that our integration test
* setup is ok (SLING-82).
*/
-public class HttpPingTest extends TestCase {
- public static final String BASE_URL = System.getProperty("microsling.http.server.url");
-
+public class HttpPingTest extends MicroslingHttpTestBase {
public void testWebServerRoot() throws Exception
{
- URL url = new URL(BASE_URL + "/");
- HttpURLConnection connection = (HttpURLConnection) url.openConnection();
- try {
- connection.connect();
- assertEquals(200, connection.getResponseCode());
- } finally {
- if(connection!=null) {
- connection.disconnect();
- }
- }
+ assertHttpStatus("/", 200);
}
public void test404() throws Exception
{
- URL url = new URL(BASE_URL + "/someNonExistentUrl." + System.currentTimeMillis());
- HttpURLConnection connection = (HttpURLConnection) url.openConnection();
- try {
- connection.connect();
- assertEquals(404, connection.getResponseCode());
- } finally {
- if(connection!=null) {
- connection.disconnect();
- }
- }
+ assertHttpStatus("/someNonExistentUrl", 404);
}
}
Added: incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/MicroslingHttpTestBase.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/MicroslingHttpTestBase.java?rev=588270&view=auto
==============================================================================
--- incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/MicroslingHttpTestBase.java (added)
+++ incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/MicroslingHttpTestBase.java Thu Oct 25 09:20:13 2007
@@ -0,0 +1,59 @@
+/*
+ * 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.HttpURLConnection;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+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_URL = System.getProperty("microsling.http.server.url");
+ public static final String WEBDAV_URL = System.getProperty("microsling.webdav.server.url");
+
+ /** base path for test files */
+ public static final String TEST_PATH = "/microsling-integration-tests";
+
+ protected final MicroslingIntegrationTestClient testClient = new MicroslingIntegrationTestClient();
+
+ /** Verify that given URL path returns expectedStatusCode
+ * @throws IOException */
+ protected void assertHttpStatus(String path, int expectedStatusCode, String assertMessage) throws IOException {
+ URL url = new URL(HTTP_URL + path);
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+ try {
+ connection.connect();
+ if(assertMessage == null) {
+ assertEquals(expectedStatusCode, connection.getResponseCode());
+ } else {
+ assertEquals(assertMessage, expectedStatusCode, connection.getResponseCode());
+ }
+ } finally {
+ if(connection!=null) {
+ connection.disconnect();
+ }
+ }
+ }
+
+ protected void assertHttpStatus(String path, int expectedStatusCode) throws IOException {
+ assertHttpStatus(path, expectedStatusCode, null);
+ }
+}
\ No newline at end of file
Propchange: incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/MicroslingHttpTestBase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/MicroslingHttpTestBase.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Added: 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=588270&view=auto
==============================================================================
--- incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/helpers/MicroslingIntegrationTestClient.java (added)
+++ incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/helpers/MicroslingIntegrationTestClient.java Thu Oct 25 09:20:13 2007
@@ -0,0 +1,58 @@
+/*
+ * 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 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.DeleteMethod;
+import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
+import org.apache.commons.httpclient.methods.PutMethod;
+
+/** Client functions to interact with microsling in integration tests */
+public class MicroslingIntegrationTestClient {
+ private final HttpClient client;
+
+ public MicroslingIntegrationTestClient() {
+ client = new HttpClient();
+ client.getParams().setAuthenticationPreemptive(true);
+ Credentials defaultcreds = new UsernamePasswordCredentials("admin", "admin");
+ // TODO host/port should not be hardcoded
+ client.getState().setCredentials(new AuthScope("localhost", 8080, AuthScope.ANY_REALM), defaultcreds);
+ }
+
+ /** 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 client.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 client.executeMethod(delete);
+ }
+}
Propchange: incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/helpers/MicroslingIntegrationTestClient.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/helpers/MicroslingIntegrationTestClient.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Added: incubator/sling/whiteboard/microsling/src/test/resources/integration-test/testfile.txt
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/test/resources/integration-test/testfile.txt?rev=588270&view=auto
==============================================================================
--- incubator/sling/whiteboard/microsling/src/test/resources/integration-test/testfile.txt (added)
+++ incubator/sling/whiteboard/microsling/src/test/resources/integration-test/testfile.txt Thu Oct 25 09:20:13 2007
@@ -0,0 +1 @@
+This is hust some text in an ASCII file.
\ No newline at end of file
Propchange: incubator/sling/whiteboard/microsling/src/test/resources/integration-test/testfile.txt
------------------------------------------------------------------------------
svn:eol-style = native