]> source.dussan.org Git - archiva.git/commitdiff
use tomcat rather than jetty for unit tests
authorOlivier Lamy <olamy@apache.org>
Fri, 15 Jun 2012 21:08:53 +0000 (21:08 +0000)
committerOlivier Lamy <olamy@apache.org>
Fri, 15 Jun 2012 21:08:53 +0000 (21:08 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/redback/redback-core/trunk@1350797 13f79535-47bb-0310-9956-ffa450edef68

redback-integrations/redback-rest/redback-rest-services/pom.xml
redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/AbstractRestServicesTest.java

index 9eabc43dcd98b7e5162f4539bcd74942de92e7f8..00b012223c075b2ae3b8a1c56006e8a7dcd6ae9a 100644 (file)
@@ -29,7 +29,7 @@
 
   <properties>
     <jettyVersion>7.5.3.v20111011</jettyVersion>
-    <tomcatVersion>7.0.21</tomcatVersion>
+    <tomcatVersion>7.0.27</tomcatVersion>
     <test.useTomcat>false</test.useTomcat>
   </properties>
 
       <artifactId>commons-io</artifactId>
     </dependency>
 
-    <dependency>
-      <groupId>javax.servlet</groupId>
-      <artifactId>servlet-api</artifactId>
-      <scope>provided</scope>
-    </dependency>
-
     <dependency>
       <groupId>org.apache.archiva.redback</groupId>
       <artifactId>redback-users-api</artifactId>
           <groupId>org.eclipse.jetty</groupId>
           <artifactId>jetty-server</artifactId>
         </exclusion>
+        <exclusion>
+          <groupId>org.apache.geronimo.specs</groupId>
+          <artifactId>geronimo-servlet_2.5_spec</artifactId>
+        </exclusion>
         <exclusion>
           <groupId>org.codehaus.jettison</groupId>
           <artifactId>jettison</artifactId>
       <scope>test</scope>
     </dependency>
 
-    <dependency>
-      <groupId>org.eclipse.jetty</groupId>
-      <artifactId>jetty-server</artifactId>
-      <version>${jettyVersion}</version>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.eclipse.jetty</groupId>
-      <artifactId>jetty-plus</artifactId>
-      <version>${jettyVersion}</version>
-      <scope>test</scope>
-    </dependency>
-
-    <!--
     <dependency>
       <groupId>org.apache.tomcat.embed</groupId>
       <artifactId>tomcat-embed-core</artifactId>
       <version>${tomcatVersion}</version>
       <scope>test</scope>
     </dependency>
-    -->
+    <dependency>
+      <groupId>org.apache.tomcat</groupId>
+      <artifactId>tomcat-servlet-api</artifactId>
+      <version>${tomcatVersion}</version>
+      <scope>test</scope>
+    </dependency>
 
     <dependency>
       <groupId>org.slf4j</groupId>
index fc82802a559e7726fa218674f0ab1937dd0edacf..580a116418b42c4f573511bdbc13f27beb928a2e 100644 (file)
@@ -20,22 +20,20 @@ package org.apache.archiva.redback.rest.services;
  */
 
 import junit.framework.TestCase;
+import org.apache.archiva.redback.integration.security.role.RedbackRoleConstants;
+import org.apache.archiva.redback.rest.api.model.User;
+import org.apache.archiva.redback.rest.api.services.LoginService;
+import org.apache.archiva.redback.rest.api.services.RoleManagementService;
+import org.apache.archiva.redback.rest.api.services.UserService;
+import org.apache.catalina.Context;
+import org.apache.catalina.deploy.ApplicationParameter;
+import org.apache.catalina.startup.Tomcat;
 import org.apache.commons.lang.StringUtils;
 import org.apache.cxf.common.util.Base64Utility;
 import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
 import org.apache.cxf.jaxrs.client.WebClient;
 import org.apache.cxf.transport.servlet.CXFServlet;
 import org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider;
-import org.apache.archiva.redback.integration.security.role.RedbackRoleConstants;
-import org.apache.archiva.redback.rest.api.model.User;
-import org.apache.archiva.redback.rest.api.services.LoginService;
-import org.apache.archiva.redback.rest.api.services.RoleManagementService;
-import org.apache.archiva.redback.rest.api.services.UserService;
-import org.eclipse.jetty.server.Connector;
-import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.server.session.SessionHandler;
-import org.eclipse.jetty.servlet.ServletContextHandler;
-import org.eclipse.jetty.servlet.ServletHolder;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.runner.RunWith;
@@ -56,9 +54,7 @@ public abstract class AbstractRestServicesTest
 {
     protected Logger log = LoggerFactory.getLogger( getClass() );
 
-    public Server server = null;
-
-    //private Tomcat tomcat;
+    private Tomcat tomcat;
 
     public int port;
 
@@ -91,36 +87,30 @@ public abstract class AbstractRestServicesTest
         return "restServices";
     }
 
-    static boolean useTomcat = Boolean.getBoolean( "test.useTomcat" );
-
     @Before
     public void startServer()
         throws Exception
     {
 
-        this.server = new Server( 0 );
-
-        ServletContextHandler context = new ServletContextHandler();
-
-        context.setContextPath( "/" );
-
-        context.setInitParameter( "contextConfigLocation", getSpringConfigLocation() );
+        tomcat = new Tomcat();
+        tomcat.setBaseDir( System.getProperty( "java.io.tmpdir" ) );
+        tomcat.setPort( 0 );
 
-        ContextLoaderListener contextLoaderListener = new ContextLoaderListener();
+        Context context = tomcat.addContext( "", System.getProperty( "java.io.tmpdir" ) );
 
-        context.addEventListener( contextLoaderListener );
+        ApplicationParameter applicationParameter = new ApplicationParameter();
+        applicationParameter.setName( "contextConfigLocation" );
+        applicationParameter.setValue( getSpringConfigLocation() );
+        context.addApplicationParameter( applicationParameter );
 
-        ServletHolder sh = new ServletHolder( CXFServlet.class );
+        context.addApplicationListener( ContextLoaderListener.class.getName() );
 
-        SessionHandler sessionHandler = new SessionHandler();
+        Tomcat.addServlet( context, "cxf", new CXFServlet() );
+        context.addServletMapping( "/" + getRestServicesPath() + "/*", "cxf" );
 
-        context.setSessionHandler( sessionHandler );
+        tomcat.start();
 
-        context.addServlet( sh, "/" + getRestServicesPath() + "/*" );
-        server.setHandler( context );
-        this.server.start();
-        Connector connector = this.server.getConnectors()[0];
-        this.port = connector.getLocalPort();
+        this.port = tomcat.getConnector().getLocalPort();
 
         log.info( "start server on port " + this.port );
 
@@ -149,9 +139,9 @@ public abstract class AbstractRestServicesTest
     public void stopServer()
         throws Exception
     {
-        if ( this.server != null && this.server.isRunning() )
+        if ( this.tomcat != null )
         {
-            this.server.stop();
+            this.tomcat.stop();
         }
     }