I looking at the following code which tests a REST Endpoint:
Response response = server.newRequest("/myresource").request().buildPost(Entity.text("42")).invoke();
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
MyModel myModel = response.readEntity(MyModel.class);
assertEquals(42, myModel.getResult());
as outlined here:
I'm wondering though is it best to convert the response to a MyModel object and apply the tests on this object. I would be more inclined to do this:
JSONObject expectedResponse = new JSONObject();
expectedResponse.put("name", "mkyong.com");
expectedResponse.put("age", new Integer(100));
assert(response, expectedResponse);
What are your opinions?
Aucun commentaire:
Enregistrer un commentaire