private void makeDowngradeCluster(RepositoryVersionEntity sourceRepoVersion,
      RepositoryVersionEntity targetRepoVersion) throws Exception {
    String hostName = "h1";

    clusters.addCluster(clusterName, sourceRepoVersion.getStackId());

    // add a host component
    clusters.addHost(hostName);

    Host host = clusters.getHost(hostName);

    Map<String, String> hostAttributes = new HashMap<>();
    hostAttributes.put("os_family", "redhat");
    hostAttributes.put("os_release_version", "6");
    host.setHostAttributes(hostAttributes);

    HostVersionEntity entity = new HostVersionEntity();
    entity.setHostEntity(hostDAO.findByName(hostName));
    entity.setRepositoryVersion(targetRepoVersion);
    entity.setState(RepositoryVersionState.INSTALLING);
    hostVersionDAO.create(entity);
  }
Tests upgrade-related server side actions
ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/UpgradeActionTest.java