@Test
  public void testFindCurrentByHost() throws Exception {
    // create a host
    AlertDefinitionEntity hostDef = new AlertDefinitionEntity();
    hostDef.setDefinitionName("Host Alert Definition ");
    hostDef.setServiceName("YARN");
    hostDef.setComponentName(null);
    hostDef.setClusterId(m_cluster.getClusterId());
    hostDef.setHash(UUID.randomUUID().toString());
    hostDef.setScheduleInterval(Integer.valueOf(60));
    hostDef.setScope(Scope.HOST);
    hostDef.setSource("{\"type\" : \"SCRIPT\"}");
    hostDef.setSourceType(SourceType.SCRIPT);
    m_definitionDao.create(hostDef);

    // history for the definition
    AlertHistoryEntity history = new AlertHistoryEntity();
    history.setServiceName(hostDef.getServiceName());
    history.setClusterId(m_cluster.getClusterId());
    history.setAlertDefinition(hostDef);
    history.setAlertLabel(hostDef.getDefinitionName());
    history.setAlertText(hostDef.getDefinitionName());
    history.setAlertTimestamp(Long.valueOf(1L));
    history.setHostName(HOSTNAME);
    history.setAlertState(AlertState.OK);
    m_dao.create(history);

    // current for the history
    AlertCurrentEntity current = new AlertCurrentEntity();
    current.setOriginalTimestamp(1L);
    current.setLatestTimestamp(2L);
    current.setAlertHistory(history);
    m_dao.create(current);

    Predicate hostPredicate = null;
    hostPredicate = new PredicateBuilder().property(
        AlertResourceProvider.ALERT_HOST).equals(HOSTNAME).toPredicate();

    AlertCurrentRequest request = new AlertCurrentRequest();
    request.Predicate = hostPredicate;

    List<AlertCurrentEntity> currentAlerts = m_dao.findAll(request);
    assertNotNull(currentAlerts);
    assertEquals(1, currentAlerts.size());

    hostPredicate = new PredicateBuilder().property(
        AlertResourceProvider.ALERT_HOST).equals("invalid.apache.org").toPredicate();

    request = new AlertCurrentRequest();
    request.Predicate = hostPredicate;
    currentAlerts = m_dao.findAll(request);

    assertNotNull(currentAlerts);
    assertEquals(0, currentAlerts.size());
  }
Test looking up current by a host name.
ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertsDAOTest.java