jeudi 1 septembre 2016

unit testing for spring mvc controller

I have the following controller which accept input as @RequestParam

@RequestMapping(value = "/fetchstatus", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public Response fetchStatus(
        @RequestParam(value = "userId", required = true) Integer userId) {
    Response response = new Response();
    try {
        response.setResponse(service.fetchStatus(userId));
        response = (Response) Util.getResponse(
                response, ResponseCode.SUCCESS, FETCH_STATUS_SUCCESS,
                Message.SUCCESS);
    } catch (NullValueException e) {
        e.printStackTrace();
        responseDTO = (Response) Util.getResponse(
                response, ResponseCode.FAILED, e.getMessage(), Message.ERROR);
    } catch (Exception e) {
        e.printStackTrace();
        response = (Response) Util.getResponse(
                response, ResponseCode.FAILED, e.getMessage(), Message.ERROR);
    }
    return response;
}

I need a unit test class for this and I am beginner with spring mvc. I don't know writing test classes with @RequestParam as input.

Any help will be appreciated ..

Aucun commentaire:

Enregistrer un commentaire