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