@Test
  @Ignore("Ignoring until active HDP stacks are available")
  public void testConfigurationDefinitionsExist() throws Exception {
    Collection<StackInfo> stacks = ambariMetaInfo.getStacks();
    Assert.assertFalse(stacks.isEmpty());

    Cluster cluster = EasyMock.createNiceMock(Cluster.class);

    for( StackInfo stack : stacks ){
      if (!stack.isActive()) {
        LOG.info("Skipping configuration validity test for {}", new StackId(stack));
        continue;
      }

      Map<String, UpgradePack> upgradePacks = ambariMetaInfo.getUpgradePacks(stack.getName(), stack.getVersion());
      for (String key : upgradePacks.keySet()) {
        UpgradePack upgradePack = upgradePacks.get(key);
        final StackId sourceStack = new StackId(stack);

        final RepositoryVersionEntity rve = new RepositoryVersionEntity() {{
          setStack(new StackEntity(){{
            setStackName(sourceStack.getStackName());
            setStackVersion(sourceStack.getStackVersion());
          }});
        }};

        final UpgradeEntity upgradeEntity = new UpgradeEntity();

        UpgradeHistoryEntity upgradeHistoryEntity = new UpgradeHistoryEntity(){{
          setServiceName("TEST");
          setComponentName("TEST");
          setFromRepositoryVersion(rve);
          setUpgrade(upgradeEntity);
        }};

        upgradeEntity.setDirection(Direction.UPGRADE);
        upgradeEntity.addHistory(upgradeHistoryEntity);
        upgradeEntity.setRepositoryVersion(rve);

        UpgradeContext cx = upgradeContextFactory.create(cluster, upgradeEntity);

        ConfigUpgradePack configUpgradePack = ConfigurationPackBuilder.build(cx);

        // do configure tasks in the group section
        List<Grouping> groups = upgradePack.getGroups(Direction.UPGRADE);
        for( Grouping group : groups ){
          if( group instanceof ClusterGrouping ){
            ClusterGrouping clusterGrouping = (ClusterGrouping)group;
            if( null != clusterGrouping.executionStages ){
              for( ExecuteStage executionStage : clusterGrouping.executionStages ){
                if( executionStage.task.getType() == Type.CONFIGURE ){
                  ConfigureTask configureTask = (ConfigureTask) executionStage.task;
                  assertIdDefinitionExists(configureTask.id, configUpgradePack, upgradePack,
                      sourceStack);

                  if (StringUtils.isNotBlank(executionStage.service)) {
                    Assert.assertEquals(executionStage.service, configureTask.associatedService);
                  } else {
                    Assert.assertTrue(null == configureTask.associatedService);
                  }
                }
              }
            }
          }
        }

        // do tasks in the "processing" section
        Map<String, Map<String, ProcessingComponent>> tasks = upgradePack.getTasks();
        for( Map<String,ProcessingComponent> value : tasks.values() ){
          for( ProcessingComponent processingComponent : value.values() ){
            if (null != processingComponent.preTasks) {
              for (Task preTask : processingComponent.preTasks) {
                if (preTask.getType() == Type.CONFIGURE) {
                  ConfigureTask configureTask = (ConfigureTask) preTask;
                  assertIdDefinitionExists(configureTask.id, configUpgradePack, upgradePack,
                      sourceStack);
                  Assert.assertTrue(StringUtils.isNotBlank(configureTask.associatedService));
                }
              }

              if (null != processingComponent.tasks) {
                for (Task task : processingComponent.tasks) {
                  if (task.getType() == Type.CONFIGURE) {
                    ConfigureTask configureTask = (ConfigureTask) task;
                    assertIdDefinitionExists(configureTask.id, configUpgradePack, upgradePack,
                        sourceStack);
                    Assert.assertTrue(StringUtils.isNotBlank(configureTask.associatedService));
                  }
                }
              }

              if (null != processingComponent.postTasks) {
                for (Task postTask : processingComponent.postTasks) {
                  if (postTask.getType() == Type.CONFIGURE) {
                    ConfigureTask configureTask = (ConfigureTask) postTask;
                    assertIdDefinitionExists(configureTask.id, configUpgradePack, upgradePack,
                        sourceStack);
                    Assert.assertTrue(StringUtils.isNotBlank(configureTask.associatedService));
                  }
                }
              }
            }
          }
        }
      }
    }

    // make sure we actually checked a bunch of configs :)
    Assert.assertTrue(validatedConfigCount > 100);
  }
Tests that every ID specified in an upgrade pack actually exists in the
created {@link ConfigUpgradePack}.

@throws Exception
ambari-server/src/test/java/org/apache/ambari/server/state/stack/ConfigUpgradeValidityTest.java