PersonController extends BaseController implements CrudController<PersonResource, PersonResourceList> { @Override @ResponseStatus(HttpStatus.OK) @RequestMapping(value = Request.ID, method = RequestMethod.GET) @ApiOperation(value = "Get Person by id", position = 3) public PersonResource getResource(@PathVariable("id") final Long id) { LOG.info("Retrieving person with id: {}", id); return facade.getResource(id); }  @Override @ResponseStatus(HttpStatus.CREATED) @RequestMapping(method = RequestMethod.POST) @ApiOperation(value = "Create Person", position = 1) PersonResource createResource(@Valid @RequestBody final PersonResource personResource); @Override @ResponseStatus(HttpStatus.OK) @RequestMapping(value = Request.ID, method = RequestMethod.PUT) @ApiOperation(value = "Update Person", position = 2) MessageResource updateResource(@PathVariable("id") final Long id,
			@Valid @RequestBody final PersonResource personResource); @Override @ResponseStatus(HttpStatus.OK) @RequestMapping(value = Request.ID, method = RequestMethod.GET) @ApiOperation(value = "Get Person by id", position = 3) PersonResource getResource(@PathVariable("id") final Long id); @Override @ResponseStatus(HttpStatus.NO_CONTENT) @RequestMapping(value = Request.ID, method = RequestMethod.DELETE) @ApiOperation(value = "Delete Person", position = 4) MessageResource removeResource(@PathVariable("id") final Long id); @Override @ResponseStatus(HttpStatus.OK) @RequestMapping(method = RequestMethod.GET) @ApiOperation(value = "Get Persons") PagedResultResource<PersonResource> getPagedResource(final PagedRequest<PersonResourceList> request);  }
@Test public void testGetResource() throws Exception { Long id = 1L; String docNum = "docNum"; PersonResource personResource = new PersonResource(); personResource.setId(id); personResource.setBegDate(new Date()); personResource.setDocNum(docNum); String response = getJson(personResource, false); when(facade.getResource(anyLong())).thenReturn(personResource); mockMvc.perform(get("/persons/{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("/persons/{id}", id)); verify(facade).getResource(id); }