简体   繁体   中英

JAX-RS with Jersey: Testing REST service deployed in weblogic/JBoss

I am trying to test a REST service using Jersey Test Framework with maven. When I run tests with mvn test , it runs them on Grizzly Web Server and gives lots of ClassNotFoundException . The service internally calls EJB and other SOAP services. I am able to resolve few by adding dependency in pom.xml but I feel it is very cumbersome task to resolve dependencies.

If I deploy the service in weblogic and test it with SoapUI , it works fine. No ClassNotFoundException found. Wouldn't it be possible to test the rest API which I used to deploy in weblogic?

I would very appreciate if someone help me to workout.

Thanks, Amit Patel

Yes, it is possible - you can use ExternalTestContainer and point it to url where is your app deployed.

You'll need to add dependency:

       <dependency>
            <groupId>com.sun.jersey.jersey-test-framework</groupId>
            <artifactId>jersey-test-framework-external</artifactId>
            <version>${jersey.version}</version>
            <scope>test</scope>
       </dependency>

and run your tests like:

mvn test -Djersey.test.containerFactory=com.sun.jersey.test.framework.spi.container.external.ExternalTestContainerFactory -Djersey.test.host=$appBaseUri -Djersey.test.port=$appPort

you can omit "jersey.test.containerFactory" settings if this is only test framework module declared in your pom.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM