@Test
  public void testUpgradeConditions() throws Exception {
    Map<String, UpgradePack> upgrades = ambariMetaInfo.getUpgradePacks("HDP", "2.2.0");
    assertTrue(upgrades.containsKey("upgrade_test_conditions"));
    UpgradePack upgrade = upgrades.get("upgrade_test_conditions");
    assertNotNull(upgrade);

    Cluster cluster = makeCluster();

    KerberosDetails kerberosDetails = createNiceMock(KerberosDetails.class);
    expect(kerberosDetails.getKdcType()).andReturn(KDCType.NONE).atLeastOnce();
    replay(kerberosDetails);

    UpgradeContext context = getMockUpgradeContext(cluster, Direction.UPGRADE, UpgradeType.ROLLING, false);
    expect(context.getKerberosDetails()).andReturn(kerberosDetails).atLeastOnce();
    replay(context);

    // initially, no conditions should be met, so only 1 group should be
    // available
    List<UpgradeGroupHolder> groups = m_upgradeHelper.createSequence(upgrade, context);
    assertEquals(1, groups.size());

    // from that 1 group, only 1 task is condition-less
    List<StageWrapper> stageWrappers = groups.get(0).items;
    assertEquals(1, stageWrappers.size());
    assertEquals(1, stageWrappers.get(0).getTasks().size());

    // set the configuration property and try again
    Map<String, String> fooConfigs = new HashMap<>();
    fooConfigs.put("foo-property", "foo-value");
    ConfigurationRequest configurationRequest = new ConfigurationRequest();
    configurationRequest.setClusterName(cluster.getClusterName());
    configurationRequest.setType("foo-site");
    configurationRequest.setVersionTag("version1");
    configurationRequest.setProperties(fooConfigs);

    final ClusterRequest clusterRequest = new ClusterRequest(cluster.getClusterId(),
        cluster.getClusterName(), cluster.getDesiredStackVersion().getStackVersion(), null);

    clusterRequest.setDesiredConfig(singletonList(configurationRequest));
    m_managementController.updateClusters(Sets.newHashSet(clusterRequest), null);

    // the config condition should now be set
    groups = m_upgradeHelper.createSequence(upgrade, context);
    assertEquals(2, groups.size());
    assertEquals("ZOOKEEPER_CONFIG_CONDITION_TEST", groups.get(0).name);

    // now change the cluster security so the other conditions come back too
    cluster.setSecurityType(SecurityType.KERBEROS);

    groups = m_upgradeHelper.createSequence(upgrade, context);
    assertEquals(5, groups.size());

    EasyMock.verify(kerberosDetails);
  }
Tests that the {@link SecurityCondition} element correctly restricts the groups in
an upgrade.

@throws Exception
ambari-server/src/test/java/org/apache/ambari/server/stack/upgrade/orchestrate/UpgradeHelperTest.java