@Test
public void testHdfsSiteUpdateConfigs() throws Exception{

  Map<String, String> oldPropertiesHdfsSite = new HashMap<String, String>() {
    {
      put("dfs.nameservices", "nnha");
    }
  };
  Map<String, String> newPropertiesHdfsSite = new HashMap<String, String>() {
    {
      put("dfs.nameservices", "nnha");
      put("dfs.internal.nameservices", "nnha");
    }
  };
  Map<String, String> oldPropertiesHadoopEnv = new HashMap<String, String>() {
    {
      put("keyserver_port", " ");
    }
  };
  Map<String, String> newPropertiesHadoopEnv = new HashMap<String, String>() {
    {
      put("keyserver_port", "");
    }
  };
  EasyMockSupport easyMockSupport = new EasyMockSupport();
  Clusters clusters = easyMockSupport.createNiceMock(Clusters.class);
  final Cluster cluster = easyMockSupport.createNiceMock(Cluster.class);
  final Service service = createStrictMock(Service.class);
  final Map<String, Service> services = Collections.singletonMap("HDFS", service);
  Config mockHdfsSite = easyMockSupport.createNiceMock(Config.class);
  Config mockHadoopEnv = easyMockSupport.createNiceMock(Config.class);
  expect(clusters.getClusters()).andReturn(new HashMap<String, Cluster>() {{
    put("normal", cluster);
  }}).anyTimes();
  expect(cluster.getDesiredConfigByType("hdfs-site")).andReturn(mockHdfsSite).atLeastOnce();
  expect(cluster.getDesiredConfigByType("hadoop-env")).andReturn(mockHadoopEnv).atLeastOnce();
  expect(mockHdfsSite.getProperties()).andReturn(oldPropertiesHdfsSite).anyTimes();
  expect(mockHadoopEnv.getProperties()).andReturn(oldPropertiesHadoopEnv).anyTimes();
  expect(cluster.getServices()).andReturn(services).once();
  Injector injector = easyMockSupport.createNiceMock(Injector.class);
  expect(injector.getInstance(Gson.class)).andReturn(null).anyTimes();
  expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(null).anyTimes();
  expect(injector.getInstance(KerberosHelper.class)).andReturn(createNiceMock(KerberosHelper.class)).anyTimes();
  replay(injector, clusters, mockHdfsSite, mockHadoopEnv, cluster);
  AmbariManagementControllerImpl controller = createMockBuilder(AmbariManagementControllerImpl.class)
      .addMockedMethod("createConfiguration")
      .addMockedMethod("getClusters", new Class[] { })
      .addMockedMethod("createConfig")
      .withConstructor(createNiceMock(ActionManager.class), clusters, injector)
      .createNiceMock();
  Injector injector2 = easyMockSupport.createNiceMock(Injector.class);
  Capture<Map<String, String>> propertiesCaptureHdfsSite = EasyMock.newCapture();
  Capture<Map<String, String>> propertiesCaptureHadoopEnv = EasyMock.newCapture();
  expect(injector2.getInstance(AmbariManagementController.class)).andReturn(controller).anyTimes();
  expect(controller.getClusters()).andReturn(clusters).anyTimes();
  expect(controller.createConfig(anyObject(Cluster.class), eq("hdfs-site"), capture(propertiesCaptureHdfsSite), anyString(),
                                 EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(createNiceMock(Config.class)).once();
  expect(controller.createConfig(anyObject(Cluster.class), eq("hadoop-env"), capture(propertiesCaptureHadoopEnv), anyString(),
      EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(createNiceMock(Config.class)).once();
  replay(controller, injector2);
  new UpgradeCatalog240(injector2).updateHDFSConfigs();
  easyMockSupport.verifyAll();
  Map<String, String> updatedPropertiesHdfsSite = propertiesCaptureHdfsSite.getValue();
  assertTrue(Maps.difference(newPropertiesHdfsSite, updatedPropertiesHdfsSite).areEqual());
  Map<String, String> updatedPropertiesHadoopEnv = propertiesCaptureHadoopEnv.getValue();
  assertTrue(Maps.difference(newPropertiesHadoopEnv, updatedPropertiesHadoopEnv).areEqual());
}