use tomcat rather than jetty for unit tests
git-svn-id: https://svn.apache.org/repos/asf/archiva/redback/redback-core/trunk@1350797 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c2d6f8a2c8
commit
b758ce9c9e
|
@ -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>
|
||||
|
||||
|
@ -58,12 +58,6 @@
|
|||
<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>
|
||||
|
@ -92,6 +86,10 @@
|
|||
<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>
|
||||
|
@ -132,20 +130,6 @@
|
|||
<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>
|
||||
|
@ -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>
|
||||
|
|
|
@ -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 );
|
||||
tomcat = new Tomcat();
|
||||
tomcat.setBaseDir( System.getProperty( "java.io.tmpdir" ) );
|
||||
tomcat.setPort( 0 );
|
||||
|
||||
ServletContextHandler context = new ServletContextHandler();
|
||||
Context context = tomcat.addContext( "", System.getProperty( "java.io.tmpdir" ) );
|
||||
|
||||
context.setContextPath( "/" );
|
||||
ApplicationParameter applicationParameter = new ApplicationParameter();
|
||||
applicationParameter.setName( "contextConfigLocation" );
|
||||
applicationParameter.setValue( getSpringConfigLocation() );
|
||||
context.addApplicationParameter( applicationParameter );
|
||||
|
||||
context.setInitParameter( "contextConfigLocation", getSpringConfigLocation() );
|
||||
context.addApplicationListener( ContextLoaderListener.class.getName() );
|
||||
|
||||
ContextLoaderListener contextLoaderListener = new ContextLoaderListener();
|
||||
Tomcat.addServlet( context, "cxf", new CXFServlet() );
|
||||
context.addServletMapping( "/" + getRestServicesPath() + "/*", "cxf" );
|
||||
|
||||
context.addEventListener( contextLoaderListener );
|
||||
tomcat.start();
|
||||
|
||||
ServletHolder sh = new ServletHolder( CXFServlet.class );
|
||||
|
||||
SessionHandler sessionHandler = new SessionHandler();
|
||||
|
||||
context.setSessionHandler( sessionHandler );
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue