Writing “clean” integration tests - REST using jersey 2 and Spring

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Writing “clean” integration tests - REST using jersey 2 and Spring

Arun Menon
Hi,

  I am looking for suggestions for a problem I face while  writing  integration tests for a Jersey REST service. Following is the problem description.

I would like the test case written below to be a "clean" test i.e automatically rollback database changes after the test.

@Test
public void testUpdate(){
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.register(JacksonFeature.class);
    Client client = ClientBuilder.newClient(clientConfig);
    Name name = new Name(1L,"Updated","Updated");
    Response response = client
            .target("http://localhost:8080/jersey-spring/name/").request().header("Content-type", MediaType.APPLICATION_JSON).post(Entity.json(name));
    Assert.assertTrue(response.getStatus() == 200);
}

The rest services are deployed using jetty-maven-plugin during integration tests. The problem I am facing now is that I cannot use spring test transactional tests which means that any state changes to the database needs to be cleaned up manually after tests which is very cumbersome.

What is a suggested approach to run "clean" integration tests when using jersey as REST implementation(if it is possible). I have tried using JerseyTest as well and also face the same problem.



Thanks for help.

Regards,
Arun Menon




Loading...