@Test
  public void testDuplicates() throws Exception {
    HostEntity host1 = hostDAO.findByName("test_host1");

    RepositoryVersionEntity repoVersion = helper.getOrCreateRepositoryVersion(HDP_22_STACK, repoVersion_2200);

    HostVersionEntity hostVersionEntity1 = new HostVersionEntity(host1, repoVersion, RepositoryVersionState.CURRENT);

    try {
      hostVersionDAO.create(hostVersionEntity1);
      Assert.fail("Each host can have a relationship to a repo version, but cannot have more than one for the same repo");
    } catch (Exception e) {
      // expected
    }

  }
Test the {@link HostVersionDAO#findByClusterStackVersionAndHost(String, StackId, String, String)} method.
ambari-server/src/test/java/org/apache/ambari/server/orm/dao/HostVersionDAOTest.java