@Test public void shouldCreateCHW() throws Exception { Agent agent = mock(Agent.class); ResponseEntity<RestResponse> expectResponse = new ResponseEntity<>(new RestResponse(), HttpStatus.OK); when(RestResponse.success("message.success.agent.created")).thenReturn(expectResponse); ResponseEntity<RestResponse> response = restAgentController.createCHW(agent, principal); verify(restAgentService).create(agent, 1L); assertThat(response, is(expectResponse)); }
@RequestMapping(value = "/rest-api/agents", method = POST, headers = ACCEPT_JSON) public ResponseEntity<RestResponse> createCHW(@RequestBody Agent agent, Principal principal) { try { restAgentService.create(agent, loggedInUserId(principal)); return success("message.success.agent.created"); } catch (DataException e) { return error(e.getOpenLmisMessage(), BAD_REQUEST); } }
RestAgentController extends BaseController { @RequestMapping(value = "/rest-api/agents", method = POST, headers = ACCEPT_JSON) public ResponseEntity<RestResponse> createCHW(@RequestBody Agent agent, Principal principal) { try { restAgentService.create(agent, loggedInUserId(principal)); return success("message.success.agent.created"); } catch (DataException e) { return error(e.getOpenLmisMessage(), BAD_REQUEST); } } }
RestAgentController extends BaseController { @RequestMapping(value = "/rest-api/agents", method = POST, headers = ACCEPT_JSON) public ResponseEntity<RestResponse> createCHW(@RequestBody Agent agent, Principal principal) { try { restAgentService.create(agent, loggedInUserId(principal)); return success("message.success.agent.created"); } catch (DataException e) { return error(e.getOpenLmisMessage(), BAD_REQUEST); } }  }
RestAgentController extends BaseController { @RequestMapping(value = "/rest-api/agents", method = POST, headers = ACCEPT_JSON) public ResponseEntity<RestResponse> createCHW(@RequestBody Agent agent, Principal principal) { try { restAgentService.create(agent, loggedInUserId(principal)); return success("message.success.agent.created"); } catch (DataException e) { return error(e.getOpenLmisMessage(), BAD_REQUEST); } }  @RequestMapping(value = "/rest-api/agents", method = POST, headers = ACCEPT_JSON) ResponseEntity<RestResponse> createCHW(@RequestBody Agent agent, Principal principal); @RequestMapping(value = "/rest-api/agents/{agentCode}", method = PUT, headers = ACCEPT_JSON) ResponseEntity<RestResponse> updateCHW(@RequestBody Agent agent,
                                                @PathVariable String agentCode,
                                                Principal principal); }
RestAgentController extends BaseController { @RequestMapping(value = "/rest-api/agents", method = POST, headers = ACCEPT_JSON) public ResponseEntity<RestResponse> createCHW(@RequestBody Agent agent, Principal principal) { try { restAgentService.create(agent, loggedInUserId(principal)); return success("message.success.agent.created"); } catch (DataException e) { return error(e.getOpenLmisMessage(), BAD_REQUEST); } }  @RequestMapping(value = "/rest-api/agents", method = POST, headers = ACCEPT_JSON) ResponseEntity<RestResponse> createCHW(@RequestBody Agent agent, Principal principal); @RequestMapping(value = "/rest-api/agents/{agentCode}", method = PUT, headers = ACCEPT_JSON) ResponseEntity<RestResponse> updateCHW(@RequestBody Agent agent,
                                                @PathVariable String agentCode,
                                                Principal principal);  }