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