AssetController extends BaseController implements CrudController<AssetResource, AssetResource> { @Override @ResponseStatus(HttpStatus.OK) @RequestMapping(value = Request.ID, method = RequestMethod.GET) @ApiOperation(value = "Get Asset by id") public AssetResource getResource(@PathVariable("id") final Long id) { LOG.info("Retrieving asset with id: {}", id); return facade.getResource(id); }  @Override @ResponseStatus(HttpStatus.CREATED) @RequestMapping(method = RequestMethod.POST) @ApiOperation(value = "Create Asset") AssetResource createResource(@Valid @RequestBody final AssetResource resource); @Override @ResponseStatus(HttpStatus.OK) @RequestMapping(value = Request.ID, method = RequestMethod.PUT) @ApiOperation(value = "Update Asset") MessageResource updateResource(@PathVariable("id") final Long id,
			@Valid @RequestBody final AssetResource resource); @Override @ResponseStatus(HttpStatus.OK) @RequestMapping(value = Request.ID, method = RequestMethod.GET) @ApiOperation(value = "Get Asset by id") AssetResource getResource(@PathVariable("id") final Long id); @Override @ResponseStatus(HttpStatus.NO_CONTENT) @RequestMapping(value = Request.ID, method = RequestMethod.DELETE) @ApiOperation(value = "Delete Asset by id") MessageResource removeResource(@PathVariable("id") final Long id); @Override @ResponseStatus(HttpStatus.OK) @RequestMapping(method = RequestMethod.GET) @ApiOperation(value = "Get Assets") PagedResultResource<AssetResource> getPagedResource(final PagedRequest<AssetResource> request);  }
@Test public void testGetAsset() throws Exception { Long id = 1L; AssetResource assetResource = new AssetResource(); assetResource.setId(id); String response = getJson(assetResource, false); when(facade.getResource(anyLong())).thenReturn(assetResource); mockMvc.perform(get("/assets/{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("/assets/{id}", id)); verify(facade).getResource(id); }