@Test public void testUpdateUser() throws Exception { final User user = new User(); user.setId("1"); user.setEmail("bhdrkn@gmail.com"); user.setUsername("bhdrkn"); user.setPassword("1q2w3e"); Mockito.when(userService.updateUser(Mockito.eq("1"), Mockito.any(User.class))).thenReturn(user); mockMvc.perform(MockMvcRequestBuilders.put("/rest/users/1") .content("{\"username\":\"bhdrkn\",\"password\":\"1q2w3e\",\"email\":\"bhdrkn@gmail.com\"}") .contentType(MediaType.APPLICATION_JSON)) .andExpect(MockMvcResultMatchers.jsonPath("$.username", Matchers.is("bhdrkn"))) .andExpect(MockMvcResultMatchers.jsonPath("$.password",Matchers.is("1q2w3e"))) .andExpect(MockMvcResultMatchers.jsonPath("$.id",Matchers.is("1"))) .andExpect(MockMvcResultMatchers.jsonPath("$.email",Matchers.is("bhdrkn@gmail.com"))) .andExpect(MockMvcResultMatchers.status().isOk()); }
@RequestMapping(value="/{id}",method = RequestMethod.PUT) public ResponseEntity<User> updateUser(@PathVariable String id, @RequestBody User user){ try { final User dbuser = userService.updateUser(id, user); return new ResponseEntity<User>(dbuser, HttpStatus.OK); }catch (Exception e){ return new ResponseEntity<User>(HttpStatus.BAD_REQUEST); } }
UserController implements Serializable { @RequestMapping(value="/{id}",method = RequestMethod.PUT) public ResponseEntity<User> updateUser(@PathVariable String id, @RequestBody User user){ try { final User dbuser = userService.updateUser(id, user); return new ResponseEntity<User>(dbuser, HttpStatus.OK); }catch (Exception e){ return new ResponseEntity<User>(HttpStatus.BAD_REQUEST); } } }
UserController implements Serializable { @RequestMapping(value="/{id}",method = RequestMethod.PUT) public ResponseEntity<User> updateUser(@PathVariable String id, @RequestBody User user){ try { final User dbuser = userService.updateUser(id, user); return new ResponseEntity<User>(dbuser, HttpStatus.OK); }catch (Exception e){ return new ResponseEntity<User>(HttpStatus.BAD_REQUEST); } } @Autowired  UserController(UserService userService); }
UserController implements Serializable { @RequestMapping(value="/{id}",method = RequestMethod.PUT) public ResponseEntity<User> updateUser(@PathVariable String id, @RequestBody User user){ try { final User dbuser = userService.updateUser(id, user); return new ResponseEntity<User>(dbuser, HttpStatus.OK); }catch (Exception e){ return new ResponseEntity<User>(HttpStatus.BAD_REQUEST); } } @Autowired  UserController(UserService userService); @RequestMapping(method=RequestMethod.GET) ResponseEntity<List<User>> findAll(); @RequestMapping(method = RequestMethod.POST) ResponseEntity<User> createUser(@RequestBody User user); @RequestMapping(value="/{id}",method = RequestMethod.GET) ResponseEntity<User> getUser(@PathVariable String id); @RequestMapping(value="/{id}",method = RequestMethod.PUT) ResponseEntity<User> updateUser(@PathVariable String id, @RequestBody User user); @RequestMapping(value="/{id}",method = RequestMethod.DELETE) ResponseEntity<User> deleteUser(@PathVariable String id, @RequestBody User user); }
UserController implements Serializable { @RequestMapping(value="/{id}",method = RequestMethod.PUT) public ResponseEntity<User> updateUser(@PathVariable String id, @RequestBody User user){ try { final User dbuser = userService.updateUser(id, user); return new ResponseEntity<User>(dbuser, HttpStatus.OK); }catch (Exception e){ return new ResponseEntity<User>(HttpStatus.BAD_REQUEST); } } @Autowired  UserController(UserService userService); @RequestMapping(method=RequestMethod.GET) ResponseEntity<List<User>> findAll(); @RequestMapping(method = RequestMethod.POST) ResponseEntity<User> createUser(@RequestBody User user); @RequestMapping(value="/{id}",method = RequestMethod.GET) ResponseEntity<User> getUser(@PathVariable String id); @RequestMapping(value="/{id}",method = RequestMethod.PUT) ResponseEntity<User> updateUser(@PathVariable String id, @RequestBody User user); @RequestMapping(value="/{id}",method = RequestMethod.DELETE) ResponseEntity<User> deleteUser(@PathVariable String id, @RequestBody User user);  }