@Test
public void testAlertHistoryPredicate() throws Exception {

  m_helper.installHdfsService(m_cluster, m_serviceFactory,
      m_componentFactory, m_schFactory, HOSTNAME);
  m_alertHelper.populateData(m_cluster);
  Predicate clusterPredicate = null;
  Predicate hdfsPredicate = null;
  Predicate yarnPredicate = null;
  Predicate clusterAndHdfsPredicate = null;
  Predicate clusterAndHdfsAndCriticalPredicate = null;
  Predicate hdfsAndCriticalOrWarningPredicate = null;
  Predicate alertNamePredicate = null;
  Predicate historyIdPredicate = null;
  clusterPredicate = new PredicateBuilder().property(
      AlertHistoryResourceProvider.ALERT_HISTORY_CLUSTER_NAME).equals("c1").toPredicate();
  AlertHistoryRequest request = new AlertHistoryRequest();
  request.Predicate = clusterPredicate;
  List<AlertHistoryEntity> histories = m_dao.findAll(request);
  assertEquals(3, histories.size());
  hdfsPredicate = new PredicateBuilder().property(
      AlertHistoryResourceProvider.ALERT_HISTORY_SERVICE_NAME).equals("HDFS").toPredicate();
  yarnPredicate = new PredicateBuilder().property(
      AlertHistoryResourceProvider.ALERT_HISTORY_SERVICE_NAME).equals("YARN").toPredicate();
  clusterAndHdfsPredicate = new PredicateBuilder().property(
      AlertHistoryResourceProvider.ALERT_HISTORY_CLUSTER_NAME).equals("c1").and().property(
      AlertHistoryResourceProvider.ALERT_HISTORY_SERVICE_NAME).equals("HDFS").toPredicate();
  clusterAndHdfsPredicate = new PredicateBuilder().property(
      AlertHistoryResourceProvider.ALERT_HISTORY_CLUSTER_NAME).equals("c1").and().property(
      AlertHistoryResourceProvider.ALERT_HISTORY_SERVICE_NAME).equals("HDFS").toPredicate();
  clusterAndHdfsAndCriticalPredicate = new PredicateBuilder().property(
      AlertHistoryResourceProvider.ALERT_HISTORY_CLUSTER_NAME).equals("c1").and().property(
      AlertHistoryResourceProvider.ALERT_HISTORY_SERVICE_NAME).equals("HDFS").and().property(
      AlertHistoryResourceProvider.ALERT_HISTORY_STATE).equals(
      AlertState.CRITICAL.name()).toPredicate();
  hdfsAndCriticalOrWarningPredicate = new PredicateBuilder().begin().property(
      AlertHistoryResourceProvider.ALERT_HISTORY_SERVICE_NAME).equals("HDFS").and().property(
      AlertHistoryResourceProvider.ALERT_HISTORY_STATE).equals(
      AlertState.CRITICAL.name()).end().or().property(
      AlertHistoryResourceProvider.ALERT_HISTORY_STATE).equals(
      AlertState.WARNING.name()).toPredicate();
  alertNamePredicate = new PredicateBuilder().property(
      AlertHistoryResourceProvider.ALERT_HISTORY_DEFINITION_NAME).equals(
      "NAMENODE").toPredicate();
  request.Predicate = hdfsPredicate;
  histories = m_dao.findAll(request);
  assertEquals(2, histories.size());
  request.Predicate = yarnPredicate;
  histories = m_dao.findAll(request);
  assertEquals(1, histories.size());
  request.Predicate = clusterAndHdfsPredicate;
  histories = m_dao.findAll(request);
  assertEquals(2, histories.size());
  request.Predicate = clusterAndHdfsAndCriticalPredicate;
  histories = m_dao.findAll(request);
  assertEquals(0, histories.size());
  request.Predicate = hdfsAndCriticalOrWarningPredicate;
  histories = m_dao.findAll(request);
  assertEquals(1, histories.size());
  request.Predicate = alertNamePredicate;
  histories = m_dao.findAll(request);
  assertEquals(1, histories.size());
  historyIdPredicate = new PredicateBuilder().property(
      AlertHistoryResourceProvider.ALERT_HISTORY_ID).equals(
      histories.get(0).getAlertId()).toPredicate();
  request.Predicate = historyIdPredicate;
  histories = m_dao.findAll(request);
  assertEquals(1, histories.size());
}