Author: olamy
Date: Fri Jun 15 21:08:53 2012
New Revision: 1350797
URL: http://svn.apache.org/viewvc?rev=1350797&view=rev
Log:
use tomcat rather than jetty for unit tests
Modified:
archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/pom.xml
archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/AbstractRestServicesTest.java
Modified:
archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/pom.xml
URL:
http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/pom.xml?rev=1350797&r1=1350796&r2=1350797&view=diff
==============================================================================
---
archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/pom.xml
(original)
+++
archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/pom.xml
Fri Jun 15 21:08:53 2012
@@ -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>
@@ -59,12 +59,6 @@
</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>
</dependency>
@@ -93,6 +87,10 @@
<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>
</exclusion>
@@ -133,20 +131,6 @@
</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>
@@ -164,7 +148,12 @@
<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>
Modified:
archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/AbstractRestServicesTest.java
URL:
http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/AbstractRestServicesTest.java?rev=1350797&r1=1350796&r2=1350797&view=diff
==============================================================================
---
archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/AbstractRestServicesTest.java
(original)
+++
archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/AbstractRestServicesTest.java
Fri Jun 15 21:08:53 2012
@@ -20,22 +20,20 @@ package org.apache.archiva.redback.rest.
*/
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 AbstractRestServic
{
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 AbstractRestServic
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 AbstractRestServic
public void stopServer()
throws Exception
{
- if ( this.server != null && this.server.isRunning() )
+ if ( this.tomcat != null )
{
- this.server.stop();
+ this.tomcat.stop();
}
}