DegreeController extends BaseController implements CrudController<DegreeResource, DegreeResource> { @Override @ResponseStatus(HttpStatus.OK) @RequestMapping(value = "/degrees/{id}", method = RequestMethod.GET) public DegreeResource getResource(@PathVariable("id") final Long id) { LOGGER.info("Getting degree by id: {}", id); return facade.getResource(id); }  @Override @ResponseStatus(HttpStatus.OK) @RequestMapping(value = { "/degrees", "/persons/{personId}/degrees" }, method = RequestMethod.GET) PagedResultResource<DegreeResource> getPagedResource(final PagedRequest<DegreeResource> request); @Override @ResponseStatus(HttpStatus.OK) @RequestMapping(value = "/degrees/{id}", method = RequestMethod.GET) DegreeResource getResource(@PathVariable("id") final Long id); @Override @ResponseStatus(HttpStatus.CREATED) @RequestMapping(value = "/degrees", method = RequestMethod.POST) DegreeResource createResource(@Valid @RequestBody final DegreeResource resource); @Override @ResponseStatus(HttpStatus.OK) @RequestMapping(value = "/degrees/{id}", method = RequestMethod.PUT) MessageResource updateResource(@PathVariable("id") final Long id,
			@Valid @RequestBody final DegreeResource resource); @Override @ResponseStatus(HttpStatus.NO_CONTENT) @RequestMapping(value = "/degrees/{id}", method = RequestMethod.DELETE) MessageResource removeResource(@PathVariable("id") final Long id);  }
@Test public void testGetResourceById() throws Exception { Long id = 1L; DegreeResource benefitResource = new DegreeResource(); benefitResource.setId(id); String response = getJson(benefitResource, false); when(facade.getResource(anyLong())).thenReturn(benefitResource); mockMvc.perform(get("/degrees/{id}", id)) .andExpect(status().isOk()) .andExpect(content().string(response)); verify(facade).getResource(id); }
@Test(expected = AccessDeniedException.class) public void testGetResourceWithAccessDeniedException() throws Exception { Long id = 1L; doThrow(AccessDeniedException.class).when(facade).getResource(anyLong()); mockMvc.perform(get("/degrees/{id}", id)); verify(facade).getResource(id); }