vendredi 29 juillet 2016

How to write a proper Junit test for this Rest client controller

I know that this is very bold question, but maybe someone can at least lead on the correct way....

  @RequestMapping(value = "/check", method = RequestMethod.POST)
        public String checkUser(@ModelAttribute(value="userl") User userl)  {

        final String uri = new String(URL + "login");
        //make request to REST service and redirect to users page
         try{   
             RestTemplate restTemplate = new RestTemplate();
             ResponseEntity<User> responseEntity =  restTemplate.postForEntity(uri,userl,User.class);
             headers = responseEntity.getHeaders();
             setHeader(headers);
             User currentUser = responseEntity.getBody();
             System.out.println(currentUser.toString());
             logedUser.setUserType(currentUser.getUserType());

                    return "redirect:/users";       
            }
         //if request failed, redirect to login page
         catch(Exception e){
             e.getMessage();
             return "redirect:/";
         }                                  
    }

Aucun commentaire:

Enregistrer un commentaire