@Test
public void testGetSingleResource() throws Exception {

  Request request = PropertyHelper.getReadRequest(
    WidgetResourceProvider.WIDGET_ID_PROPERTY_ID,
    WidgetResourceProvider.WIDGET_WIDGET_NAME_PROPERTY_ID,
    WidgetResourceProvider.WIDGET_WIDGET_TYPE_PROPERTY_ID,
    WidgetResourceProvider.WIDGET_TIME_CREATED_PROPERTY_ID,
    WidgetResourceProvider.WIDGET_CLUSTER_NAME_PROPERTY_ID,
    WidgetResourceProvider.WIDGET_AUTHOR_PROPERTY_ID,
    WidgetResourceProvider.WIDGET_DESCRIPTION_PROPERTY_ID,
    WidgetResourceProvider.WIDGET_SCOPE_PROPERTY_ID,
    WidgetResourceProvider.WIDGET_METRICS_PROPERTY_ID,
    WidgetResourceProvider.WIDGET_VALUES_PROPERTY_ID,
    WidgetResourceProvider.WIDGET_PROPERTIES_PROPERTY_ID);
  AmbariManagementController amc = createMock(AmbariManagementController.class);
  Clusters clusters = createMock(Clusters.class);
  Cluster cluster = createMock(Cluster.class);
  expect(amc.getClusters()).andReturn(clusters).atLeastOnce();
  expect(clusters.getClusterById(1L)).andReturn(cluster).atLeastOnce();
  expect(cluster.getClusterName()).andReturn("c1").anyTimes();
  Predicate predicate = new PredicateBuilder().property(
      WidgetResourceProvider.WIDGET_CLUSTER_NAME_PROPERTY_ID).equals("c1")
        .and().property(WidgetResourceProvider.WIDGET_ID_PROPERTY_ID).equals("1")
          .and().property(WidgetResourceProvider.WIDGET_AUTHOR_PROPERTY_ID).equals("username").toPredicate();
  expect(dao.findById(1L)).andReturn(getMockEntities("CLUSTER").get(0));
  replay(amc, clusters, cluster, dao);
  WidgetResourceProvider provider = createProvider(amc);
  Set<Resource> results = provider.getResources(request, predicate);
  assertEquals(1, results.size());
  Resource r = results.iterator().next();
  Assert.assertEquals("GAUGE", r.getPropertyValue(WidgetResourceProvider.WIDGET_WIDGET_TYPE_PROPERTY_ID));
  Assert.assertEquals("CLUSTER", r.getPropertyValue(WidgetResourceProvider.WIDGET_SCOPE_PROPERTY_ID));
  Assert.assertEquals("username", r.getPropertyValue(WidgetResourceProvider.WIDGET_AUTHOR_PROPERTY_ID));
  Assert.assertEquals("widget name", r.getPropertyValue(WidgetResourceProvider.WIDGET_WIDGET_NAME_PROPERTY_ID));
  Object metrics = r.getPropertyValue(WidgetResourceProvider.WIDGET_METRICS_PROPERTY_ID);
  Assert.assertEquals("[{\"widget_id\":\"metrics/jvm/HeapMemoryUsed\"," +
          "\"host_component_criteria\":\"host_components/metrics/dfs/FSNamesystem/HAState\\u003dactive\"," +
          "\"service_name\":\"HDFS\",\"component_name\":\"NAMENODE\"," +
          "\"name\":\"java.lang:type\\u003dMemory.HeapMemoryUsage[used]\",\"category\":\"\"}," +
          "{\"widget_id\":\"metrics/jvm/HeapMemoryMax\"," +
          "\"host_component_criteria\":\"host_components/metrics/dfs/FSNamesystem/HAState\\u003dactive\"," +
          "\"service_name\":\"HDFS\",\"component_name\":\"NAMENODE\"," +
          "\"name\":\"java.lang:type\\u003dMemory.HeapMemoryUsage[max]\"," +
          "\"category\":\"\"}]", r.getPropertyValue(WidgetResourceProvider.WIDGET_METRICS_PROPERTY_ID));
  Assert.assertEquals("[{\"name\":\"NameNode Heap\"," +
          "\"value\":\"${java.lang:type\\u003dMemory.HeapMemoryUsage[used] / " +
          "java.lang:type\\u003dMemory.HeapMemoryUsage[max]}\"}]",
          r.getPropertyValue(WidgetResourceProvider.WIDGET_VALUES_PROPERTY_ID));
  Assert.assertEquals("{\"name\":\"value\"}", r.getPropertyValue(WidgetResourceProvider.WIDGET_PROPERTIES_PROPERTY_ID));
}