如何为外部提供商指定球衣测试的上下文路径 [英] How to specify context path for jersey test with external provider
问题描述
我希望我的球衣测试在tomcat的一个实例上运行,该实例的其余服务在
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/contexpath/service2/
..so on
我既有内存依赖又有外部容器依赖
I have both in memory and external container dependencies
[ group: 'org.glassfish.jersey.test-framework.providers', name: 'jersey-test-framework-provider-inmemory', version: '2.17'],
[group: 'org.glassfish.jersey.test-framework.providers', name: 'jersey-test-framework-provider-external' , version: '2.17'],
然后在测试中,我将使用以下方法来决定选择哪个容器
Then in the test i over ride the below method to decide which container to choose
@Override
public TestContainerFactory getTestContainerFactory() {
System.setProperty("jersey.test.host", "localhost");
System.setProperty("jersey.config.test.container.port", "8000");
//how to set the context path ??
return new ExternalTestContainerFactory();
}
内存中测试之所以有效,是因为服务是由框架在其知道的路径中部署的(无论如何它都没有上下文路径) 当我在外部容器上运行时,它尝试连接到 http://myhost:port/service1/而不是 http://myhost:port/contexpath/service1/从而找不到404
The in memory test works because the services are deployed by the framework at path which it knows(it does not have a context path anyway) When i run on external container it tries to connect to http://myhost:port/service1/ instead of http://myhost:port/contexpath/service1/ thus getting 404 not found
要在外部容器上运行,如何指定上下文路径? 该文档仅指定主机和端口属性.上下文路径是否有任何属性?
To run on an external container how do i specify the context path ? The documentation specifies only host and port property.Is there any property for context path ?
我正在使用Jersey 2.17
I am using Jersey 2.17
推荐答案
最后我想出了一个解决方案
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);
}
};
}
这篇关于如何为外部提供商指定球衣测试的上下文路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!