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;
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;
/**
* 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
{
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" ) );
Tomcat.addServlet( context, "repository", servlet );
context.addServletMapping( "/repository/*", "repository" );
-
Tomcat.addServlet( context, "reinitservlet", new ReinitServlet() );
context.addServletMapping( "/reinit/*", "reinitservlet" );
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";
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()
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();
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." );
}
}