DepartmentAddressController extends BaseController implements CrudController<DepartmentAddressResource, DepartmentAddressResource> { @Override @ResponseStatus(HttpStatus.OK) @RequestMapping(value = "/{departmentId}/addresses/{id}", method = RequestMethod.GET) public DepartmentAddressResource getResource(@PathVariable("id") final Long id) { LOG.info("Retrieving department address with id: {}", id); return facade.getResource(id); }  @Override @ResponseStatus(HttpStatus.CREATED) @RequestMapping(value = "/{departmentId}/addresses", method = RequestMethod.POST) DepartmentAddressResource createResource(@Valid @RequestBody final DepartmentAddressResource resource); @Override @ResponseStatus(HttpStatus.OK) @RequestMapping(value = "/{departmentId}/addresses/{id}", method = RequestMethod.PUT) MessageResource updateResource(@PathVariable("id") final Long id,
			@Valid @RequestBody final DepartmentAddressResource resource); @Override @ResponseStatus(HttpStatus.OK) @RequestMapping(value = "/{departmentId}/addresses/{id}", method = RequestMethod.GET) DepartmentAddressResource getResource(@PathVariable("id") final Long id); @Override @ResponseStatus(HttpStatus.NO_CONTENT) @RequestMapping(value = "/{departmentId}/addresses/{id}", method = RequestMethod.DELETE) MessageResource removeResource(@PathVariable("id") final Long id); @Override @ResponseStatus(HttpStatus.OK) @RequestMapping(value = "/{departmentId}/addresses", method = RequestMethod.GET) PagedResultResource<DepartmentAddressResource> getPagedResource(final PagedRequest<DepartmentAddressResource> request);  }
@Test public void testGetAddress() throws Exception { Long departmentId = 1L; Long id = 2L; DepartmentAddressResource departmentAddressResource = new DepartmentAddressResource(); departmentAddressResource.setId(id); departmentAddressResource.setDepartmentId(departmentId); String response = getJson(departmentAddressResource, false); when(facade.getResource(anyLong())).thenReturn(departmentAddressResource); mockMvc.perform(get("/departments/{departmentId}/addresses/{addressId}", departmentId, 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 departmentId = 2L; doThrow(AccessDeniedException.class).when(facade).getResource(anyLong()); mockMvc.perform(get("/departments/{departmentId}/addresses/{id}", departmentId, id)); verify(facade).getResource(id); }