@Test
  public void testHostMaintenanceMode() throws Exception {
    List<AlertCurrentEntity> alerts = getMockAlerts("HOST");

    AlertCurrentEntity hostAlert = alerts.get(0);
    AlertCurrentEntity serviceAlert = alerts.get(1);
    AlertCurrentEntity componentAlert = alerts.get(2);

    EasyMock.expect(hostAlert.getMaintenanceState()).andReturn(MaintenanceState.OFF).atLeastOnce();
    hostAlert.setMaintenanceState(MaintenanceState.ON);
    EasyMock.expectLastCall().once();

    EasyMock.expect(m_alertsDAO.merge(hostAlert)).andReturn(hostAlert).once();

    Host host = EasyMock.createNiceMock(Host.class);
    EasyMock.expect(host.getHostName()).andReturn(HOSTNAME).atLeastOnce();

    STOMPUpdatePublisher stompUpdatePublisher = injector.getInstance(STOMPUpdatePublisher.class);
    Capture<AlertUpdateEvent> alertUpdateEventCapture = EasyMock.newCapture();
    stompUpdatePublisher.publish(EasyMock.capture(alertUpdateEventCapture));

    EasyMock.replay(hostAlert, serviceAlert, componentAlert, host, m_alertsDAO, stompUpdatePublisher);

    MaintenanceModeEvent hostEvent = new MaintenanceModeEvent(MaintenanceState.ON, 1 /* cluster id */, host);
    m_eventPublisher.publish(hostEvent);

    EasyMock.verify(hostAlert, serviceAlert, componentAlert, host, m_alertsDAO);

    AlertUpdateEvent alertUpdateEvent = alertUpdateEventCapture.getValue();
    Assert.assertNotNull(alertUpdateEvent);
    Assert.assertEquals(1, alertUpdateEvent.getSummaries().size());
    Assert.assertTrue(alertUpdateEvent.getSummaries().containsKey(CLUSTER_ID));
    Assert.assertEquals(1, alertUpdateEvent.getSummaries().get(CLUSTER_ID).size());
    Assert.assertTrue(alertUpdateEvent.getSummaries().get(CLUSTER_ID).containsKey(DEFINITION_NAME));
    Assert.assertEquals(1, alertUpdateEvent.getSummaries().get(CLUSTER_ID).get(DEFINITION_NAME).State.Ok.MaintenanceCount);
  }
Tests that only the host alert has its maintenance mode changed.

@throws Exception
ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/AlertMaintenanceModeListenerTest.java