@Test
  public void testMaintenance() throws Exception {
    String stackVersion = "HDP-2.0.6";
    StackId stackId = new StackId(stackVersion);
    String clusterName = "c2";
    createCluster(stackId, clusterName);

    final String hostName = "h3";
    Set<String> hostNames = new HashSet<>();
    hostNames.add(hostName);
    addHostsToCluster(clusterName, hostAttributes, hostNames);

    Cluster cluster = clusters.getCluster(clusterName);

    helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion());

    HostEntity hostEntity = hostDAO.findByName(hostName);
    Assert.assertNotNull(hostEntity);

    ServiceComponentHost sch1 = createNewServiceComponentHost(cluster, "HDFS", "NAMENODE", hostName);
    //ServiceComponentHost sch2 = createNewServiceComponentHost(cluster, "HDFS", "DATANODE", hostName);
    //ServiceComponentHost sch3 = createNewServiceComponentHost(cluster, "MAPREDUCE2", "HISTORYSERVER", hostName);

    HostComponentDesiredStateEntity entity = hostComponentDesiredStateDAO.findByIndex(
      cluster.getClusterId(),
      sch1.getServiceName(),
      sch1.getServiceComponentName(),
      hostEntity.getHostId()
    );
    Assert.assertEquals(MaintenanceState.OFF, entity.getMaintenanceState());
    Assert.assertEquals(MaintenanceState.OFF, sch1.getMaintenanceState());

    sch1.setMaintenanceState(MaintenanceState.ON);
    Assert.assertEquals(MaintenanceState.ON, sch1.getMaintenanceState());

    entity = hostComponentDesiredStateDAO.findByIndex(
      cluster.getClusterId(),
      sch1.getServiceName(),
      sch1.getServiceComponentName(),
      hostEntity.getHostId()
    );
    Assert.assertEquals(MaintenanceState.ON, entity.getMaintenanceState());
  }
Helper method to create a configuration
@param cluster the cluster
@param type the config type
@param tag the config tag
@param values the values for the config
ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java