WidgetController { @RequestMapping(value = "/{widgetId}", method = GET, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<WidgetConfigResource> getWidget( @PathVariable String slug, @PathVariable String widgetId) { WidgetConfig widgetConfig = widgetService.loadWidget(widgetId); if (widgetConfig == null) { return new ResponseEntity<>(NOT_FOUND); } WidgetConfigResourceAssembler assembler = new WidgetConfigResourceAssembler(slug, widgetConfig.getDashboardId()); WidgetConfigResource resource = assembler.toResource(widgetConfig); return new ResponseEntity<>(resource, OK); } @Autowired  WidgetController(
      WidgetConfigService widgetService,
      WidgetConfigRepository widgetConfigRepository,
      DashboardService dashboardService); @RequestMapping(value = "/{widgetId}", method = GET, produces = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<WidgetConfigResource> getWidget(
      @PathVariable String slug, @PathVariable String widgetId); @RequestMapping( value = "/{widgetId}", method = DELETE, produces = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<Void> deleteWidget(@PathVariable String widgetId); @RequestMapping( method = POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<WidgetConfigResource> createWidget(
      @PathVariable String slug, @RequestBody WidgetConfigResource widgetConfigResource); @RequestMapping( value = "/{widgetId}/data", method = GET, produces = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<SourceDataResource> getData(
      @PathVariable String slug, @PathVariable String widgetId); @SuppressWarnings("unchecked") @RequestMapping(method = GET, produces = MediaType.APPLICATION_JSON_VALUE) ResponseEntity<PagedResources<WidgetConfigResource>> getWidgets(
      @PathVariable String slug,
      @PageableDefault Pageable pageable,
      PagedResourcesAssembler pagedResourcesAssembler); @RequestMapping(value = "/all", method = GET, produces = MediaType.APPLICATION_JSON_VALUE) Resources<WidgetConfigResource> getAllWidgets(@PathVariable String slug);  }
@Test public void getWidget() throws Exception { when(widgetService.loadWidget("my_little_widget")).thenReturn(widgetConfig()); MvcResult result = mvc() .perform(get("/api/dashboards/test/widgets/my_little_widget")) .andExpect(status().isOk()) .andExpect(containsResource(WidgetConfigResource.class)) .andDo( document( "widgets/get", links( halLinks(), linkWithRel("self").description("Link to the widget resource itself."), linkWithRel("dashboard") .description("Link to the dashboard the widget is part of."), linkWithRel("data") .description("Link to the data the widget should display.")))) .andReturn(); WidgetConfigResource resource = fromJson(result.getResponse().getContentAsString(), WidgetConfigResource.class); assertThat(resource.getTitle()).isEqualTo("Production"); }