AdminUnitController extends BaseController implements CrudController<AdminUnitResource, AdminUnitResource> { @Override @ResponseStatus(HttpStatus.OK) @RequestMapping(value = Request.ID, method = RequestMethod.GET) @ApiOperation(value = "Get Admin Unit by id") public AdminUnitResource getResource(@PathVariable("id") final Long id) { LOG.info("Getting admin unit resource: {}", id); return facade.getResource(id); }  @Override @ResponseStatus(HttpStatus.OK) @RequestMapping(method = RequestMethod.GET) @ApiOperation(value = "Get Admin Unit Types") PagedResultResource<AdminUnitResource> getPagedResource(final PagedRequest<AdminUnitResource> request); @Override @ResponseStatus(HttpStatus.OK) @RequestMapping(value = Request.ID, method = RequestMethod.GET) @ApiOperation(value = "Get Admin Unit by id") AdminUnitResource getResource(@PathVariable("id") final Long id); @Override @ResponseStatus(HttpStatus.CREATED) @RequestMapping(method = RequestMethod.POST) @ApiOperation(value = "Create Admin Unit") AdminUnitResource createResource(@Valid @RequestBody final AdminUnitResource resource); @Override @ResponseStatus(HttpStatus.OK) @RequestMapping(value = Request.ID, method = RequestMethod.PUT) @ApiOperation(value = "Update Admin Unit") MessageResource updateResource(@PathVariable("id") final Long id, @Valid @RequestBody final AdminUnitResource resource); @Override @ResponseStatus(HttpStatus.NO_CONTENT) @RequestMapping(value = Request.ID, method = RequestMethod.DELETE) @ApiOperation(value = "Delete Admin Unit by id") MessageResource removeResource(@PathVariable("id") final Long id);  }
@Test public void testGetResource() throws Exception { Long id = 1L; String name = "all difficult"; AdminUnitResource expected = new AdminUnitResource(); expected.setName(name); expected.setId(id); when(facade.getResource(anyLong())).thenReturn(expected); String response = getJson(expected, false); mockMvc.perform(get("/adminunits/{id}", id)) .andExpect(status().isOk()) .andExpect(content().string(response)); verify(facade).getResource(id); }
@Test(expected = AccessDeniedException.class) public void testGetResourceWithAccessDeniedException() throws Exception { Long id = 1L; doThrow(AccessDeniedException.class).when(facade).getResource(anyLong()); mockMvc.perform(get("/adminunits/{id}", id)); verify(facade).getResource(id); }