mirror of https://github.com/apache/archiva.git
fix unit test
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1555668 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ba3e35c60c
commit
0be38b5026
|
@ -36,6 +36,7 @@ import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
|
||||||
import org.apache.archiva.webdav.util.MavenIndexerCleaner;
|
import org.apache.archiva.webdav.util.MavenIndexerCleaner;
|
||||||
import org.apache.archiva.webdav.util.ReinitServlet;
|
import org.apache.archiva.webdav.util.ReinitServlet;
|
||||||
import org.apache.catalina.Context;
|
import org.apache.catalina.Context;
|
||||||
|
import org.apache.catalina.core.StandardContext;
|
||||||
import org.apache.catalina.deploy.ApplicationParameter;
|
import org.apache.catalina.deploy.ApplicationParameter;
|
||||||
import org.apache.catalina.startup.Tomcat;
|
import org.apache.catalina.startup.Tomcat;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
|
@ -137,13 +138,17 @@ public abstract class AbstractRepositoryServletTestCase
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StandardContext context;
|
||||||
|
|
||||||
|
UnauthenticatedRepositoryServlet servlet;
|
||||||
|
|
||||||
protected void startRepository() throws Exception
|
protected void startRepository() throws Exception
|
||||||
{
|
{
|
||||||
tomcat = new Tomcat();
|
tomcat = new Tomcat();
|
||||||
tomcat.setBaseDir( System.getProperty( "java.io.tmpdir" ) );
|
tomcat.setBaseDir( System.getProperty( "java.io.tmpdir" ) );
|
||||||
tomcat.setPort( 0 );
|
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 applicationParameter = new ApplicationParameter();
|
||||||
applicationParameter.setName( "contextConfigLocation" );
|
applicationParameter.setName( "contextConfigLocation" );
|
||||||
|
@ -154,7 +159,9 @@ public abstract class AbstractRepositoryServletTestCase
|
||||||
|
|
||||||
context.addApplicationListener( MavenIndexerCleaner.class.getName() );
|
context.addApplicationListener( MavenIndexerCleaner.class.getName() );
|
||||||
|
|
||||||
Tomcat.addServlet( context, "repository", new UnauthenticatedRepositoryServlet() );
|
servlet = new UnauthenticatedRepositoryServlet();
|
||||||
|
|
||||||
|
Tomcat.addServlet( context, "repository", servlet );
|
||||||
context.addServletMapping( "/repository/*", "repository" );
|
context.addServletMapping( "/repository/*", "repository" );
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -25,15 +25,19 @@ import org.apache.archiva.admin.model.beans.ManagedRepository;
|
||||||
import org.apache.archiva.configuration.ArchivaConfiguration;
|
import org.apache.archiva.configuration.ArchivaConfiguration;
|
||||||
import org.apache.archiva.configuration.Configuration;
|
import org.apache.archiva.configuration.Configuration;
|
||||||
import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
|
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.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import javax.servlet.Servlet;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RepositoryServletTest
|
* RepositoryServletTest
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class RepositoryServletTest
|
public class RepositoryServletTest
|
||||||
extends AbstractRepositoryServletTestCase
|
extends AbstractRepositoryServletTestCase
|
||||||
|
@ -44,21 +48,49 @@ public class RepositoryServletTest
|
||||||
|
|
||||||
private static final String NEW_REPOSITORY_NAME = "New Repository";
|
private static final String NEW_REPOSITORY_NAME = "New Repository";
|
||||||
|
|
||||||
|
@Before
|
||||||
|
@Override
|
||||||
|
public void setUp()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
super.setUp();
|
||||||
|
startRepository();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetRepository()
|
public void testGetRepository()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
RepositoryServlet servlet = null;//(RepositoryServlet) getServletUnitClient().newInvocation( REQUEST_PATH ).getServlet();
|
|
||||||
|
RepositoryServlet servlet = RepositoryServlet.class.cast( findServlet( "repository" ) );
|
||||||
assertNotNull( servlet );
|
assertNotNull( servlet );
|
||||||
|
|
||||||
assertRepositoryValid( servlet, REPOID_INTERNAL );
|
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
|
@Test
|
||||||
public void testGetRepositoryAfterDelete()
|
public void testGetRepositoryAfterDelete()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
RepositoryServlet servlet = null;//(RepositoryServlet) getServletUnitClient().newInvocation( REQUEST_PATH ).getServlet();
|
RepositoryServlet servlet = RepositoryServlet.class.cast( findServlet( "repository" ) );
|
||||||
|
|
||||||
assertNotNull( servlet );
|
assertNotNull( servlet );
|
||||||
|
|
||||||
ArchivaConfiguration archivaConfiguration = servlet.getConfiguration();
|
ArchivaConfiguration archivaConfiguration = servlet.getConfiguration();
|
||||||
|
@ -70,19 +102,11 @@ public class RepositoryServletTest
|
||||||
assertNull( repository );
|
assertNull( repository );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
|
||||||
@Override
|
|
||||||
public void setUp() throws Exception
|
|
||||||
{
|
|
||||||
super.setUp();
|
|
||||||
startRepository();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetRepositoryAfterAdd()
|
public void testGetRepositoryAfterAdd()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
RepositoryServlet servlet = null;//(RepositoryServlet) getServletUnitClient().newInvocation( REQUEST_PATH ).getServlet();
|
RepositoryServlet servlet =RepositoryServlet.class.cast( findServlet( "repository" ) );
|
||||||
assertNotNull( servlet );
|
assertNotNull( servlet );
|
||||||
|
|
||||||
ArchivaConfiguration archivaConfiguration = servlet.getConfiguration();
|
ArchivaConfiguration archivaConfiguration = servlet.getConfiguration();
|
||||||
|
@ -114,7 +138,7 @@ public class RepositoryServletTest
|
||||||
String path = REQUEST_PATH + ".index/filecontent/segments.gen";
|
String path = REQUEST_PATH + ".index/filecontent/segments.gen";
|
||||||
|
|
||||||
populateRepo( repoRootInternal, ".index/filecontent/segments.gen", "index file" );
|
populateRepo( repoRootInternal, ".index/filecontent/segments.gen", "index file" );
|
||||||
|
|
||||||
WebRequest request = new GetMethodWebRequest( path );
|
WebRequest request = new GetMethodWebRequest( path );
|
||||||
WebResponse response = getServletUnitClient().getResponse( request );
|
WebResponse response = getServletUnitClient().getResponse( request );
|
||||||
assertResponseOK( response );
|
assertResponseOK( response );
|
||||||
|
@ -130,6 +154,6 @@ public class RepositoryServletTest
|
||||||
WebRequest request = new GetMethodWebRequest( path );
|
WebRequest request = new GetMethodWebRequest( path );
|
||||||
WebResponse response = getServletUnitClient().getResponse( request );
|
WebResponse response = getServletUnitClient().getResponse( request );
|
||||||
assertResponseNotFound( response );
|
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." );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue