AdminUnitTypeController extends BaseController implements PagedController<AdminUnitTypeResource, AdminUnitTypeResource> { @Override @ResponseStatus(HttpStatus.OK) @RequestMapping(value = Request.ID, method = RequestMethod.GET) @ApiOperation(value = "Get Admin Unit Types by id") public AdminUnitTypeResource getResource(@PathVariable("id") final Long id) { LOGGER.info("Getting admin unit type:{}", id); return facade.getResource(id); }  @Override @ResponseStatus(HttpStatus.OK) @RequestMapping(method = RequestMethod.GET) @ApiOperation(value = "Get All Admin Unit Types") PagedResultResource<AdminUnitTypeResource> getPagedResource(final PagedRequest<AdminUnitTypeResource> request); @Override @ResponseStatus(HttpStatus.OK) @RequestMapping(value = Request.ID, method = RequestMethod.GET) @ApiOperation(value = "Get Admin Unit Types by id") AdminUnitTypeResource getResource(@PathVariable("id") final Long id);  }
@Test public void testGetResource() throws Exception { Long id = 1L; String name = "all difficult"; String abbrName = "ad"; AdminUnitTypeResource expected = new AdminUnitTypeResource(); expected.setName(name); expected.setAbbrName(abbrName); expected.setId(id); when(facade.getResource(anyLong())).thenReturn(expected); String response = getJson(expected, false); mockMvc.perform(get("/adminunits/types/{id}", id)) .andExpect(status().isOk()) .andExpect(content().string(response)); verify(facade).getResource(id); }
@Test(expected = AccessDeniedException.class) public void testGetResourceWithException() throws Exception { Long id = 1L; String name = "all difficult"; String abbrName = "ad"; AdminUnitTypeResource expected = new AdminUnitTypeResource(); expected.setName(name); expected.setAbbrName(abbrName); expected.setId(id); doThrow(AccessDeniedException.class).when(facade).getResource(anyLong()); String response = getJson(expected, false); mockMvc.perform(get("/adminunits/types/{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/types/{id}", id)); verify(facade).getResource(id); }