mardi 15 décembre 2015

How to write a test to resource which uses JSON body as params in Jackson?

Like in the topic, does anyone know how to do it? I didn't see any api or tutorial how to do it. My sample resource:

@Path("/tests")
@Consumes("application/json")
@Produces("application/json")
public class TestResource {
    private final SomeDAO dao;
    public TestResource(SomeDAO dao) {
        this.dao = dao;
    }

    public static class RequestBody {
        @JsonProperty("p1")
        public String p1;

        @JsonProperty("p2")
        public String p2;
    }
    @POST
    @UnitOfWork
    public Saying postSomething(RequestBody requestBody) {
        Thing thing = dao.create(new Thing(requestBody.p1, requestBody.p2));
        return new Saying("Added : " + actor.toString());
        //Saying is the representation of JSON response
    }

Aucun commentaire:

Enregistrer un commentaire