You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@continuum.apache.org by ct...@apache.org on 2010/07/19 09:13:29 UTC

svn commit: r965372 [2/2] - in /continuum/trunk: ./ continuum-buildagent/ continuum-buildagent/continuum-buildagent-webapp/ continuum-buildagent/continuum-buildagent-webapp/src/main/webapp/WEB-INF/ continuum-buildagent/continuum-buildagent-webdav/ cont...

Added: continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/test/java/org/apache/continuum/webdav/MockContinuumBuildAgentDavResourceFactory.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/test/java/org/apache/continuum/webdav/MockContinuumBuildAgentDavResourceFactory.java?rev=965372&view=auto
==============================================================================
--- continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/test/java/org/apache/continuum/webdav/MockContinuumBuildAgentDavResourceFactory.java (added)
+++ continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/test/java/org/apache/continuum/webdav/MockContinuumBuildAgentDavResourceFactory.java Mon Jul 19 07:13:27 2010
@@ -0,0 +1,55 @@
+package org.apache.continuum.webdav;
+
+/*
+ * 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.
+ */
+
+import java.io.File;
+import java.io.IOException;
+
+public class MockContinuumBuildAgentDavResourceFactory
+    extends ContinuumBuildAgentDavResourceFactory
+{
+    @Override
+    protected File getResourceFile( int projectId, String logicalResource )
+    {
+        return new File( getWorkingDirectory( projectId ), logicalResource );
+    }
+
+    private File getWorkingDirectory( int projectId )
+    {
+        String basedir = System.getProperty( "basedir" );
+
+        if ( basedir == null )
+        {
+            basedir = new File( "" ).getAbsolutePath();
+        }
+
+        File dir = new File( basedir, "target/appserver-base/data/working-directory/" + projectId  );
+
+        try
+        {
+            dir = dir.getCanonicalFile();
+        }
+        catch ( IOException e )
+        {
+        }
+
+        return dir;
+    }
+}

