summaryrefslogtreecommitdiffstats
path: root/archiva-modules
diff options
context:
space:
mode:
authorOlivier Lamy <olamy@apache.org>2014-01-06 05:31:13 +0000
committerOlivier Lamy <olamy@apache.org>2014-01-06 05:31:13 +0000
commit0be38b502668699bbea529c19e0a38ee7b9564f5 (patch)
tree208f10aa66b95657d4e1348cfb117efd48f3c7e8 /archiva-modules
parentba3e35c60c0306d036494f9588dfcf847e5c3a6c (diff)
downloadarchiva-0be38b502668699bbea529c19e0a38ee7b9564f5.tar.gz
archiva-0be38b502668699bbea529c19e0a38ee7b9564f5.zip
fix unit test
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1555668 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules')
-rw-r--r--archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletTestCase.java11
-rw-r--r--archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/RepositoryServletTest.java56
2 files changed, 49 insertions, 18 deletions
diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletTestCase.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletTestCase.java
index d1df95a39..ee8c8d082 100644
--- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletTestCase.java
+++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletTestCase.java
@@ -36,6 +36,7 @@ import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
import org.apache.archiva.webdav.util.MavenIndexerCleaner;
import org.apache.archiva.webdav.util.ReinitServlet;
import org.apache.catalina.Context;
+import org.apache.catalina.core.StandardContext;
import org.apache.catalina.deploy.ApplicationParameter;
import org.apache.catalina.startup.Tomcat;
import org.apache.commons.io.FileUtils;
@@ -137,13 +138,17 @@ public abstract class AbstractRepositoryServletTestCase
}
+ StandardContext context;
+
+ UnauthenticatedRepositoryServlet servlet;
+
protected void startRepository() throws Exception
{
tomcat = new Tomcat();
tomcat.setBaseDir( System.getProperty( "java.io.tmpdir" ) );
tomcat.setPort( 0 );
- Context context = tomcat.addContext( "", System.getProperty( "java.io.tmpdir" ) );
+ context = (StandardContext) tomcat.addContext( "", System.getProperty( "java.io.tmpdir" ) );
ApplicationParameter applicationParameter = new ApplicationParameter();
applicationParameter.setName( "contextConfigLocation" );
@@ -154,7 +159,9 @@ public abstract class AbstractRepositoryServletTestCase
context.addApplicationListener( MavenIndexerCleaner.class.getName() );
- Tomcat.addServlet( context, "repository", new UnauthenticatedRepositoryServlet() );
+ servlet = new UnauthenticatedRepositoryServlet();
+
+ Tomcat.addServlet( context, "repository", servlet );
context.addServletMapping( "/repository/*", "repository" );
diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/RepositoryServletTest.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/RepositoryServletTest.java
index 3e897f379..a9988b11a 100644
--- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/RepositoryServletTest.java
+++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/RepositoryServletTest.java
@@ -25,15 +25,19 @@ import org.apache.archiva.admin.model.beans.ManagedRepository;
import org.apache.archiva.configuration.ArchivaConfiguration;
import org.apache.archiva.configuration.Configuration;
import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
+import org.apache.catalina.Container;
+import org.apache.catalina.startup.Tomcat;
+import org.apache.commons.lang.StringUtils;
+import org.fest.assertions.api.Assertions;
import org.junit.Before;
import org.junit.Test;
+import javax.servlet.Servlet;
import java.io.File;
+import java.util.Enumeration;
/**
- * RepositoryServletTest
- *
- *
+ * RepositoryServletTest
*/
public class RepositoryServletTest
extends AbstractRepositoryServletTestCase
@@ -44,21 +48,49 @@ public class RepositoryServletTest
private static final String NEW_REPOSITORY_NAME = "New Repository";
+ @Before
+ @Override
+ public void setUp()
+ throws Exception
+ {
+ super.setUp();
+ startRepository();
+ }
+
@Test
public void testGetRepository()
throws Exception
{
- RepositoryServlet servlet = null;//(RepositoryServlet) getServletUnitClient().newInvocation( REQUEST_PATH ).getServlet();
+
+ RepositoryServlet servlet = RepositoryServlet.class.cast( findServlet( "repository" ) );
assertNotNull( servlet );
assertRepositoryValid( servlet, REPOID_INTERNAL );
}
+ Servlet findServlet( String name )
+ throws Exception
+ {
+ Container[] childs = context.findChildren();
+ for ( Container container : childs )
+ {
+ if ( StringUtils.equals( container.getName(), name ) )
+ {
+ Tomcat.ExistingStandardWrapper esw = Tomcat.ExistingStandardWrapper.class.cast( container );
+ Servlet servlet = esw.loadServlet();
+
+ return servlet;
+ }
+ }
+ return null;
+ }
+
@Test
public void testGetRepositoryAfterDelete()
throws Exception
{
- RepositoryServlet servlet = null;//(RepositoryServlet) getServletUnitClient().newInvocation( REQUEST_PATH ).getServlet();
+ RepositoryServlet servlet = RepositoryServlet.class.cast( findServlet( "repository" ) );
+
assertNotNull( servlet );
ArchivaConfiguration archivaConfiguration = servlet.getConfiguration();
@@ -70,19 +102,11 @@ public class RepositoryServletTest
assertNull( repository );
}
- @Before
- @Override
- public void setUp() throws Exception
- {
- super.setUp();
- startRepository();
- }
-
@Test
public void testGetRepositoryAfterAdd()
throws Exception
{
- RepositoryServlet servlet = null;//(RepositoryServlet) getServletUnitClient().newInvocation( REQUEST_PATH ).getServlet();
+ RepositoryServlet servlet =RepositoryServlet.class.cast( findServlet( "repository" ) );
assertNotNull( servlet );
ArchivaConfiguration archivaConfiguration = servlet.getConfiguration();
@@ -114,7 +138,7 @@ public class RepositoryServletTest
String path = REQUEST_PATH + ".index/filecontent/segments.gen";
populateRepo( repoRootInternal, ".index/filecontent/segments.gen", "index file" );
-
+
WebRequest request = new GetMethodWebRequest( path );
WebResponse response = getServletUnitClient().getResponse( request );
assertResponseOK( response );
@@ -130,6 +154,6 @@ public class RepositoryServletTest
WebRequest request = new GetMethodWebRequest( path );
WebResponse response = getServletUnitClient().getResponse( request );
assertResponseNotFound( response );
- assertEquals( "Invalid path to Artifact: legacy paths should have an expected type ending in [s] in the second part of the path.", response.getStatusMessage() );
+ Assertions.assertThat( response.getContentAsString() ).contains( "Invalid path to Artifact: legacy paths should have an expected type ending in [s] in the second part of the path." );
}
}