@Test
  public void testServiceWidgetCreationOnServiceCreate() throws Exception {
    String cluster1 = getUniqueName();
    ClusterRequest r = new ClusterRequest(null, cluster1,
      State.INSTALLED.name(), SecurityType.NONE, "OTHER-2.0", null);
    controller.createCluster(r);
    String serviceName = "HBASE";
    clusters.getCluster(cluster1).setDesiredStackVersion(new StackId("OTHER-2.0"));

    RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(
        new StackId("OTHER-2.0"), "2.0-1234");

    createService(cluster1, serviceName, repositoryVersion, State.INIT);

    Service s = clusters.getCluster(cluster1).getService(serviceName);
    Assert.assertNotNull(s);
    Assert.assertEquals(serviceName, s.getName());
    Assert.assertEquals(cluster1, s.getCluster().getClusterName());

    WidgetDAO widgetDAO = injector.getInstance(WidgetDAO.class);
    WidgetLayoutDAO widgetLayoutDAO = injector.getInstance(WidgetLayoutDAO.class);
    List<WidgetEntity> widgetEntities = widgetDAO.findAll();
    List<WidgetLayoutEntity> layoutEntities = widgetLayoutDAO.findAll();

    Assert.assertNotNull(widgetEntities);
    Assert.assertFalse(widgetEntities.isEmpty());
    Assert.assertNotNull(layoutEntities);
    Assert.assertFalse(layoutEntities.isEmpty());

    WidgetEntity candidateVisibleEntity = null;
    for (WidgetEntity entity : widgetEntities) {
      if (entity.getWidgetName().equals("OPEN_CONNECTIONS")) {
        candidateVisibleEntity = entity;
      }
    }
    Assert.assertNotNull(candidateVisibleEntity);
    Assert.assertEquals("GRAPH", candidateVisibleEntity.getWidgetType());
    Assert.assertEquals("ambari", candidateVisibleEntity.getAuthor());
    Assert.assertEquals("CLUSTER", candidateVisibleEntity.getScope());
    Assert.assertNotNull(candidateVisibleEntity.getMetrics());
    Assert.assertNotNull(candidateVisibleEntity.getProperties());
    Assert.assertNotNull(candidateVisibleEntity.getWidgetValues());

    WidgetLayoutEntity candidateLayoutEntity = null;
    for (WidgetLayoutEntity entity : layoutEntities) {
      if (entity.getLayoutName().equals("default_hbase_layout")) {
        candidateLayoutEntity = entity;
      }
    }
    Assert.assertNotNull(candidateLayoutEntity);
    List<WidgetLayoutUserWidgetEntity> layoutUserWidgetEntities =
      candidateLayoutEntity.getListWidgetLayoutUserWidgetEntity();
    Assert.assertNotNull(layoutUserWidgetEntities);
    Assert.assertEquals(4, layoutUserWidgetEntities.size());
    Assert.assertEquals("RS_READS_WRITES", layoutUserWidgetEntities.get(0).getWidget().getWidgetName());
    Assert.assertEquals("OPEN_CONNECTIONS", layoutUserWidgetEntities.get(1).getWidget().getWidgetName());
    Assert.assertEquals("FILES_LOCAL", layoutUserWidgetEntities.get(2).getWidget().getWidgetName());
    Assert.assertEquals("UPDATED_BLOCKED_TIME", layoutUserWidgetEntities.get(3).getWidget().getWidgetName());
    Assert.assertEquals("HBASE_SUMMARY", layoutUserWidgetEntities.get(0).getWidget().getDefaultSectionName());

    File widgetsFile  = ambariMetaInfo.getCommonWidgetsDescriptorFile();
    assertNotNull(widgetsFile);
    assertEquals("src/test/resources/widgets.json", widgetsFile.getPath());
    assertTrue(widgetsFile.exists());

    candidateLayoutEntity = null;
    for (WidgetLayoutEntity entity : layoutEntities) {
      if (entity.getLayoutName().equals("default_system_heatmap")) {
        candidateLayoutEntity = entity;
        break;
      }
    }
    Assert.assertNotNull(candidateLayoutEntity);
    Assert.assertEquals("ambari", candidateVisibleEntity.getAuthor());
    Assert.assertEquals("CLUSTER", candidateVisibleEntity.getScope());
  }
Ensure that ServiceNotFoundException is handled where there are multiple requests as would be the
case when an OR predicate is provided in the query.
ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java