@Test
public void testHBASEWidgetUpdate() throws Exception {

  final Clusters clusters = createNiceMock(Clusters.class);
  final Cluster cluster = createNiceMock(Cluster.class);
  final AmbariManagementController controller = createNiceMock(AmbariManagementController.class);
  final Gson gson = new Gson();
  final WidgetDAO widgetDAO = createNiceMock(WidgetDAO.class);
  final AmbariMetaInfo metaInfo = createNiceMock(AmbariMetaInfo.class);
  WidgetEntity widgetEntity = createNiceMock(WidgetEntity.class);
  StackId stackId = new StackId("HDP", "2.0.0");
  StackInfo stackInfo = createNiceMock(StackInfo.class);
  ServiceInfo serviceInfo = createNiceMock(ServiceInfo.class);
  String widgetStr = "{\n" +
    "  \"layouts\": [\n" +
    "    {\n" +
    "      \"layout_name\": \"default_hbase_dashboard\",\n" +
    "      \"display_name\": \"Standard HBASE Dashboard\",\n" +
    "      \"section_name\": \"HBASE_SUMMARY\",\n" +
    "      \"widgetLayoutInfo\": [\n" +
    "        {\n" +
    "          \"widget_name\": \"Blocked Updates\",\n" +
    "          \"metrics\": [],\n" +
    "          \"values\": []\n" +
    "        }\n" +
    "      ]\n" +
    "    } " +
    "]\n" +
    "}";
  File dataDirectory = temporaryFolder.newFolder();
  File file = new File(dataDirectory, "hbase_widget.json");
  FileUtils.writeStringToFile(file, widgetStr);
  final Injector mockInjector = Guice.createInjector(new AbstractModule() {
    @Override
    protected void configure() {
      bind(EntityManager.class).toInstance(createNiceMock(EntityManager.class));
      bind(AmbariManagementController.class).toInstance(controller);
      bind(Clusters.class).toInstance(clusters);
      bind(DBAccessor.class).toInstance(createNiceMock(DBAccessor.class));
      bind(OsFamily.class).toInstance(createNiceMock(OsFamily.class));
      bind(Gson.class).toInstance(gson);
      bind(WidgetDAO.class).toInstance(widgetDAO);
      bind(StackManagerFactory.class).toInstance(createNiceMock(StackManagerFactory.class));
      bind(AmbariMetaInfo.class).toInstance(metaInfo);
    }
  });
  expect(controller.getClusters()).andReturn(clusters).anyTimes();
  expect(clusters.getClusters()).andReturn(new HashMap<String, Cluster>() {{
    put("normal", cluster);
  }}).anyTimes();
  expect(cluster.getClusterId()).andReturn(1L).anyTimes();
  expect(stackInfo.getService("HBASE")).andReturn(serviceInfo);
  expect(cluster.getDesiredStackVersion()).andReturn(stackId).anyTimes();
  expect(metaInfo.getStack("HDP", "2.0.0")).andReturn(stackInfo).anyTimes();
  expect(serviceInfo.getWidgetsDescriptorFile()).andReturn(file).anyTimes();
  expect(widgetDAO.findByName(1L, "Blocked Updates", "ambari", "HBASE_SUMMARY"))
    .andReturn(Collections.singletonList(widgetEntity));
  expect(widgetDAO.merge(widgetEntity)).andReturn(null);
  expect(widgetEntity.getWidgetName()).andReturn("Blocked Updates").anyTimes();
  replay(clusters, cluster, controller, widgetDAO, metaInfo, widgetEntity, stackInfo, serviceInfo);
  mockInjector.getInstance(UpgradeCatalog222.class).updateHBASEWidgetDefinition();
  verify(clusters, cluster, controller, widgetDAO, widgetEntity, stackInfo, serviceInfo);
}