@Test
public void testUpdateClusterEnvConfiguration() throws Exception {

  EasyMockSupport easyMockSupport = new EasyMockSupport();
  final AmbariManagementController  mockAmbariManagementController = easyMockSupport.createStrictMock(AmbariManagementController.class);
  final ConfigHelper mockConfigHelper = easyMockSupport.createMock(ConfigHelper.class);
  final Clusters mockClusters = easyMockSupport.createStrictMock(Clusters.class);
  final Cluster mockClusterExpected = easyMockSupport.createStrictMock(Cluster.class);
  final Cluster mockClusterMissingSmokeUser = easyMockSupport.createStrictMock(Cluster.class);
  final Cluster mockClusterMissingConfig = easyMockSupport.createStrictMock(Cluster.class);
  final Config mockClusterEnvExpected = easyMockSupport.createStrictMock(Config.class);
  final Config mockClusterEnvMissingSmokeUser = easyMockSupport.createStrictMock(Config.class);
  final Map<String, String> propertiesExpectedT0 = new HashMap<String, String>();
  propertiesExpectedT0.put("kerberos_domain", "EXAMPLE.COM");
  propertiesExpectedT0.put("user_group", "hadoop");
  propertiesExpectedT0.put("kinit_path_local", "/usr/bin");
  propertiesExpectedT0.put("security_enabled", "true");
  propertiesExpectedT0.put("smokeuser", "ambari-qa");
  propertiesExpectedT0.put("smokeuser_keytab", "/etc/security/keytabs/smokeuser.headless.keytab");
  propertiesExpectedT0.put("ignore_groupsusers_create", "false");
  final Map<String, String> propertiesExpectedT1 = new HashMap<String, String>(propertiesExpectedT0);
  propertiesExpectedT1.put("smokeuser_principal_name", "ambari-qa");
  final Map<String, String> propertiesMissingSmokeUserT0 = new HashMap<String, String>(propertiesExpectedT0);
  propertiesMissingSmokeUserT0.remove("smokeuser");
  final Map<String, String> propertiesMissingSmokeUserT1 = new HashMap<String, String>(propertiesMissingSmokeUserT0);
  propertiesMissingSmokeUserT1.put("smokeuser_principal_name", "ambari-qa");
  final PropertyInfo mockSmokeUserPropertyInfo = easyMockSupport.createStrictMock(PropertyInfo.class);
  final Injector mockInjector = Guice.createInjector(new AbstractModule() {
    @Override
    protected void configure() {
      bind(AmbariManagementController.class).toInstance(mockAmbariManagementController);
      bind(ConfigHelper.class).toInstance(mockConfigHelper);
      bind(Clusters.class).toInstance(mockClusters);
      bind(DBAccessor.class).toInstance(createNiceMock(DBAccessor.class));
      bind(OsFamily.class).toInstance(createNiceMock(OsFamily.class));
    }
  });
  expect(mockAmbariManagementController.getClusters()).andReturn(mockClusters).once();
  expect(mockClusters.getClusters()).andReturn(new HashMap<String, Cluster>() {{
    put("normal", mockClusterExpected);
    put("missing_smokeuser", mockClusterMissingSmokeUser);
    put("missing_cluster-env", mockClusterMissingConfig);
  }}).once();
    // Expected operation
  expect(mockClusterExpected.getDesiredConfigByType("cluster-env")).andReturn(mockClusterEnvExpected).once();
  expect(mockClusterEnvExpected.getProperties()).andReturn(propertiesExpectedT0).once();
  mockConfigHelper.createConfigType(mockClusterExpected, mockAmbariManagementController,
      "cluster-env", propertiesExpectedT1, UpgradeCatalog200.AUTHENTICATED_USER_NAME, "Upgrading to Ambari 2.0");
  expectLastCall().once();
  // Missing smokeuser
  expect(mockClusterMissingSmokeUser.getDesiredConfigByType("cluster-env")).andReturn(mockClusterEnvMissingSmokeUser).once();
  expect(mockClusterEnvMissingSmokeUser.getProperties()).andReturn(propertiesMissingSmokeUserT0).once();
  expect(mockConfigHelper.getStackProperties(mockClusterMissingSmokeUser)).andReturn(Collections.singleton(mockSmokeUserPropertyInfo)).once();
  expect(mockSmokeUserPropertyInfo.getFilename()).andReturn("cluster-env.xml").once();
  expect(mockSmokeUserPropertyInfo.getValue()).andReturn("ambari-qa").once();
  mockConfigHelper.createConfigType(mockClusterMissingSmokeUser, mockAmbariManagementController,
      "cluster-env", propertiesMissingSmokeUserT1, UpgradeCatalog200.AUTHENTICATED_USER_NAME, "Upgrading to Ambari 2.0");
  expectLastCall().once();
  // Missing cluster-env config
  expect(mockClusterMissingConfig.getDesiredConfigByType("cluster-env")).andReturn(null).once();
  easyMockSupport.replayAll();
  mockInjector.getInstance(UpgradeCatalog200.class).updateClusterEnvConfiguration();
  easyMockSupport.verifyAll();
}