@Test
public void testConfigureTask() throws Exception {

  Map<String, UpgradePack> upgrades = ambariMetaInfo.getUpgradePacks("HDP", "2.1.1");
  assertTrue(upgrades.containsKey("upgrade_test"));
  UpgradePack upgrade = upgrades.get("upgrade_test");
  ConfigUpgradePack cup = ambariMetaInfo.getConfigUpgradePack("HDP", "2.1.1");
  assertNotNull(upgrade);
  Cluster cluster = makeCluster();
  UpgradeContext context = m_upgradeContextFactory.create(cluster, UpgradeType.ROLLING,
      Direction.UPGRADE, UPGRADE_VERSION, new HashMap<String, Object>());
  context.setResolver(m_masterHostResolver);
  List<UpgradeGroupHolder> groups = m_upgradeHelper.createSequence(upgrade,
      context);
  assertEquals(7, groups.size());
  // grab the first configure task out of Hive
  UpgradeGroupHolder hiveGroup = groups.get(4);
  assertEquals("HIVE", hiveGroup.name);
  ConfigureTask configureTask = (ConfigureTask) hiveGroup.items.get(1).getTasks().get(0).getTasks().get(0);
  Map<String, String> configProperties = configureTask.getConfigurationChanges(cluster, cup);
  assertFalse(configProperties.isEmpty());
  assertEquals(configProperties.get(ConfigureTask.PARAMETER_CONFIG_TYPE), "hive-site");
  // now set the property in the if-check in the set element so that we have a match
  Map<String, String> hiveConfigs = new HashMap<>();
  hiveConfigs.put("fooKey", "THIS-BETTER-CHANGE");
  hiveConfigs.put("ifFooKey", "ifFooValue");
  ConfigurationRequest configurationRequest = new ConfigurationRequest();
  configurationRequest.setClusterName(cluster.getClusterName());
  configurationRequest.setType("hive-site");
  configurationRequest.setVersionTag("version2");
  configurationRequest.setProperties(hiveConfigs);
  final ClusterRequest clusterRequest = new ClusterRequest(
      cluster.getClusterId(), cluster.getClusterName(),
      cluster.getDesiredStackVersion().getStackVersion(), null);
  clusterRequest.setDesiredConfig(Collections.singletonList(configurationRequest));
  m_managementController.updateClusters(new HashSet<ClusterRequest>() {
    {
      add(clusterRequest);
    }
  }, null);
  // the configure task should now return different properties to set based on
  // the if-condition checks
  configProperties = configureTask.getConfigurationChanges(cluster, cup);
  assertFalse(configProperties.isEmpty());
  assertEquals( configProperties.get(ConfigureTask.PARAMETER_CONFIG_TYPE), "hive-site");
  String configurationJson = configProperties.get(ConfigureTask.PARAMETER_KEY_VALUE_PAIRS);
  assertNotNull(configurationJson);
  List<ConfigUpgradeChangeDefinition.ConfigurationKeyValue> keyValuePairs = m_gson.fromJson(
      configurationJson,
      new TypeToken<List<ConfigUpgradeChangeDefinition.ConfigurationKeyValue>>() {
      }.getType());
  assertEquals("fooKey", keyValuePairs.get(0).key);
  assertEquals("fooValue", keyValuePairs.get(0).value);
}