git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1555669 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2014-01-06 05:31:20 +00:00
parent 0be38b5026
commit 7065cd1585
2 changed files with 27 additions and 23 deletions

View File

@ -35,11 +35,13 @@ import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
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.Container;
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;
import org.apache.commons.lang.StringUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.runner.RunWith;
@ -50,6 +52,7 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.web.context.ContextLoaderListener;
import javax.inject.Inject;
import javax.servlet.Servlet;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
@ -60,8 +63,8 @@ import java.nio.charset.Charset;
/**
* AbstractRepositoryServletTestCase
*/
@RunWith( ArchivaSpringJUnit4ClassRunner.class )
@ContextConfiguration( locations = { "classpath*:/repository-servlet-simple.xml" } )
@RunWith(ArchivaSpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath*:/repository-servlet-simple.xml" })
public abstract class AbstractRepositoryServletTestCase
extends TestCase
{
@ -135,14 +138,14 @@ public abstract class AbstractRepositoryServletTestCase
applicationContext.getBean( MavenIndexerCleaner.class ).cleanupIndex();
}
StandardContext context;
UnauthenticatedRepositoryServlet servlet;
protected void startRepository() throws Exception
protected void startRepository()
throws Exception
{
tomcat = new Tomcat();
tomcat.setBaseDir( System.getProperty( "java.io.tmpdir" ) );
@ -164,7 +167,6 @@ public abstract class AbstractRepositoryServletTestCase
Tomcat.addServlet( context, "repository", servlet );
context.addServletMapping( "/repository/*", "repository" );
Tomcat.addServlet( context, "reinitservlet", new ReinitServlet() );
context.addServletMapping( "/reinit/*", "reinitservlet" );
@ -173,6 +175,23 @@ public abstract class AbstractRepositoryServletTestCase
this.port = tomcat.getConnector().getLocalPort();
}
protected 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;
}
protected String getSpringConfigLocation()
{
return "classpath*:/META-INF/spring-context.xml,classpath*:spring-context.xml";

View File

@ -68,22 +68,6 @@ public class RepositoryServletTest
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()
@ -106,7 +90,7 @@ public class RepositoryServletTest
public void testGetRepositoryAfterAdd()
throws Exception
{
RepositoryServlet servlet =RepositoryServlet.class.cast( findServlet( "repository" ) );
RepositoryServlet servlet = RepositoryServlet.class.cast( findServlet( "repository" ) );
assertNotNull( servlet );
ArchivaConfiguration archivaConfiguration = servlet.getConfiguration();
@ -154,6 +138,7 @@ public class RepositoryServletTest
WebRequest request = new GetMethodWebRequest( path );
WebResponse response = getServletUnitClient().getResponse( request );
assertResponseNotFound( response );
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." );
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." );
}
}