@SuppressWarnings("unchecked")
  private void testGetClusterGroupedSummary(Authentication authentication) throws Exception {
    expect(m_dao.findAll(capture(EasyMock.<AlertCurrentRequest>newCapture()))).andReturn(
        getMockEntitiesManyStates()).anyTimes();

    replay(m_dao);

    SecurityContextHolder.getContext().setAuthentication(authentication);

    Request request = PropertyHelper.getReadRequest(
        AlertResourceProvider.ALERT_ID, AlertResourceProvider.ALERT_DEFINITION_NAME,
        AlertResourceProvider.ALERT_LABEL, AlertResourceProvider.ALERT_STATE,
        AlertResourceProvider.ALERT_ORIGINAL_TIMESTAMP,
        AlertResourceProvider.ALERT_TEXT);

    Predicate predicate = new PredicateBuilder().property(
        AlertResourceProvider.ALERT_CLUSTER_NAME).equals("c1").toPredicate();

    AlertResourceProvider provider = createProvider();
    Set<Resource> results = provider.getResources(request, predicate);

    verify(m_dao);

    AlertSummaryGroupedRenderer renderer = new AlertSummaryGroupedRenderer();
    ResultImpl result = new ResultImpl(true);
    TreeNode<Resource> resources = result.getResultTree();

    AtomicInteger alertResourceId = new AtomicInteger(1);
    for (Resource resource : results) {
      resources.addChild(resource, "Alert " + alertResourceId.getAndIncrement());
    }

    Result groupedSummary = renderer.finalizeResult(result);
    Assert.assertNotNull(groupedSummary);

    // pull out the alerts_summary child set by the renderer
    TreeNode<Resource> summaryResultTree = groupedSummary.getResultTree();
    TreeNode<Resource> summaryResources = summaryResultTree.getChild("alerts_summary_grouped");

    Resource summaryResource = summaryResources.getObject();
    List<AlertDefinitionSummary> summaryList = (List<AlertDefinitionSummary>) summaryResource.getPropertyValue("alerts_summary_grouped");
    assertEquals(4, summaryList.size());

    AlertDefinitionSummary nnSummary = null;
    AlertDefinitionSummary rmSummary = null;
    AlertDefinitionSummary hiveSummary = null;
    AlertDefinitionSummary flumeSummary = null;

    for (AlertDefinitionSummary summary : summaryList) {
      if (summary.Name.equals("hdfs_namenode")) {
        nnSummary = summary;
      } else if (summary.Name.equals("yarn_resourcemanager")) {
        rmSummary = summary;
      } else if (summary.Name.equals("hive_server")) {
        hiveSummary = summary;
      } else if (summary.Name.equals("flume_handler")) {
        flumeSummary = summary;
      }
    }

    Assert.assertNotNull(nnSummary);
    Assert.assertNotNull(rmSummary);
    Assert.assertNotNull(hiveSummary);
    Assert.assertNotNull(flumeSummary);

    Assert.assertEquals(10, nnSummary.State.Ok.Count);
    Assert.assertEquals(ALERT_VALUE_TEXT, nnSummary.State.Ok.AlertText);
    Assert.assertEquals(0, nnSummary.State.Warning.Count);
    Assert.assertEquals(0, nnSummary.State.Critical.Count);
    Assert.assertEquals(0, nnSummary.State.Unknown.Count);

    Assert.assertEquals(0, rmSummary.State.Ok.Count);
    Assert.assertEquals(2, rmSummary.State.Warning.Count);
    Assert.assertEquals(ALERT_VALUE_TEXT, rmSummary.State.Warning.AlertText);
    Assert.assertEquals(0, rmSummary.State.Critical.Count);
    Assert.assertEquals(0, rmSummary.State.Unknown.Count);

    Assert.assertEquals(0, hiveSummary.State.Ok.Count);
    Assert.assertEquals(0, hiveSummary.State.Warning.Count);
    Assert.assertEquals(1, hiveSummary.State.Critical.Count);
    Assert.assertEquals(ALERT_VALUE_TEXT, hiveSummary.State.Critical.AlertText);
    Assert.assertEquals(0, hiveSummary.State.Unknown.Count);

    Assert.assertEquals(0, flumeSummary.State.Ok.Count);
    Assert.assertEquals(0, flumeSummary.State.Warning.Count);
    Assert.assertEquals(0, flumeSummary.State.Critical.Count);
    Assert.assertEquals(3, flumeSummary.State.Unknown.Count);
    Assert.assertEquals(ALERT_VALUE_TEXT, flumeSummary.State.Unknown.AlertText);
  }
Tests that the {@link AlertSummaryGroupedRenderer} correctly transforms the
alert data.

@throws Exception
ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertResourceProviderTest.java