Selvakumar Ponnusamy Selvakumar Ponnusamy - 5 months ago 33
Java Question

Junit CXF REST API and rollback test data

I would like to write Junit test cases for REST API. The APIs are written using CXF framework.




<jaxrs:server id="/SomeAction" address="/SomeAction" staticSubresourceResolution="true" publishedEndpointUrl="${endpointUrl}/SomeAction">
<ref bean="SomeWebService"></ref>
<ref bean="jsonProvider"></ref>
<ref bean="exceptionMapper"></ref>



public WSResponse doSome(WSRequest request) {
//Do Some operation


public void testDoSome()
throws Exception {

I can write Junit test cases for simple REST API and rollback the data after test is done using spring test. But I couldn't write when CXF framework is involved. I have two issues here.

  • The above Junit code returns 404 response instead of 200.

  • I want to
    rollback the data when test is done

Pleas help me to resolve the issues


As the name implies, the Spring MVC Test Framework is for testing Spring MVC Web and Spring MVC REST applications.

You are writing a CXF REST application which is based on JAX-RS.

Spring MVC REST is not an implementation of JAX-RS.

It is therefore not possible to test a JAX-RS application with Spring MVC Test (i.e., MockMvc).

To test your JAX-RS endpoints, you will need to use a testing framework with dedicated support for JAX-RS. For example, you may want to use the JAX-RS Testing support from CXF, or you can Google "jax-rs testing" to find other solutions.