Added: continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/test/java/org/apache/continuum/webdav/WorkingCopyServletTest.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/test/java/org/apache/continuum/webdav/WorkingCopyServletTest.java?rev=965372&view=auto
==============================================================================
--- continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/test/java/org/apache/continuum/webdav/WorkingCopyServletTest.java (added)
+++ continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/test/java/org/apache/continuum/webdav/WorkingCopyServletTest.java Mon Jul 19 07:13:27 2010
@@ -0,0 +1,177 @@
+package org.apache.continuum.webdav;
+
+/*
+ * 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.
+ */
+
+import java.io.File;
+
+import javax.servlet.http.HttpServletResponse;
+
+import net.sf.ehcache.CacheManager;
+
+import org.apache.commons.io.FileUtils;
+import org.codehaus.plexus.spring.PlexusInSpringTestCase;
+
+import com.meterware.httpunit.GetMethodWebRequest;
+import com.meterware.httpunit.HttpUnitOptions;
+import com.meterware.httpunit.WebLink;
+import com.meterware.httpunit.WebRequest;
+import com.meterware.httpunit.WebResponse;
+import com.meterware.servletunit.ServletRunner;
+import com.meterware.servletunit.ServletUnitClient;
+
+public class WorkingCopyServletTest
+    extends PlexusInSpringTestCase
+{
+    private static final String REQUEST_PATH = "http://machine.com/workingcopy/1/";
+
+    private WebRequest request;
+
+    private WebResponse response;
+
+    private ServletRunner sr;
+
+    private ServletUnitClient sc;
+
+    private File workingDirectory;
+
+    @Override
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+
+        String appserverBase = getTestFile( "target/appserver-base" ).getAbsolutePath();
+        System.setProperty( "appserver.base", appserverBase );
+
+        workingDirectory = new File( appserverBase, "data/working-directory" );
+
+        CacheManager.getInstance().removeCache( "url-failures-cache" );
+
+        HttpUnitOptions.setExceptionsThrownOnErrorStatus( false );
+
+        sr = new ServletRunner( getTestFile( "src/test/resources/WEB-INF/web.xml" ) );
+        sr.registerServlet( "/workingcopy/*", WorkingCopyServlet.class.getName() );
+        sc = sr.newClient();
+
+        new File( workingDirectory, "1/src/main/java/org/apache/continuum" ).mkdirs();
+        new File( workingDirectory, "1/src/main/java/org/apache/continuum/App.java" ).createNewFile();
+        new File( workingDirectory, "1/src/test" ).mkdirs();
+        new File( workingDirectory, "1/pom.xml" ).createNewFile();
+        new File( workingDirectory, "1/target" ).mkdir();
+        new File( workingDirectory, "1/target/continuum-artifact-1.0.jar" ).createNewFile();
+    }
+
+    @Override
+    protected void tearDown()
+        throws Exception
+    {
+        if ( sc != null )
+        {
+            sc.clearContents();
+        }
+
+        if ( sr != null )
+        {
+            sr.shutDown();
+        }
+
+        if ( workingDirectory.exists() )
+        {
+            FileUtils.deleteDirectory( workingDirectory );
+        }
+
+        super.tearDown();
+    }
+
+    public void testGetWorkingCopy()
+        throws Exception
+    {
+        WorkingCopyServlet servlet = (WorkingCopyServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
+        assertNotNull( servlet );
+    }
+
+    public void testBrowse()
+        throws Exception
+    {
+        request = new GetMethodWebRequest( REQUEST_PATH );
+        response = sc.getResponse( request );
+        assertEquals( "Response", HttpServletResponse.SC_OK, response.getResponseCode() );
+
+        String expectedLinks[] = new String[] { "pom.xml", "src/", "target/" };
+        assertLinks( expectedLinks, response.getLinks() );
+    }
+
+    public void testBrowseSubDirectory()
+        throws Exception
+    {
+        request = new GetMethodWebRequest( REQUEST_PATH + "src/" );
+        response = sc.getResponse( request );
+        assertEquals( "Response", HttpServletResponse.SC_OK, response.getResponseCode() );
+
+        String expectedLinks[] = new String[] { "../", "main/", "test/" };
+        assertLinks( expectedLinks, response.getLinks() );
+    }
+
+    public void testGetFile()
+        throws Exception
+    {
+        request = new GetMethodWebRequest( REQUEST_PATH + 
+                                           "src/main/java/org/apache/continuum" );
+        response = sc.getResponse( request );
+        assertEquals( "Response", HttpServletResponse.SC_OK, response.getResponseCode() );
+
+        request = new GetMethodWebRequest( REQUEST_PATH + "src/main/java/org/apache/continuum/" );
+        response = sc.getResponse( request );
+        assertEquals( "Response", HttpServletResponse.SC_OK, response.getResponseCode() );
+
+        request = new GetMethodWebRequest( REQUEST_PATH + "src/main/java/org/apache/continuum/App.java" );
+        response = sc.getResponse( request );
+        assertEquals( "Response", HttpServletResponse.SC_OK, response.getResponseCode() );
+
+        request = new GetMethodWebRequest( REQUEST_PATH + "src/main/java/org/apache/continuum/App.java/" );
+        response = sc.getResponse( request );
+        assertEquals( "Response", HttpServletResponse.SC_NOT_FOUND, response.getResponseCode() );
+
+        request = new GetMethodWebRequest( REQUEST_PATH + "pom.xml" );
+        response = sc.getResponse( request );
+        assertEquals( "Response", HttpServletResponse.SC_OK, response.getResponseCode() );
+
+        request = new GetMethodWebRequest( REQUEST_PATH + "pom.xml/" );
+        response = sc.getResponse( request );
+        assertEquals( "Response", HttpServletResponse.SC_NOT_FOUND, response.getResponseCode() );
+
+        request = new GetMethodWebRequest( REQUEST_PATH + "target/continuum-artifact-1.0.jar" );
+        response = sc.getResponse( request );
+        assertEquals( "Response", HttpServletResponse.SC_OK, response.getResponseCode() );
+
+        request = new GetMethodWebRequest( REQUEST_PATH + "target/continuum-artifact-1.0.jar/" );
+        response = sc.getResponse( request );
+        assertEquals( "Response", HttpServletResponse.SC_NOT_FOUND, response.getResponseCode() );
+    }
+
+    private void assertLinks( String expectedLinks[], WebLink actualLinks[] )
+    {
+        assertEquals( "Links.length", expectedLinks.length, actualLinks.length );
+        for ( int i = 0; i < actualLinks.length; i++ )
+        {
+            assertEquals( "Link[" + i + "]", expectedLinks[i], actualLinks[i].getURLString() );
+        }
+    }
+}

Added: continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/test/java/org/apache/continuum/webdav/util/WorkingCopyPathUtilTest.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/test/java/org/apache/continuum/webdav/util/WorkingCopyPathUtilTest.java?rev=965372&view=auto
==============================================================================
--- continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/test/java/org/apache/continuum/webdav/util/WorkingCopyPathUtilTest.java (added)
+++ continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/test/java/org/apache/continuum/webdav/util/WorkingCopyPathUtilTest.java Mon Jul 19 07:13:27 2010
@@ -0,0 +1,50 @@
+package org.apache.continuum.webdav.util;
+
+/*
+ * 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.
+ */
+
+import junit.framework.TestCase;
+
+public class WorkingCopyPathUtilTest
+    extends TestCase
+{
+    public void testGetProjectId()
+    {
+        String href = "/path/1/src/main/java";
+        assertEquals( 1, WorkingCopyPathUtil.getProjectId( href ) );
+
+        href = "path/2/src/test";
+        assertEquals( 2, WorkingCopyPathUtil.getProjectId( href ) );
+    }
+
+    public void testGetLogicalPath()
+    {
+        String href = "/workingcopy/1/src/main/java/org/apache/maven/someartifact.jar";
+        assertEquals("/src/main/java/org/apache/maven/someartifact.jar", WorkingCopyPathUtil.getLogicalResource( href ) );
+
+        href = "workingcopy/1/src/main/java/org/apache/maven/someartifact.jar";
+        assertEquals("/src/main/java/org/apache/maven/someartifact.jar", WorkingCopyPathUtil.getLogicalResource( href ) );
+        
+        href = "workingcopy/1/src/main/java/";
+        assertEquals( "/src/main/java/", WorkingCopyPathUtil.getLogicalResource( href ) );
+
+        href = "workingcopy";
+        assertEquals( "/", WorkingCopyPathUtil.getLogicalResource( href ) );
+    }
+}

Added: continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/test/resources/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/test/resources/WEB-INF/web.xml?rev=965372&view=auto
==============================================================================
--- continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/test/resources/WEB-INF/web.xml (added)
+++ continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/test/resources/WEB-INF/web.xml Mon Jul 19 07:13:27 2010
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+  ~ 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.
+  -->
+
+<web-app xmlns="http://java.sun.com/xml/ns/j2ee" version="2.4"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
+
+  <display-name>Apache Continuum Build Agent</display-name>
+
+  <listener>
+    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
+  </listener>
+
+  <context-param>
+    <param-name>contextClass</param-name>
+    <param-value>org.codehaus.plexus.spring.PlexusWebApplicationContext</param-value>
+  </context-param>
+
+   <context-param>
+    <param-name>contextConfigLocation</param-name>
+    <param-value>
+        classpath*:/META-INF/plexus/components.xml
+        classpath*:/META-INF/spring-context.xml
+        target/test-classes/org/apache/continuum/webdav/WorkingCopyServletTest.xml
+    </param-value>
+  </context-param>
+
+</web-app>
\ No newline at end of file

Added: continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/test/resources/org/apache/continuum/webdav/WorkingCopyServletTest.xml
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/test/resources/org/apache/continuum/webdav/WorkingCopyServletTest.xml?rev=965372&view=auto
==============================================================================
--- continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/test/resources/org/apache/continuum/webdav/WorkingCopyServletTest.xml (added)
+++ continuum/trunk/continuum-buildagent/continuum-buildagent-webdav/src/test/resources/org/apache/continuum/webdav/WorkingCopyServletTest.xml Mon Jul 19 07:13:27 2010
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+  ~ 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.
+  -->
+
+<plexus>
+  <components>
+    <component>
+      <role>org.apache.continuum.webdav.ContinuumBuildAgentDavResourceFactory</role>
+      <implementation>org.apache.continuum.webdav.MockContinuumBuildAgentDavResourceFactory</implementation>
+    </component>
+  </components>
+</plexus>
\ No newline at end of file

Modified: continuum/trunk/continuum-buildagent/pom.xml
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-buildagent/pom.xml?rev=965372&r1=965371&r2=965372&view=diff
==============================================================================
--- continuum/trunk/continuum-buildagent/pom.xml (original)
+++ continuum/trunk/continuum-buildagent/pom.xml Mon Jul 19 07:13:27 2010
@@ -32,6 +32,7 @@ under the License.
   <modules>
     <module>continuum-buildagent-api</module>
     <module>continuum-buildagent-core</module>
+    <module>continuum-buildagent-webdav</module>
     <module>continuum-buildagent-webapp</module>
     <module>continuum-buildagent-jetty</module>
   </modules>

Modified: continuum/trunk/pom.xml
URL: http://svn.apache.org/viewvc/continuum/trunk/pom.xml?rev=965372&r1=965371&r2=965372&view=diff
==============================================================================
--- continuum/trunk/pom.xml (original)
+++ continuum/trunk/pom.xml Mon Jul 19 07:13:27 2010
@@ -665,6 +665,11 @@ under the License.
         <version>${project.version}</version>
       </dependency>
       <dependency>
+        <groupId>org.apache.continuum</groupId>
+        <artifactId>continuum-buildagent-webdav</artifactId>
+        <version>${project.version}</version>
+      </dependency>
+      <dependency>
         <groupId>org.apache.xmlrpc</groupId>
         <artifactId>xmlrpc-client</artifactId>
         <version>${xmlrpc.version}</version>
@@ -1593,6 +1598,34 @@ under the License.
         <artifactId>commons-logging-api</artifactId>
         <version>1.1</version>
       </dependency>
+      <dependency>
+        <groupId>javax.servlet</groupId>
+        <artifactId>servlet-api</artifactId>
+        <version>2.4</version>
+        <scope>provided</scope>
+      </dependency>
+      <dependency>
+        <groupId>joda-time</groupId>
+        <artifactId>joda-time</artifactId>
+        <version>1.5.2</version>
+      </dependency>
+      <dependency> 
+        <groupId>org.apache.jackrabbit</groupId>
+        <artifactId>jackrabbit-webdav</artifactId>
+        <version>1.5.0</version>
+        <exclusions>
+          <exclusion>
+            <groupId>commons-logging</groupId>
+            <artifactId>commons-logging</artifactId>
+          </exclusion>
+        </exclusions>
+      </dependency>
+      <dependency>
+        <groupId>httpunit</groupId>
+        <artifactId>httpunit</artifactId>
+        <version>1.6.2</version>
+        <scope>test</scope>
+      </dependency>
     </dependencies>
   </dependencyManagement>