private void addMoreVersions() {
    ClusterEntity clusterEntity = clusterDAO.findByName("test_cluster1");

    RepositoryVersionEntity repositoryVersionEnt_2_2_0_1 = helper.getOrCreateRepositoryVersion(HDP_22_STACK, repoVersion_2201);


    HostEntity[] hostEntities = clusterEntity.getHostEntities().toArray(new HostEntity[clusterEntity.getHostEntities().size()]);
    // Must sort by host name in ascending order to ensure that state is accurately set later on.
    Arrays.sort(hostEntities);

    // For each of the hosts, add a host version
    for (HostEntity host : hostEntities) {
      HostVersionEntity hostVersionEntity = new HostVersionEntity(host, repositoryVersionEnt_2_2_0_1, RepositoryVersionState.INSTALLED);
      hostVersionDAO.create(hostVersionEntity);
    }

    // For each of the hosts, add one more host version
    RepositoryVersionEntity repositoryVersionEnt_2_2_0_2 = helper.getOrCreateRepositoryVersion(HDP_22_STACK, repoVersion_2202);
    for (int i = 0; i < hostEntities.length; i++) {
      RepositoryVersionState desiredState = null;
      if (i % 3 == 0) {
        desiredState = RepositoryVersionState.INSTALLED;
      }
      if (i % 3 == 1) {
        desiredState = RepositoryVersionState.INSTALLING;
      }
      if (i % 3 == 2) {
        desiredState = RepositoryVersionState.INSTALL_FAILED;
      }


      HostVersionEntity hostVersionEntity = new HostVersionEntity(hostEntities[i], repositoryVersionEnt_2_2_0_2, desiredState);
      hostVersionDAO.create(hostVersionEntity);
    }
  }
Helper function to bootstrap additional data on top of the default data.
ambari-server/src/test/java/org/apache/ambari/server/orm/dao/HostVersionDAOTest.java