@Test
  public void testCreateServicesWithInvalidRequest() throws Exception, AuthorizationException {
    // invalid request
    // dups in requests
    // multi cluster updates

    Set<ServiceRequest> set1 = new HashSet<>();

    try {
      set1.clear();
      ServiceRequest rInvalid = new ServiceRequest(null, null, null, null, null);
      set1.add(rInvalid);
      ServiceResourceProviderTest.createServices(controller, repositoryVersionDAO, set1);
      fail("Expected failure for invalid requests");
    } catch (Exception e) {
      // Expected
    }

    try {
      set1.clear();
      ServiceRequest rInvalid = new ServiceRequest("foo", null, null, null, null);
      set1.add(rInvalid);
      ServiceResourceProviderTest.createServices(controller, repositoryVersionDAO, set1);
      fail("Expected failure for invalid requests");
    } catch (Exception e) {
      // Expected
    }

    try {
      set1.clear();
      ServiceRequest rInvalid = new ServiceRequest("foo", "bar", null, null, null);
      set1.add(rInvalid);
      ServiceResourceProviderTest.createServices(controller, repositoryVersionDAO, set1);
      fail("Expected failure for invalid cluster");
    } catch (Exception e) {
      // Expected
      Assert.assertTrue(checkExceptionType(e, ClusterNotFoundException.class));
    }

    String cluster1 = getUniqueName();
    String cluster2 = getUniqueName();


    clusters.addCluster(cluster1, new StackId("HDP-0.1"));
    clusters.addCluster(cluster2, new StackId("HDP-0.1"));

    try {
      set1.clear();
      ServiceRequest valid1 = new ServiceRequest(cluster1, "HDFS", null, null, null);
      ServiceRequest valid2 = new ServiceRequest(cluster1, "HDFS", null, null, null);
      set1.add(valid1);
      set1.add(valid2);
      ServiceResourceProviderTest.createServices(controller, repositoryVersionDAO, set1);
      fail("Expected failure for invalid requests");
    } catch (Exception e) {
      // Expected
    }

    try {
      set1.clear();
      ServiceRequest valid1 = new ServiceRequest(cluster1, "bar", repositoryVersion02.getId(), State.STARTED.toString(), null);
      set1.add(valid1);
      ServiceResourceProviderTest.createServices(controller, repositoryVersionDAO, set1);
      fail("Expected failure for invalid service");
    } catch (Exception e) {
      // Expected
    }


    try {
      set1.clear();
      ServiceRequest valid1 = new ServiceRequest(cluster1, "HDFS", repositoryVersion02.getId(), State.STARTED.toString(), null);
      ServiceRequest valid2 = new ServiceRequest(cluster2, "HDFS", repositoryVersion02.getId(), State.STARTED.toString(), null);
      set1.add(valid1);
      set1.add(valid2);
      ServiceResourceProviderTest.createServices(controller, repositoryVersionDAO, set1);
      fail("Expected failure for multiple clusters");
    } catch (Exception e) {
      // Expected
    }

    Assert.assertNotNull(clusters.getCluster(cluster1));
    Assert.assertEquals(0, clusters.getCluster(cluster1).getServices().size());

    set1.clear();
    ServiceRequest valid = new ServiceRequest(cluster1, "HDFS", repositoryVersion02.getId(), null, null);
    set1.add(valid);
    ServiceResourceProviderTest.createServices(controller, repositoryVersionDAO, set1);

    try {
      set1.clear();
      ServiceRequest valid1 = new ServiceRequest(cluster1, "HDFS", repositoryVersion02.getId(), State.STARTED.toString(), null);
      ServiceRequest valid2 = new ServiceRequest(cluster1, "HDFS", repositoryVersion02.getId(), State.STARTED.toString(), null);
      set1.add(valid1);
      set1.add(valid2);
      ServiceResourceProviderTest.createServices(controller, repositoryVersionDAO, set1);
      fail("Expected failure for existing service");
    } catch (Exception e) {
      // Expected
    }

    Assert.assertEquals(1, clusters.getCluster(cluster1).getServices().size());

  }
Allows to set maintenanceStateHelper. For use when there is anything to test
with maintenance mode.
ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java