From 7065cd1585c0b33cb7d049a2803b8906bf5a1bb2 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Mon, 6 Jan 2014 05:31:20 +0000 Subject: [PATCH] refactor git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1555669 13f79535-47bb-0310-9956-ffa450edef68 --- .../AbstractRepositoryServletTestCase.java | 29 +++++++++++++++---- .../archiva/webdav/RepositoryServletTest.java | 21 ++------------ 2 files changed, 27 insertions(+), 23 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 ee8c8d082..e51bfe314 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 @@ -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"; 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 a9988b11a..3f444d341 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 @@ -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." ); } } -- 2.39.5