testing - how to test an REST app (built with apache-cxf) with jersey-test-framework -



know how can test rest application, developed using apache cxf , spring, jersey test framework (jtf).

the application made of several maven modules, of "app-rest" 1 integrates them , exposes rest interface tested.

i've made separate maven module contains tests, has "app-rest" dependency, i'm receiving exception :

beandefinitionstoreexception: ioexception parsing xml document class path resource   

when running tests.
think that's because app-rest not deployed in embedded container.

i've tried put tests "app-rest" module, instead :

runtimeexception: scope of component class org.apache.cxf.jaxrs.provider.atomfeedprovider must singleton 

i'm running test command line:

mvn test -dtest=jerseyresttest -djersey.test.containerfactory=com.sun.jersey.test.framework.spi.container.grizzly.web.grizzlywebtestcontainerfactory 

these pom.xml file tests module:

<project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">       <modelversion>4.0.0</modelversion>     <parent>         <groupid>project-group-id</groupid>         <artifactid>projectname</artifactid>         <version>1.0.0-snapshot</version>     </parent>     <groupid>project-group-id</groupid>     <artifactid>integration-tests</artifactid>     <version>1.0.0-snapshot</version>     <packaging>jar</packaging>     <name>integration tests of rest interface</name>     <!-- build -->     <build>         <finalname>${project.artifactid}</finalname>     </build>     <!-- additional repositories -->     <repositories>         <repository>             <id>java.net.m2</id>             <url>http://download.java.net/maven/2/</url>         </repository>     </repositories>     <dependencies>         <dependency>             <groupid>project-group-id</groupid>             <artifactid>app-rest</artifactid>             <version>1.0.0-snapshot</version>             <type>war</type>             <scope>test</scope>         </dependency>         <!-- junit -->         <dependency>             <groupid>junit</groupid>             <artifactid>junit</artifactid>             <version>4.8.2</version>             <scope>test</scope>         </dependency>         <!-- jersey stuff -->         <dependency>             <groupid>com.sun.jersey</groupid>             <artifactid>jersey-server</artifactid>             <version>1.6</version>             <scope>test</scope>         </dependency>         <dependency>             <groupid>com.sun.jersey.jersey-test-framework</groupid>             <artifactid>jersey-test-framework-grizzly</artifactid>             <version>1.6</version>             <scope>test</scope>         </dependency>         <dependency>             <groupid>com.sun.jersey.contribs</groupid>             <artifactid>jersey-spring</artifactid>             <version>1.6</version>             <scope>test</scope>         </dependency>     </dependencies> </project> 

the simple test is:

public class jerseyresttest extends jerseytest {     public jerseyresttest() {         super(new webappdescriptor.builder("projectname.resource")                 .servletclass(springservlet.class)                 .contextparam("contextconfiglocation", "classpath:meta-inf/spring/context-rest.xml")                 .contextlistenerclass(org.springframework.web.context.contextloaderlistener.class)                 .contextpath("app-rest")                 .build());     }      @test     public void testsomeresource() {         string response = resource().path("/rest/resources").get(string.class);         assert.assertnotnull("no text returned!", response);          assertresponsecontains(response, "<html>");         assertresponsecontains(response, "</html>");     }      protected void assertresponsecontains(string response, string text) {         assert.asserttrue("response should contain " + text + " was: " + response, response.contains(text));     } } 

thank much!


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -