@Test
  @PrepareForTest(AmbariServer.class)
  public void testGetLogicalRequestStatusWithNoTasks() throws Exception {
    Iterable<CalculatedStatus> statusList = ImmutableList.of(CalculatedStatus.COMPLETED, CalculatedStatus.PENDING, CalculatedStatus.ABORTED);
    for (CalculatedStatus calculatedStatus : statusList) {
      // Given
      resetAll();

      PowerMock.mockStatic(AmbariServer.class);
      AmbariManagementController managementController = createMock(AmbariManagementController.class);
      ActionManager actionManager = createNiceMock(ActionManager.class);
      Clusters clusters = createNiceMock(Clusters.class);
      Cluster cluster = createNiceMock(Cluster.class);
      RequestEntity requestMock = createNiceMock(RequestEntity.class);
      Blueprint blueprint = createNiceMock(Blueprint.class);
      ClusterTopology topology = createNiceMock(ClusterTopology.class);
      HostGroup hostGroup = createNiceMock(HostGroup.class);
      TopologyRequest topologyRequest = createNiceMock(TopologyRequest.class);
      LogicalRequest logicalRequest = createNiceMock(LogicalRequest.class);
      HostRequest hostRequest = createNiceMock(HostRequest.class);

      Long requestId = 100L;
      Long clusterId = 2L;
      String clusterName = "cluster1";
      String hostGroupName = "host_group_1";
      HostGroupInfo hostGroupInfo = new HostGroupInfo(hostGroupName);
      hostGroupInfo.setRequestedCount(1);
      Map<String, HostGroupInfo> hostGroupInfoMap = ImmutableMap.of(hostGroupName, hostGroupInfo);
      Collection<HostRequest> hostRequests = Collections.singletonList(hostRequest);
      Map<Long, HostRoleCommandStatusSummaryDTO> dtoMap = Collections.emptyMap();

      expect(AmbariServer.getController()).andReturn(managementController).anyTimes();
      expect(requestMock.getRequestContext()).andReturn("this is a context").anyTimes();
      expect(requestMock.getRequestId()).andReturn(requestId).anyTimes();
      expect(hostGroup.getName()).andReturn(hostGroupName).anyTimes();
      expect(blueprint.getHostGroup(hostGroupName)).andReturn(hostGroup).anyTimes();
      expect(topology.getClusterId()).andReturn(2L).anyTimes();
      expect(cluster.getClusterId()).andReturn(clusterId).anyTimes();
      expect(cluster.getClusterName()).andReturn(clusterName).anyTimes();
      expect(managementController.getActionManager()).andReturn(actionManager).anyTimes();
      expect(managementController.getClusters()).andReturn(clusters).anyTimes();
      expect(clusters.getCluster(eq(clusterName))).andReturn(cluster).anyTimes();
      expect(clusters.getClusterById(clusterId)).andReturn(cluster).anyTimes();
      Collection<Long> requestIds = anyObject();
      expect(requestDAO.findByPks(requestIds, eq(true))).andReturn(Lists.newArrayList(requestMock));
      expect(hrcDAO.findAggregateCounts((Long) anyObject())).andReturn(dtoMap).anyTimes();
      expect(topologyManager.getRequest(requestId)).andReturn(logicalRequest).anyTimes();
      expect(topologyManager.getRequests(eq(Collections.singletonList(requestId)))).andReturn(Collections.singletonList(logicalRequest)).anyTimes();
      expect(topologyManager.getStageSummaries(EasyMock.<Long>anyObject())).andReturn(dtoMap).anyTimes();

      expect(topologyRequest.getHostGroupInfo()).andReturn(hostGroupInfoMap).anyTimes();
      expect(topology.getBlueprint()).andReturn(blueprint).anyTimes();
      expect(blueprint.shouldSkipFailure()).andReturn(true).anyTimes();

      expect(logicalRequest.getHostRequests()).andReturn(hostRequests).anyTimes();
      expect(logicalRequest.constructNewPersistenceEntity()).andReturn(requestMock).anyTimes();
      expect(logicalRequest.calculateStatus()).andReturn(calculatedStatus).anyTimes();
      Optional<String> failureReason = calculatedStatus == CalculatedStatus.ABORTED
        ? Optional.of("some reason")
        : Optional.<String>absent();
      expect(logicalRequest.getFailureReason()).andReturn(failureReason).anyTimes();

      prepareGetAuthorizationExpectations();

      replayAll();

      Resource.Type type = Resource.Type.Request;
      ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
        type,
        managementController
      );

      Set<String> propertyIds = ImmutableSet.of(
        RequestResourceProvider.REQUEST_ID_PROPERTY_ID,
        RequestResourceProvider.REQUEST_STATUS_PROPERTY_ID,
        RequestResourceProvider.REQUEST_PROGRESS_PERCENT_ID,
        RequestResourceProvider.REQUEST_CONTEXT_ID
      );

      Predicate predicate = new PredicateBuilder().
        property(RequestResourceProvider.REQUEST_ID_PROPERTY_ID).equals("100").
        toPredicate();

      Request request = PropertyHelper.getReadRequest(propertyIds);

      // When
      Set<Resource> resources = provider.getResources(request, predicate);

      // Then
      verifyAll();

      Assert.assertEquals(1, resources.size());
      Resource resource = Iterables.getOnlyElement(resources);
      Assert.assertEquals(requestId, resource.getPropertyValue(RequestResourceProvider.REQUEST_ID_PROPERTY_ID));
      Assert.assertEquals(calculatedStatus.getStatus().toString(), resource.getPropertyValue(RequestResourceProvider.REQUEST_STATUS_PROPERTY_ID));
      Assert.assertEquals(calculatedStatus.getPercent(), resource.getPropertyValue(RequestResourceProvider.REQUEST_PROGRESS_PERCENT_ID));

      Object requestContext = resource.getPropertyValue(RequestResourceProvider.REQUEST_CONTEXT_ID);
      Assert.assertNotNull(requestContext);
      Assert.assertTrue(!failureReason.isPresent() || requestContext.toString().contains(failureReason.get()));
    }
  }
Tests that if there are no tasks, topology requests return status they get from the logical request.
ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RequestResourceProviderTest.java