private void testCheckWhenLogSearchNotAvailable(Authentication authentication, boolean authorizedForLogSearch) throws Exception {

    final String expectedStackName = "HDP";
    final String expectedStackVersion = "2.4";
    final String expectedComponentName = "NAMENODE";
    final String expectedServiceName = "HDFS";
    final String expectedLogSearchComponentName = "hdfs_namenode";

    EasyMockSupport mockSupport = new EasyMockSupport();

    Resource resourceMock =
      mockSupport.createMock(Resource.class);
    expect(resourceMock.getPropertyValue(PropertyHelper.getPropertyId("HostRoles", "component_name"))).andReturn(expectedComponentName).atLeastOnce();
    expect(resourceMock.getPropertyValue(PropertyHelper.getPropertyId("HostRoles", "host_name"))).andReturn("c6401.ambari.apache.org").atLeastOnce();
    expect(resourceMock.getPropertyValue(PropertyHelper.getPropertyId("HostRoles", "cluster_name"))).andReturn("clusterone").atLeastOnce();

    Request requestMock =
      mockSupport.createMock(Request.class);

    Predicate predicateMock =
      mockSupport.createMock(Predicate.class);

    AmbariManagementController controllerMock =
      mockSupport.createMock(AmbariManagementController.class);

    Clusters clustersMock =
      mockSupport.createMock(Clusters.class);

    Cluster clusterMock =
      mockSupport.createMock(Cluster.class);

    LogSearchDataRetrievalService dataRetrievalServiceMock =
      mockSupport.createMock(LogSearchDataRetrievalService.class);

    LoggingRequestHelperFactory loggingRequestHelperFactoryMock =
        mockSupport.createMock(LoggingRequestHelperFactory.class);

    if(authorizedForLogSearch) {
      AmbariMetaInfo metaInfoMock =
          mockSupport.createMock(AmbariMetaInfo.class);

      StackId stackIdMock =
          mockSupport.createMock(StackId.class);

      LogDefinition logDefinitionMock =
          mockSupport.createMock(LogDefinition.class);

      ComponentInfo componentInfoMock =
          mockSupport.createMock(ComponentInfo.class);

      LoggingRequestHelper loggingRequestHelperMock =
          mockSupport.createMock(LoggingRequestHelper.class);

      Service serviceMock = mockSupport.createNiceMock(Service.class);
      expect(controllerMock.findServiceName(clusterMock, expectedComponentName)).andReturn(expectedServiceName).atLeastOnce();
      expect(clusterMock.getService(expectedServiceName)).andReturn(serviceMock).anyTimes();
      expect(serviceMock.getDesiredStackId()).andReturn(stackIdMock).anyTimes();


      expect(controllerMock.getAmbariMetaInfo()).andReturn(metaInfoMock).atLeastOnce();
      expect(stackIdMock.getStackName()).andReturn(expectedStackName).atLeastOnce();
      expect(stackIdMock.getStackVersion()).andReturn(expectedStackVersion).atLeastOnce();

      expect(metaInfoMock.getComponent(expectedStackName, expectedStackVersion, expectedServiceName, expectedComponentName)).andReturn(componentInfoMock).atLeastOnce();

      // simulate the case when LogSearch is not deployed, or is not available for some reason
      expect(dataRetrievalServiceMock.getLogFileNames(expectedLogSearchComponentName, "c6401.ambari.apache.org", "clusterone")).andReturn(null).atLeastOnce();

      expect(componentInfoMock.getLogs()).andReturn(Collections.singletonList(logDefinitionMock)).atLeastOnce();
      expect(logDefinitionMock.getLogId()).andReturn(expectedLogSearchComponentName).atLeastOnce();

      expect(loggingRequestHelperFactoryMock.getHelper(anyObject(AmbariManagementController.class), anyObject(String.class)))
          .andReturn(loggingRequestHelperMock).atLeastOnce();
    }

    expect(controllerMock.getClusters()).andReturn(clustersMock).atLeastOnce();
    expect(clustersMock.getCluster("clusterone")).andReturn(clusterMock).atLeastOnce();
    expect(clusterMock.getResourceId()).andReturn(4L).atLeastOnce();

    mockSupport.replayAll();

    AuthorizationHelperInitializer.viewInstanceDAOReturningNull();
    SecurityContextHolder.getContext().setAuthentication(authentication);

    LoggingSearchPropertyProvider propertyProvider =
      new LoggingSearchPropertyProvider();

    propertyProvider.setAmbariManagementController(controllerMock);
    propertyProvider.setLogSearchDataRetrievalService(dataRetrievalServiceMock);
    propertyProvider.setLoggingRequestHelperFactory(loggingRequestHelperFactoryMock);


    // execute the populate resources method, verify that no exceptions occur, due to
    // the LogSearch helper not being available
    Set<Resource> returnedResources =
      propertyProvider.populateResources(Collections.singleton(resourceMock), requestMock, predicateMock);

    // verify that the set of resources has not changed in size
    assertEquals("Returned resource set was of an incorrect size",
      1, returnedResources.size());

    // verify that the single resource passed in was returned
    assertSame("Returned resource was not the expected instance.",
      resourceMock, returnedResources.iterator().next());

    mockSupport.verifyAll();
  }
Verifies that this property provider implementation will
properly handle the case of LogSearch not being deployed in
the cluster or available.

@param authentication the authenticated user
@param authorizedForLogSearch true of the user is expected to be authorized; otherwise false
@throws Exception
ambari-server/src/test/java/org/apache/ambari/server/controller/logging/LoggingSearchPropertyProviderTest.java