lundi 25 janvier 2016

Jersey unit test of call to rest with path parameters returns 404

I'm using Jersey version 2.22 in a Java application to create a REST service.

I have a get method in class AResource like the following:

@Get
@Path("/xxx/{value1}")
@Produces(MediaType.APPLICATION_JSON)
Response doSomething(@PathParam("value1") String v1){
   return Response.status(OK).entity("{}").build();
}

and then the unit test is:

public class AResourceTest extends JerseyTest {

    @Override
    protected Application configure() {
        return new ResourceConfig(AResource.class);
    }

    @Test
    public void testJson() throws Exception {
        String output = target(BASE_PATH + "/xxx/{value1}").resolveTemplate("value1", "a_value").request()
                                                             .accept(APPLICATION_JSON_TYPE).get(String.class);
    }

}

So I get:

javax.ws.rs.NotFoundException: HTTP 404 Not Found

    at org.glassfish.jersey.client.JerseyInvocation.convertToException(JerseyInvocation.java:1008)

Funny thing is that I can get from another url with no parameters. What am I doing wrong?

Aucun commentaire:

Enregistrer un commentaire