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