@Test
  public void testServiceOperationsAllowance() throws Exception {
    Injector injector = createStrictMock(Injector.class);
    MaintenanceStateHelper maintenanceStateHelper =
            createMockBuilder(MaintenanceStateHelper.class)
                    .withConstructor(injector)
                    .createNiceMock();

    Service service = createMock(Service.class);

    // only called for Cluster level
    expect(service.getMaintenanceState()).andReturn(MaintenanceState.ON);
    expect(service.getMaintenanceState()).andReturn(MaintenanceState.OFF);

    replay(maintenanceStateHelper, service);


    Assert.assertEquals(false, maintenanceStateHelper.isOperationAllowed(Resource.Type.Cluster, service));
    Assert.assertEquals(true, maintenanceStateHelper.isOperationAllowed(Resource.Type.Service, service));
    Assert.assertEquals(true, maintenanceStateHelper.isOperationAllowed(Resource.Type.Host, service));
    Assert.assertEquals(true, maintenanceStateHelper.isOperationAllowed(Resource.Type.HostComponent, service));

    Assert.assertEquals(true, maintenanceStateHelper.isOperationAllowed(Resource.Type.Cluster, service));
    Assert.assertEquals(true, maintenanceStateHelper.isOperationAllowed(Resource.Type.Service, service));
    Assert.assertEquals(true, maintenanceStateHelper.isOperationAllowed(Resource.Type.Host, service));
    Assert.assertEquals(true, maintenanceStateHelper.isOperationAllowed(Resource.Type.HostComponent, service));

    verify(maintenanceStateHelper, service);
  }
Tests that the service MM state is calculated correctly for an alert.

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