@Test
  @SuppressWarnings("unchecked")
  public void testValidateConfigUpgradePacks() throws Exception {
    IOFileFilter filter = new IOFileFilter() {
      @Override
      public boolean accept(File dir, String name) {
        return false;
      }

      @Override
      public boolean accept(File file) {
        // file has the folder named 'upgrades', ends with '.xml' and is NOT
        // 'config-upgrade.xml'
        if (file.getAbsolutePath().contains("upgrades")
            && file.getAbsolutePath().endsWith("config-upgrade.xml")) {
          return true;
        }

        return false;
      }
    };

    List<File> files = new ArrayList<>();

    files.addAll(FileUtils.listFiles(new File("src/main/resources/stacks"), filter,
        FileFilterUtils.directoryFileFilter()));

    files.addAll(FileUtils.listFiles(new File("src/test/resources/stacks"), filter,
        FileFilterUtils.directoryFileFilter()));

    files.addAll(FileUtils.listFiles(new File("src/test/resources/stacks_with_upgrade_cycle"),
        filter, FileFilterUtils.directoryFileFilter()));

    ModuleFileUnmarshaller unmarshaller = new ModuleFileUnmarshaller();

    int filesTestedCount = 0;
    for (File file : files) {
      String fileContent = FileUtils.readFileToString(file, "UTF-8");

      // these things must be in upgrade packs for them to work anyway
      if (fileContent.contains("<upgrade-config-changes")
          && fileContent.contains("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"")) {
        if (!fileContent.contains("xsi:noNamespaceSchemaLocation=\"upgrade-config.xsd\"")) {
          String msg = String.format(
              "File %s appears to be a config upgrade pack, but does not define 'upgrade-config.xsd' as its schema",
              file.getAbsolutePath());
          Assert.fail(msg);
        } else {
          filesTestedCount++;
          unmarshaller.unmarshal(ConfigUpgradePack.class, file, true);
        }
      }
    }

    Assert.assertTrue(
        "This test didn't appear to do any work which could indicate that it failed to find files to validate",
        filesTestedCount > 5);
  }
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