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

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

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

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

    ServiceComponentHost serviceComponentHost = EasyMock.createNiceMock(ServiceComponentHost.class);
    EasyMock.expect(serviceComponentHost.getHostName()).andReturn(HOSTNAME).atLeastOnce();
    EasyMock.expect(serviceComponentHost.getServiceName()).andReturn(SERVICE).atLeastOnce();
    EasyMock.expect(serviceComponentHost.getServiceComponentName()).andReturn(COMPONENT).atLeastOnce();

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

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

    MaintenanceModeEvent serviceComponentHostEvent = new MaintenanceModeEvent(MaintenanceState.ON,
        serviceComponentHost);

    m_eventPublisher.publish(serviceComponentHostEvent);

    EasyMock.verify(hostAlert, serviceAlert, componentAlert, serviceComponentHost, 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 service alert has its maintenance mode changed.
ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/AlertMaintenanceModeListenerTest.java