@Test
  public void testUpgradeHistory() throws Exception {
    Cluster cluster = clusters.getCluster("c1");

    Map<String, Object> requestProps = new HashMap<>();
    requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1");
    requestProps.put(UpgradeResourceProvider.UPGRADE_REPO_VERSION_ID, String.valueOf(repoVersionEntity2200.getId()));
    requestProps.put(UpgradeResourceProvider.UPGRADE_PACK, "upgrade_test");
    requestProps.put(UpgradeResourceProvider.UPGRADE_TYPE, UpgradeType.ROLLING.toString());
    requestProps.put(UpgradeResourceProvider.UPGRADE_SKIP_MANUAL_VERIFICATION, Boolean.TRUE.toString());
    requestProps.put(UpgradeResourceProvider.UPGRADE_SKIP_PREREQUISITE_CHECKS, Boolean.TRUE.toString());
    requestProps.put(UpgradeResourceProvider.UPGRADE_DIRECTION, Direction.UPGRADE.name());

    ResourceProvider upgradeResourceProvider = createProvider(amc);
    Request request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps), null);
    upgradeResourceProvider.createResources(request);

    List<UpgradeEntity> upgrades = upgradeDao.findUpgrades(cluster.getClusterId());
    assertEquals(1, upgrades.size());

    UpgradeEntity upgrade = cluster.getUpgradeInProgress();
    List<UpgradeHistoryEntity> histories = upgrade.getHistory();
    assertEquals(2, histories.size());

    for (UpgradeHistoryEntity history : histories) {
      assertEquals("ZOOKEEPER", history.getServiceName());
      assertEquals(repoVersionEntity2110, history.getFromReposistoryVersion());
      assertEquals(repoVersionEntity2200, history.getTargetRepositoryVersion());
    }

    // abort the upgrade and create the downgrade
    abortUpgrade(upgrade.getRequestId());

    requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1");
    requestProps.put(UpgradeResourceProvider.UPGRADE_PACK, "upgrade_nonrolling_new_stack");
    requestProps.put(UpgradeResourceProvider.UPGRADE_SKIP_PREREQUISITE_CHECKS, "true");
    requestProps.put(UpgradeResourceProvider.UPGRADE_DIRECTION, Direction.DOWNGRADE.name());

    Map<String, String> requestInfoProperties = new HashMap<>();

    request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps),
        requestInfoProperties);
    RequestStatus status = upgradeResourceProvider.createResources(request);
    UpgradeEntity downgrade = upgradeDao.findUpgradeByRequestId(getRequestId(status));
    assertEquals(Direction.DOWNGRADE, downgrade.getDirection());

    // check from/to history
    histories = downgrade.getHistory();
    assertEquals(2, histories.size());

    for (UpgradeHistoryEntity history : histories) {
      assertEquals("ZOOKEEPER", history.getServiceName());
      assertEquals(repoVersionEntity2200, history.getFromReposistoryVersion());
      assertEquals(repoVersionEntity2110, history.getTargetRepositoryVersion());
    }
  }
Tests that from/to repository version history is created correctly on the
upgrade.

@throws Exception
ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java