EnrolmentStatusController extends BaseController implements CrudController<EnrolmentStatusResource, EnrolmentStatusResource> { @Override @ResponseStatus(HttpStatus.OK) @RequestMapping(value = "/{enrolmentId}/statuses/{id}", method = RequestMethod.GET) public EnrolmentStatusResource getResource(@PathVariable("id") final Long id) { LOG.info("Retrieving enrolment status with id : {} ", id); return facade.getResource(id); }  @Override @ResponseStatus(HttpStatus.CREATED) @RequestMapping(value = "/{enrolmentId}/statuses", method = RequestMethod.POST) EnrolmentStatusResource createResource(@Valid @RequestBody final EnrolmentStatusResource enrolmentResource); @Override @ResponseStatus(HttpStatus.OK) @RequestMapping(value = "/{enrolmentId}/statuses/{id}", method = RequestMethod.PUT) MessageResource updateResource(@PathVariable("id") final Long id, 
			@Valid @RequestBody final EnrolmentStatusResource resource); @Override @ResponseStatus(HttpStatus.OK) @RequestMapping(value = "/{enrolmentId}/statuses/{id}", method = RequestMethod.GET) EnrolmentStatusResource getResource(@PathVariable("id") final Long id); @Override @ResponseStatus(HttpStatus.NO_CONTENT) @RequestMapping(value = "/{enrolmentId}/statuses/{id}", method = RequestMethod.DELETE) MessageResource removeResource(@PathVariable("id") final Long id); @Override @ResponseStatus(HttpStatus.OK) @RequestMapping(value = "/{enrolmentId}/statuses", method = RequestMethod.GET) PagedResultResource<EnrolmentStatusResource> getPagedResource(final PagedRequest<EnrolmentStatusResource> request);  }
@Test public void testGetEnrolmentStatus() throws Exception { Long id = 1L; Long enrolmentId = 2L; EnrolmentStatusResource enrolmentResource = new EnrolmentStatusResource(); enrolmentResource.setId(id); enrolmentResource.setEnrolmentId(enrolmentId); String response = getJson(enrolmentResource, false); when(facade.getResource(anyLong())).thenReturn(enrolmentResource); mockMvc.perform( get("/enrolments/{enrolmentId}/statuses/{id}", enrolmentId, id)) .andExpect(status().isOk()) .andExpect(content().string(response)); verify(facade).getResource(id); }
@Test(expected = AccessDeniedException.class) public void testGetResourceWithAccessDeniedException() throws Exception { Long id = 1L; Long enrolmentId = 2L; doThrow(AccessDeniedException.class).when(facade) .getResource(anyLong()); mockMvc.perform(get("/enrolments/{enrolmentId}/statuses/{id}", enrolmentId, id)); verify(facade).getResource(id); }