I need to write a junit test case for REST API.Am new to Junit test case can anyone help me to understand and write the test cases for REST APIs. Note: REST Application is NOT a spring based application.
@Path("/watchlistService") public class sample {
private static final MCPLogger LOGGER =
MCPLoggerFactory.getLogger(WatchlistServiceAPI.class);
@Inject
private Config configModel;
@Inject
private UIConfig configUIModel;
@EJB
private CaseDatabaseBean caseDatabase;
@EJB
IDBAccess dbAccess;
@EJB
WatchlistServiceBean watchlistService;
@EJB
private IWatchlistSecurity watchlistSecurity;
@EJB
private TrackBean trackBean;
@EJB
IWatchlistAccess watchlistAccess;
@EJB
private DBModelValidationBean modelValidation;
@EJB
private IMVIAuditLogger mviAuditLogger;
ThreadLocal<Integer> threadLocalValue = new ThreadLocal<>();
private String getRequestUserName( @Context HttpServletRequest req )
{
return req.getUserPrincipal() == null ? "null" :
req.getUserPrincipal().getName();
}
@GET
@Path("/personattributes")
@Produces("application/json;charset=utf-8")
public Response getWatchlistPersonAttributes(@Context HttpServletRequest req) {
try {
JSONObject jsonPAttr = new JSONObject();
JSONArray jsonAttributes = new JSONArray();
for(WatchlistPersonAttribute attribute :
watchlistAccess.getPersonAttributes()) {
JSONObject jsonAttribute = new JSONObject();
jsonAttribute.put("name", attribute.name);
jsonAttribute.put("type", attribute.type.toString());
jsonAttribute.put("required", attribute.required);
jsonAttributes.put(jsonAttribute);
}
jsonPAttr.put("attributes", jsonAttributes);
WatchlistPersonDescriptor descriptor =
watchlistAccess.getPersonDescriptor();
jsonPAttr.put("descriptor", descriptor.descriptor);
JSONArray jsonDescriptorArguments = new JSONArray();
for(int i = 0; i < descriptor.arguments.length; ++i) {
jsonDescriptorArguments.put(descriptor.arguments[i]);
}
jsonPAttr.put("descriptorArguments", jsonDescriptorArguments);
return Response.status(200).entity(jsonPAttr.toString()).build();
} catch (Exception e) {
return getReturnError("Couldn't retreive watchlist person attributes: " + e.getMessage());
}
}
}
I need to write a junit test case for REST API.Am new to Junit test case can anyone help me to understand and write the test cases for REST APIs. Note: REST Application is NOT a spring based application.
Aucun commentaire:
Enregistrer un commentaire