@Test
public void testCreateResources() throws Exception {

  AmbariManagementController amc = createMock(AmbariManagementController.class);
  Clusters clusters = createMock(Clusters.class);
  Cluster cluster = createMock(Cluster.class);
  expect(amc.getClusters()).andReturn(clusters).atLeastOnce();
  expect(clusters.getCluster((String) anyObject())).andReturn(cluster).atLeastOnce();
  expect(cluster.getClusterId()).andReturn(Long.valueOf(1)).anyTimes();
  Capture<WidgetEntity> entityCapture = EasyMock.newCapture();
  dao.create(capture(entityCapture));
  expectLastCall();
  replay(amc, clusters, cluster, dao);
  WidgetResourceProvider provider = createProvider(amc);
  Map<String, Object> requestProps = new HashMap<>();
  requestProps.put(WidgetResourceProvider.WIDGET_CLUSTER_NAME_PROPERTY_ID, "c1");
  requestProps.put(WidgetResourceProvider.WIDGET_WIDGET_NAME_PROPERTY_ID, "widget name");
  requestProps.put(WidgetResourceProvider.WIDGET_WIDGET_TYPE_PROPERTY_ID, "GAUGE");
  requestProps.put(WidgetResourceProvider.WIDGET_AUTHOR_PROPERTY_ID, "admin");
  requestProps.put(WidgetResourceProvider.WIDGET_SCOPE_PROPERTY_ID, "USER");
  Set<Map<String, String>> testSet = new LinkedHashSet<>();
  Map<String, String> testMap = new HashMap<>();
  testMap.put("name","value");
  testMap.put("name2","value2");
  testSet.add(testMap);
  requestProps.put(WidgetResourceProvider.WIDGET_METRICS_PROPERTY_ID, testSet);
  requestProps.put(WidgetResourceProvider.WIDGET_VALUES_PROPERTY_ID, testSet);
  requestProps.put(WidgetResourceProvider.WIDGET_PROPERTIES_PROPERTY_ID+"/property1", "value1");
  requestProps.put(WidgetResourceProvider.WIDGET_PROPERTIES_PROPERTY_ID+"/property2", "value2");
  Request request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps), null);
  RequestStatus requestStatus = provider.createResources(request);
  Assert.assertTrue(entityCapture.hasCaptured());
  WidgetEntity entity = entityCapture.getValue();
  Assert.assertNotNull(entity);
  Assert.assertEquals(1, requestStatus.getAssociatedResources().size());
  Assert.assertEquals(Long.valueOf(1), entity.getClusterId());
  Assert.assertEquals("USER", entity.getScope());
  Assert.assertEquals("widget name", entity.getWidgetName());
  Assert.assertEquals(null, entity.getDefaultSectionName());
  Assert.assertEquals("GAUGE", entity.getWidgetType());
  Assert.assertEquals("admin", entity.getAuthor());
  Assert.assertEquals("[{\"name\":\"value\",\"name2\":\"value2\"}]", entity.getMetrics());
  Assert.assertEquals("[{\"name\":\"value\",\"name2\":\"value2\"}]", entity.getWidgetValues());
  Assert.assertEquals("{\"property2\":\"value2\",\"property1\":\"value1\"}", entity.getProperties());
  verify(amc, clusters, cluster, dao);
}