PersonWorkController extends BaseController implements CrudController<PersonWorkResource, PersonWorkResource> { @Override @ResponseStatus(HttpStatus.OK) @RequestMapping(value = "/{personId}/works/{id}", method = RequestMethod.GET) public PersonWorkResource getResource(@PathVariable("id") final Long id) { LOG.info("Retrieving person work with id: {}", id); return facade.getResource(id); }  @Override @ResponseStatus(HttpStatus.CREATED) @RequestMapping(value = "/{personId}/works", method = RequestMethod.POST) PersonWorkResource createResource(@Valid @RequestBody final PersonWorkResource resource); @Override @ResponseStatus(HttpStatus.OK) @RequestMapping(value = "/{personId}/works/{id}", method = RequestMethod.PUT) MessageResource updateResource(@PathVariable("id") final Long id,
			@Valid @RequestBody final PersonWorkResource resource); @Override @ResponseStatus(HttpStatus.OK) @RequestMapping(value = "/{personId}/works/{id}", method = RequestMethod.GET) PersonWorkResource getResource(@PathVariable("id") final Long id); @Override @ResponseStatus(HttpStatus.NO_CONTENT) @RequestMapping(value = "/{personId}/works/{id}", method = RequestMethod.DELETE) MessageResource removeResource(@PathVariable("id") final Long id); @Override @ResponseStatus(HttpStatus.OK) @RequestMapping(value = "/{personId}/works", method = RequestMethod.GET) PagedResultResource<PersonWorkResource> getPagedResource(final PagedRequest<PersonWorkResource> request);  }
@Test public void testGetWork() throws Exception { Long personId = 1L; Long id = 2L; PersonWorkResource personWorkResource = new PersonWorkResource(); personWorkResource.setId(id); personWorkResource.setPersonId(personId); String response = getJson(personWorkResource, false); when(facade.getResource(anyLong())).thenReturn( personWorkResource); mockMvc.perform( get("/persons/{personId}/works/{workId}", personId, 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 personId = 2L; doThrow(AccessDeniedException.class).when(facade) .getResource(anyLong()); mockMvc.perform(get("/persons/{personId}/works/{id}", personId, id)); verify(facade).getResource(id); }