@Test public void shouldGetRegimenByProgram() { List<Regimen> expectedRegimens = new ArrayList<>(); Long programId = 1l; when(regimenService.getByProgram(programId)).thenReturn(expectedRegimens); ResponseEntity<OpenLmisResponse> response = controller.getByProgram(programId); assertThat((List<Regimen>) response.getBody().getData().get(REGIMENS), is(expectedRegimens)); verify(regimenService).getByProgram(programId); }
@RequestMapping(value = "/programId/{programId}/regimens", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_REGIMEN_TEMPLATE')") public ResponseEntity<OpenLmisResponse> getByProgram(@PathVariable("programId") Long programId) { try { ResponseEntity<OpenLmisResponse> response; List<Regimen> regimens = regimenService.getByProgram(programId); response = response(REGIMENS, regimens); return response; } catch (DataException dataException) { return error(UNEXPECTED_EXCEPTION, HttpStatus.BAD_REQUEST); } }
RegimenController extends BaseController { @RequestMapping(value = "/programId/{programId}/regimens", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_REGIMEN_TEMPLATE')") public ResponseEntity<OpenLmisResponse> getByProgram(@PathVariable("programId") Long programId) { try { ResponseEntity<OpenLmisResponse> response; List<Regimen> regimens = regimenService.getByProgram(programId); response = response(REGIMENS, regimens); return response; } catch (DataException dataException) { return error(UNEXPECTED_EXCEPTION, HttpStatus.BAD_REQUEST); } } }
RegimenController extends BaseController { @RequestMapping(value = "/programId/{programId}/regimens", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_REGIMEN_TEMPLATE')") public ResponseEntity<OpenLmisResponse> getByProgram(@PathVariable("programId") Long programId) { try { ResponseEntity<OpenLmisResponse> response; List<Regimen> regimens = regimenService.getByProgram(programId); response = response(REGIMENS, regimens); return response; } catch (DataException dataException) { return error(UNEXPECTED_EXCEPTION, HttpStatus.BAD_REQUEST); } }  }
RegimenController extends BaseController { @RequestMapping(value = "/programId/{programId}/regimens", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_REGIMEN_TEMPLATE')") public ResponseEntity<OpenLmisResponse> getByProgram(@PathVariable("programId") Long programId) { try { ResponseEntity<OpenLmisResponse> response; List<Regimen> regimens = regimenService.getByProgram(programId); response = response(REGIMENS, regimens); return response; } catch (DataException dataException) { return error(UNEXPECTED_EXCEPTION, HttpStatus.BAD_REQUEST); } }  @Transactional @RequestMapping(value = "/programId/{programId}/regimens", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_REGIMEN_TEMPLATE')") ResponseEntity<OpenLmisResponse> save(@PathVariable Long programId, @RequestBody RegimenFormDTO regimenFormDTO, HttpServletRequest request); @RequestMapping(value = "/programId/{programId}/regimens", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_REGIMEN_TEMPLATE')") ResponseEntity<OpenLmisResponse> getByProgram(@PathVariable("programId") Long programId); @RequestMapping(value = "/regimenCategories", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_REGIMEN_TEMPLATE')") ResponseEntity<OpenLmisResponse> getAllRegimenCategories(); }
RegimenController extends BaseController { @RequestMapping(value = "/programId/{programId}/regimens", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_REGIMEN_TEMPLATE')") public ResponseEntity<OpenLmisResponse> getByProgram(@PathVariable("programId") Long programId) { try { ResponseEntity<OpenLmisResponse> response; List<Regimen> regimens = regimenService.getByProgram(programId); response = response(REGIMENS, regimens); return response; } catch (DataException dataException) { return error(UNEXPECTED_EXCEPTION, HttpStatus.BAD_REQUEST); } }  @Transactional @RequestMapping(value = "/programId/{programId}/regimens", method = POST, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_REGIMEN_TEMPLATE')") ResponseEntity<OpenLmisResponse> save(@PathVariable Long programId, @RequestBody RegimenFormDTO regimenFormDTO, HttpServletRequest request); @RequestMapping(value = "/programId/{programId}/regimens", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_REGIMEN_TEMPLATE')") ResponseEntity<OpenLmisResponse> getByProgram(@PathVariable("programId") Long programId); @RequestMapping(value = "/regimenCategories", method = GET, headers = ACCEPT_JSON) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_REGIMEN_TEMPLATE')") ResponseEntity<OpenLmisResponse> getAllRegimenCategories(); static final String REGIMENS_SAVED_SUCCESSFULLY; static final String REGIMENS; static final String REGIMEN_CATEGORIES; }