I want my jersey tests to run on one instance of tomcat which has the rest services running at
http://myhost:port/contexpath/service1/
http://myhost:port/con
If you have your external servlet:
Import the jersey-test-framework-core apis to implement your own TestContainerFactory
testCompile 'org.glassfish.jersey.test-framework:jersey-test-framework-core:2.22.2'
.
Let JerseyTest know you will have your own provider through SystemProperties
systemProperty 'jersey.config.test.container.factory', 'my.package.MyTestContainerFactory'
.
Create your own provider (better and more custom configurable than their jersey-test-framework-provider-external
)
import org.glassfish.jersey.test.spi.TestContainer;
import org.glassfish.jersey.test.spi.TestContainerFactory;
public class MyTestContainerFactory implements TestContainerFactory {
@Override
public TestContainer create(URI baseUri, DeploymentContext deploymentContext) {
return new TestContainer(){
@Override
public ClientConfig getClientConfig() {
return null;
}
@Override
public URI getBaseUri() {
return URI.create("http://localhost:8080/myapp/api");
}
@Override
public void start() {
// Do nothing
}
@Override
public void stop() {
// Do nothing
}
};
}
}
Finally I figured out a solution
@Override
public TestContainerFactory getTestContainerFactory() {
return new ExternalTestContainerFactory(){
@Override
public TestContainer create(URI baseUri, DeploymentContext context)
throws IllegalArgumentException {
try {
baseUri = new URI("http://localhost:8000/contextpath");
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return super.create(baseUri, context);
}
};
}