How to specify context path for jersey test with external provider

后端 未结 2 2009
梦毁少年i
梦毁少年i 2021-01-26 01:52

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         


        
2条回答
  •  不要未来只要你来
    2021-01-26 02:41

    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
                }
            };
        }
    }
    

提交回复
热议问题