@Test
public void testNameserviceAlertsUpdate() {

  EasyMockSupport easyMockSupport = new EasyMockSupport();
  long clusterId = 1;
  final AmbariManagementController mockAmbariManagementController = easyMockSupport.createNiceMock(AmbariManagementController.class);
  final AlertDefinitionDAO mockAlertDefinitionDAO = easyMockSupport.createNiceMock(AlertDefinitionDAO.class);
  final Clusters mockClusters = easyMockSupport.createStrictMock(Clusters.class);
  final Cluster mockClusterExpected = easyMockSupport.createNiceMock(Cluster.class);
  final AlertDefinitionEntity namenodeWebUiAlertDefinitionEntity = new AlertDefinitionEntity();
  final AlertDefinitionEntity mockStormRestApiAlertDefinitionEntity = easyMockSupport.createNiceMock(AlertDefinitionEntity.class);
  namenodeWebUiAlertDefinitionEntity.setDefinitionName("namenode_webui");
  namenodeWebUiAlertDefinitionEntity.setSource("{\"uri\": {\"high_availability\": {\"nameservice\": \"{{hdfs-site/dfs.nameservices}}\",\"alias_key\" : \"{{hdfs-site/dfs.ha.namenodes.{{ha-nameservice}}}}\",\"http_pattern\" : \"{{hdfs-site/dfs.namenode.http-address.{{ha-nameservice}}.{{alias}}}}\",\"https_pattern\" : \"{{hdfs-site/dfs.namenode.https-address.{{ha-nameservice}}.{{alias}}}}\"}}}");
  final Injector mockInjector = Guice.createInjector(new AbstractModule() {
    @Override
    protected void configure() {
      bind(AmbariManagementController.class).toInstance(mockAmbariManagementController);
      bind(Clusters.class).toInstance(mockClusters);
      bind(EntityManager.class).toInstance(entityManager);
      bind(AlertDefinitionDAO.class).toInstance(mockAlertDefinitionDAO);
      bind(DBAccessor.class).toInstance(createNiceMock(DBAccessor.class));
      bind(OsFamily.class).toInstance(createNiceMock(OsFamily.class));
      bind(PasswordEncoder.class).toInstance(createNiceMock(PasswordEncoder.class));
      bind(HookContextFactory.class).toInstance(createMock(HookContextFactory.class));
      bind(HookService.class).toInstance(createMock(HookService.class));
    }
  });
  expect(mockAmbariManagementController.getClusters()).andReturn(mockClusters).once();
  expect(mockClusters.getClusters()).andReturn(new HashMap<String, Cluster>() {{
    put("normal", mockClusterExpected);
  }}).atLeastOnce();
  expect(mockClusterExpected.getClusterId()).andReturn(clusterId).anyTimes();
  expect(mockAlertDefinitionDAO.findByName(eq(clusterId), eq("namenode_webui")))
      .andReturn(namenodeWebUiAlertDefinitionEntity).atLeastOnce();
  expect(mockAlertDefinitionDAO.findByName(eq(clusterId), eq("mapreduce_history_server_process")))
          .andReturn(mockStormRestApiAlertDefinitionEntity).atLeastOnce();
  expect(mockAlertDefinitionDAO.findByName(eq(clusterId), eq("storm_rest_api")))
          .andReturn(mockStormRestApiAlertDefinitionEntity).atLeastOnce();
  mockAlertDefinitionDAO.remove(mockStormRestApiAlertDefinitionEntity);
  expectLastCall().once();
  easyMockSupport.replayAll();
  mockInjector.getInstance(UpgradeCatalog240.class).updateAlerts();
  assertTrue(namenodeWebUiAlertDefinitionEntity.getSource().contains("{{hdfs-site/dfs.internal.nameservices}}"));
  easyMockSupport.verifyAll();
}