  @Test
  public void createWidget() throws Exception {

    ConstrainedFields fields = fields(WidgetConfigResource.class);
    WidgetConfig widgetConfig = widgetConfig();
    WidgetConfigResource widgetConfigResource = widgetConfigResource();

    when(dashboardService.load(any())).thenReturn(dashboard());
    when(widgetService.saveWidget(any(WidgetConfig.class))).thenReturn(widgetConfig);

    MvcResult result =
        mvc()
            .perform(
                post("/api/dashboards/test/widgets")
                    .contentType("application/json")
                    .content(toJsonWithoutLinks(widgetConfigResource)))
            .andExpect(status().isOk())
            .andExpect(containsResource(WidgetConfigResource.class))
            .andDo(
                document(
                    "widgets/create",
                    requestFields(
                        fields.withPath("title").description("The display title of the widget."),
                        fields.withPath("type").description("The type of the widget."),
                        fields
                            .withPath("lastModified")
                            .description(
                                "The date the widget's configuration has last been modified."),
                        fields
                            .withPath("sourceConfigs")
                            .description(
                                "List of configurations for the data sources of this widget."))))
            .andReturn();

    WidgetConfigResource resource =
        fromJson(result.getResponse().getContentAsString(), WidgetConfigResource.class);
    assertThat(resource.getTitle()).isEqualTo("Production");
  }