PersonAddressController extends BaseController implements CrudController<PersonAddressResource, PersonAddressResource> { @Override @ResponseStatus(HttpStatus.OK) @RequestMapping(value = "/{personId}/addresses/{addressId}", method = RequestMethod.GET) @ApiOperation(value = "Method for getting person address by id") public PersonAddressResource getResource(@PathVariable("addressId") final Long addressId) { LOG.info("Getting person address({})", addressId); return facade.getResource(addressId); }  @Override @ResponseStatus(HttpStatus.CREATED) @RequestMapping(value = "/{personId}/addresses", method = RequestMethod.POST) @ApiOperation(value = "Method for creating person address") PersonAddressResource createResource(@Valid @RequestBody final PersonAddressResource resource); @Override @ResponseStatus(HttpStatus.OK) @RequestMapping(value = "/{personId}/addresses/{addressId}", method = RequestMethod.PUT) @ApiOperation(value = "Method for updating person address") MessageResource updateResource(@PathVariable("addressId") final Long addressId,
			@Valid @RequestBody final PersonAddressResource resource); @Override @ResponseStatus(HttpStatus.NO_CONTENT) @RequestMapping(value = "/{personId}/addresses/{addressId}", method = RequestMethod.DELETE) @ApiOperation(value = "Method for deleting person address") MessageResource removeResource(@PathVariable("addressId") final Long addressId); @Override @ResponseStatus(HttpStatus.OK) @RequestMapping(value = "/{personId}/addresses/{addressId}", method = RequestMethod.GET) @ApiOperation(value = "Method for getting person address by id") PersonAddressResource getResource(@PathVariable("addressId") final Long addressId); @Override @ResponseStatus(HttpStatus.OK) @RequestMapping(value = "/{personId}/addresses", method = RequestMethod.GET) @ApiOperation(value = "Method for getting paged result.") PagedResultResource<PersonAddressResource> getPagedResource(final PagedRequest<PersonAddressResource> request);  }
@Test public void testGetAddress() throws Exception { Long personId = 1L; Long id = 2L; PersonAddressResource personAddressResource = new PersonAddressResource(); personAddressResource.setId(id); personAddressResource.setPersonId(personId); String response = getJson(personAddressResource, false); when(facade.getResource(anyLong())).thenReturn(personAddressResource); mockMvc.perform(get("/persons/{personId}/addresses/{addressId}", 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}/addresses/{id}", personId, id)); verify(facade).getResource(id); }