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