incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r588577 - in /incubator/sling/whiteboard/microsling: ./ src/test/java/org/apache/sling/microsling/integration/ src/test/java/org/apache/sling/microsling/integration/helpers/
Date Fri, 26 Oct 2007 09:19:42 GMT
Author: bdelacretaz
Date: Fri Oct 26 02:19:38 2007
New Revision: 588577

URL: http://svn.apache.org/viewvc?rev=588577&view=rev
Log:
SLING-82 - use HttpClient for all requests, and make it easier to debug the integration tests
(see src/test/java/org/apache/sling/microsling/integration/package.html)

Modified:
    incubator/sling/whiteboard/microsling/pom.xml
    incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/FileUploadTest.java
    incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/HttpPingTest.java
    incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/MicroslingHttpTestBase.java
    incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/helpers/MicroslingIntegrationTestClient.java
    incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/package.html

Modified: incubator/sling/whiteboard/microsling/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/pom.xml?rev=588577&r1=588576&r2=588577&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/pom.xml (original)
+++ incubator/sling/whiteboard/microsling/pom.xml Fri Oct 26 02:19:38 2007
@@ -147,9 +147,23 @@
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-surefire-plugin</artifactId>
         <configuration>
-          <excludes>
-            <exclude>${integration.test.code.path}/**.java</exclude>
-          </excludes>
+          <systemProperties>
+            <!-- 
+              WARNING: make sure these URLs are consistent with the
+              cargo-maven2-plugin settings: AFAIK Maven does not
+              expand variables in the <value> element.
+              And WARNING: these properties are duplicated somewhere in this
+              POM with slightly different values...there must be a better way. 
+            -->
+            <property>
+              <name>microsling.http.server.url</name>
+              <value>http://localhost:8080/</value>
+            </property>
+            <property>
+              <name>microsling.webdav.server.url</name>
+              <value>http://localhost:8080/repository/default</value>
+            </property>
+          </systemProperties>
         </configuration>
       </plugin>
     </plugins>
@@ -192,7 +206,9 @@
                     <!-- 
                       WARNING: make sure these URLs are consistent with the
                       cargo-maven2-plugin settings: AFAIK Maven does not
-                      expand variables in the <value> element.  
+                      expand variables in the <value> element.
+                      And WARNING: these properties are duplicated somewhere in this
+                      POM with slightly different values...there must be a better way. 
                     -->
                     <property>
                       <name>microsling.http.server.url</name>
@@ -200,7 +216,7 @@
                     </property>
                     <property>
                       <name>microsling.webdav.server.url</name>
-                      <value>http://admin:admin@localhost:8080/microsling-1.0-SNAPSHOT/repository/default</value>
+                      <value>http://localhost:8080/microsling-1.0-SNAPSHOT/repository/default</value>
                     </property>
                   </systemProperties>
                 </configuration>
@@ -239,11 +255,37 @@
       </build>
     </profile>
     <profile>
+      <!--
+        By default, do not run the integration tests in the test phase, as they have
+        no microsling to talk to.
+        To debug the integration tests faster than with the normal build cycle,
+        deactivate this profile (using -P nullProfile for example) and run a
+        separate instance of microsling that the tests can talk to.
+       -->
+      <id>disableIntegrationTestsInTestPhase</id>
+      <activation>
+        <activeByDefault>true</activeByDefault>
+      </activation>
+      <build>
+        <plugins>
+          <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-surefire-plugin</artifactId>
+            <configuration>
+              <excludes>
+                <exclude>${integration.test.code.path}/**.java</exclude>
+              </excludes>
+            </configuration>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+    <profile>
       <!-- 
         Useful to deactivate other profiles from the command-line
         Is there a better way? mvn doesn't have a "deactivate profile" option. 
        -->
-      <id>nullProfile</id>
+      <id>nullMicroslingProfile</id>
     </profile>
   </profiles>
 

Modified: incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/FileUploadTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/FileUploadTest.java?rev=588577&r1=588576&r2=588577&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/FileUploadTest.java
(original)
+++ incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/FileUploadTest.java
Fri Oct 26 02:19:38 2007
@@ -19,24 +19,29 @@
 import java.io.IOException;
 import java.io.InputStream;
 
-/** Test uploading a file to the microsling repository */
+/** 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);
         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";
+        final String webdavUrl = WEBDAV_BASE_URL + "/FileUploadTest." + System.currentTimeMillis()
+ ".txt";
         
-        assertHttpStatus(path, 404, "File " + path + " must not exist before test");
-        int status = testClient.upload(WEBDAV_URL + path, data);
+        // 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);
-        
-        // 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");
+        assertHttpStatus(webdavUrl, 200, "Resource " + webdavUrl + " must exist after upload");
+        testClient.delete(webdavUrl);
+        assertHttpStatus(webdavUrl, 404, "Resource " + webdavUrl + " must not exist anymore
after deleting");
     }
 }

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=588577&r1=588576&r2=588577&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
Fri Oct 26 02:19:38 2007
@@ -23,12 +23,12 @@
 public class HttpPingTest extends MicroslingHttpTestBase {
     public void testWebServerRoot() throws Exception
     {
-        assertHttpStatus("/", 200);
+        assertHttpStatus(HTTP_BASE_URL + "/", 200);
     }
     
     public void test404() throws Exception
     {
-        assertHttpStatus("/someNonExistentUrl", 404);
+        assertHttpStatus(HTTP_BASE_URL + "/someNonExistentUrl", 404);
     }
     
 }

Modified: incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/MicroslingHttpTestBase.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/MicroslingHttpTestBase.java?rev=588577&r1=588576&r2=588577&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/MicroslingHttpTestBase.java
(original)
+++ incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/MicroslingHttpTestBase.java
Fri Oct 26 02:19:38 2007
@@ -17,43 +17,65 @@
 package org.apache.sling.microsling.integration;
 
 import java.io.IOException;
-import java.net.HttpURLConnection;
+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_URL = System.getProperty("microsling.http.server.url");
-    public static final String WEBDAV_URL = System.getProperty("microsling.webdav.server.url");
+    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";
     
-    protected final MicroslingIntegrationTestClient testClient = new MicroslingIntegrationTestClient();
+    protected MicroslingIntegrationTestClient testClient;
+    protected HttpClient httpClient;
     
-    /** 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();
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        
+        // assume http and webdav are on the same host + port
+        URL url = null;
         try {
-            connection.connect();
-            if(assertMessage == null) {
-                assertEquals(expectedStatusCode, connection.getResponseCode());
-            } else {
-                assertEquals(assertMessage, expectedStatusCode, connection.getResponseCode());
-            }
-        } finally {
-            if(connection!=null) {
-                connection.disconnect();
-            }
+            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);
         }
     }
     
-    protected void assertHttpStatus(String path, int expectedStatusCode) throws IOException
{
-        assertHttpStatus(path, expectedStatusCode, null);
+    /** Verify that given URL returns expectedStatusCode 
+     * @throws IOException */
+    protected void assertHttpStatus(String urlString, int expectedStatusCode) throws IOException
{
+        assertHttpStatus(urlString, expectedStatusCode, null);
     }
 }

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=588577&r1=588576&r2=588577&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 02:19:38 2007
@@ -19,10 +19,7 @@
 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;
@@ -31,12 +28,8 @@
 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);
+    public MicroslingIntegrationTestClient(HttpClient client) {
+        this.client = client;
     }
     
     /** Upload a file to the microsling repository 

Modified: incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/package.html
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/package.html?rev=588577&r1=588576&r2=588577&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/package.html
(original)
+++ incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/package.html
Fri Oct 26 02:19:38 2007
@@ -1,7 +1,20 @@
 <html>
 <body>
-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>
+    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>



Mime
View raw message