@Test
  public void testUpgradeOrder() throws Exception {
    String sourceResourceDirectory = "src" + File.separator + "test" + File.separator + "resources";

    Properties properties = new Properties();
    properties.setProperty(Configuration.SERVER_PERSISTENCE_TYPE.getKey(), "in-memory");
    properties.setProperty(Configuration.OS_VERSION.getKey(), "centos6");
    properties.setProperty(Configuration.SHARED_RESOURCES_DIR.getKey(), sourceResourceDirectory);

    Injector injector = Guice.createInjector(new ControllerModule(properties), new AuditLoggerModule(), new LdapModule());
    UpgradeCheckRegistry registry = injector.getInstance(UpgradeCheckRegistry.class);
    UpgradeCheckRegistry registry2 = injector.getInstance(UpgradeCheckRegistry.class);

    // verify singleton
    Assert.assertEquals(registry, registry2);

    // get the check list
    List<UpgradeCheck> checks = registry.getBuiltInUpgradeChecks();

    // scan for all checks
    ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
    AssignableTypeFilter filter = new AssignableTypeFilter(UpgradeCheck.class);
    scanner.addIncludeFilter(filter);

    // grab all check subclasses using the exact folder they are in to avoid loading the SampleServiceCheck from the test jar
    Set<BeanDefinition> beanDefinitions = scanner.findCandidateComponents("org.apache.ambari.server.checks");

    // verify they are equal
    Assert.assertTrue(checks.size() > 0);
    Assert.assertTrue(beanDefinitions.size() > 0);
    Assert.assertEquals(beanDefinitions.size(), checks.size());

    UpgradeCheck lastCheck = null;
    for (UpgradeCheck check : checks) {
      UpgradeCheckGroup group = UpgradeCheckGroup.DEFAULT;
      UpgradeCheckGroup lastGroup = UpgradeCheckGroup.DEFAULT;

      if (null != lastCheck) {
        UpgradeCheckInfo annotation = check.getClass().getAnnotation(UpgradeCheckInfo.class);
        UpgradeCheckInfo lastAnnotation = lastCheck.getClass().getAnnotation(UpgradeCheckInfo.class);

        if (null != annotation && null != lastAnnotation) {
          group = annotation.group();
          lastGroup = lastAnnotation.group();
          Assert.assertTrue(lastGroup.getOrder().compareTo(group.getOrder()) <= 0);
        }
      }

      lastCheck = check;
    }
  }
Tests that instances of {@link UpgradeCheck} are ordered
correctly.

@throws Exception
ambari-server/src/test/java/org/apache/ambari/server/checks/UpgradeCheckOrderTest.java