@Test
public void testGetRequestSchedule() throws Exception {

  AmbariManagementController managementController = createMock(AmbariManagementController.class);
  RequestStatusResponse response = createNiceMock(RequestStatusResponse.class);
  Clusters clusters = createNiceMock(Clusters.class);
  Cluster cluster = createNiceMock(Cluster.class);
  final RequestExecution requestExecution = createNiceMock(RequestExecution.class);
  RequestScheduleResponse requestScheduleResponse = createNiceMock
    (RequestScheduleResponse.class);
  expect(managementController.getClusters()).andReturn(clusters).anyTimes();
  expect(clusters.getCluster("Cluster100")).andReturn(cluster).anyTimes();
  expect(managementController.getAuthName()).andReturn("admin").anyTimes();
  expect(requestExecution.getId()).andReturn(25L).anyTimes();
  expect(requestExecution.getStatus()).andReturn(RequestExecution.Status
    .SCHEDULED.name()).anyTimes();
  expect(requestExecution.convertToResponse()).andReturn
    (requestScheduleResponse).anyTimes();
  expect(requestExecution.convertToResponseWithBody()).andReturn
    (requestScheduleResponse).anyTimes();
  expect(requestScheduleResponse.getId()).andReturn(25L).anyTimes();
  expect(requestScheduleResponse.getClusterName()).andReturn("Cluster100")
    .anyTimes();
  expect(cluster.getAllRequestExecutions()).andStubAnswer(new IAnswer<Map<Long, RequestExecution>>() {
    @Override
    public Map<Long, RequestExecution> answer() throws Throwable {
      Map<Long, RequestExecution> requestExecutionMap = new HashMap<Long,
        RequestExecution>();
      requestExecutionMap.put(requestExecution.getId(), requestExecution);
      return requestExecutionMap;
    }
  });
  replay(managementController, clusters, cluster, requestExecution,
    response, requestScheduleResponse);
  RequestScheduleResourceProvider resourceProvider = getResourceProvider
    (managementController);
  Map<String, Object> properties = new LinkedHashMap<String, Object>();
  properties.put(RequestScheduleResourceProvider
    .REQUEST_SCHEDULE_CLUSTER_NAME_PROPERTY_ID, "Cluster100");
  properties.put(RequestScheduleResourceProvider
    .REQUEST_SCHEDULE_DESC_PROPERTY_ID, "some description");
  Set<String> propertyIds = new HashSet<String>();
  propertyIds.add(RequestScheduleResourceProvider
    .REQUEST_SCHEDULE_CLUSTER_NAME_PROPERTY_ID);
  propertyIds.add(RequestScheduleResourceProvider
    .REQUEST_SCHEDULE_ID_PROPERTY_ID);
  Request request = PropertyHelper.getReadRequest(propertyIds);
  // Read by id
  Predicate predicate = new PredicateBuilder().property
    (RequestScheduleResourceProvider.REQUEST_SCHEDULE_CLUSTER_NAME_PROPERTY_ID)
    .equals("Cluster100").and().property(RequestScheduleResourceProvider
      .REQUEST_SCHEDULE_ID_PROPERTY_ID).equals(25L).toPredicate();
  Set<Resource> resources = resourceProvider.getResources(request,
    predicate);
  Assert.assertEquals(1, resources.size());
  Assert.assertEquals(25L, resources.iterator().next().getPropertyValue
    (RequestScheduleResourceProvider.REQUEST_SCHEDULE_ID_PROPERTY_ID));
  // Read all
  predicate = new PredicateBuilder().property
    (RequestScheduleResourceProvider.REQUEST_SCHEDULE_CLUSTER_NAME_PROPERTY_ID)
    .equals("Cluster100").toPredicate();
  resources = resourceProvider.getResources(request, predicate);
  Assert.assertEquals(1, resources.size());
  Assert.assertEquals(25L, resources.iterator().next().getPropertyValue
    (RequestScheduleResourceProvider.REQUEST_SCHEDULE_ID_PROPERTY_ID));
  verify(managementController, clusters, cluster, requestExecution,
    response, requestScheduleResponse);
}