I have scoured the Internet and unfortunately found no solution to my problem. I am trying to create a full test framework for my REST API service. What I want to do is:
- Provide a set of REST processing classes that the test cases can call for sending request and receiving response.
- Create all application POJO classes which the test case can initialize and pass the objects to the REST Processors
I cannot seem to get a good layout of classes to do this. This is what I have so far; In each of the POJO classes I have created a method like-
public String objectToJSON(MyPOJO requestJSONObject) {
ObjectMapper mapperInstance = new ObjectMapper();
return mapperInstance.writeValueAsString(requestJSONObject);
}
And my REST processor for say, handling POST requests looks like-
public ClientResponse execRequest(Authorization authInstance, Object requestPOJO) {
return webResourceInstance.type(MediaType.APPLICATION_JSON).header("Authorization",
encode(authInstance)).post(ClientResponse.class, **requestPOJO**);
}
This requestPOJO object in the post() method is creating a problem, in that my REST Processor never knows what type of Object it is handling and as a consequence the objectToJSON() method is never really visible.
I could implement the REST API code in the POJO itself but that doesn't sound like a very good idea. I am looking for a full framework design example on how I might go around laying out my classes for this framework.
Aucun commentaire:
Enregistrer un commentaire