@Test
public void testUpdateRequestSchedule() 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);
  ExecutionScheduleManager executionScheduleManager = createNiceMock
    (ExecutionScheduleManager.class);
  expect(managementController.getClusters()).andReturn(clusters).anyTimes();
  expect(clusters.getCluster("Cluster100")).andReturn(cluster).anyTimes();
  expect(managementController.getAuthName()).andReturn("admin").anyTimes();
  expect(managementController.getAuthId()).andReturn(1).anyTimes();
  expect(managementController.getExecutionScheduleManager()).andReturn
    (executionScheduleManager).anyTimes();
  expect(requestExecution.getId()).andReturn(25L).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, executionScheduleManager);
  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");
  properties.put(RequestScheduleResourceProvider
    .SCHEDULE_DAY_OF_WEEK_PROPERTY_ID, "MON");
  properties.put(RequestScheduleResourceProvider
    .SCHEDULE_MINUTES_PROPERTY_ID, "2");
  properties.put(RequestScheduleResourceProvider
    .SCHEDULE_END_TIME_PROPERTY_ID, "2013-11-18T14:29:29-08:00");
  properties.put(RequestScheduleResourceProvider
    .SCHEDULE_DAYS_OF_MONTH_PROPERTY_ID, "*");
  HashSet<Map<String, Object>> batch = new HashSet<Map<String, Object>>();
  Map<String, Object> batchSettings = new HashMap<String, Object>();
  batchSettings.put(RequestScheduleResourceProvider
    .REQUEST_SCHEDULE_BATCH_SEPARATION_PROPERTY_ID, "15");
  Map<String, Object> batchRequests = new HashMap<String, Object>();
  HashSet<Map<String, Object>> requestSet = new HashSet<Map<String, Object>>();
  Map<String, Object> request1 = new HashMap<String, Object>();
  Map<String, Object> request2 = new HashMap<String, Object>();
  request1.put(RequestScheduleResourceProvider
    .BATCH_REQUEST_TYPE_PROPERTY_ID, BatchRequest.Type.PUT.name());
  request1.put(RequestScheduleResourceProvider
    .BATCH_REQUEST_ORDER_ID_PROPERTY_ID, "20");
  request1.put(RequestScheduleResourceProvider
    .BATCH_REQUEST_URI_PROPERTY_ID, "SomeUpdateUri");
  request1.put(RequestScheduleResourceProvider
    .BATCH_REQUEST_BODY_PROPERTY_ID, "data1");
  request2.put(RequestScheduleResourceProvider
    .BATCH_REQUEST_TYPE_PROPERTY_ID, BatchRequest.Type.DELETE.name());
  request2.put(RequestScheduleResourceProvider
    .BATCH_REQUEST_ORDER_ID_PROPERTY_ID, "22");
  request2.put(RequestScheduleResourceProvider
    .BATCH_REQUEST_URI_PROPERTY_ID, "SomeDeleteUri");
  requestSet.add(request1);
  requestSet.add(request2);
  batchRequests.put(RequestScheduleResourceProvider
    .REQUEST_SCHEDULE_BATCH_REQUESTS_PROPERTY_ID, requestSet);
  batch.add(batchSettings);
  batch.add(batchRequests);
  properties.put(RequestScheduleResourceProvider
    .REQUEST_SCHEDULE_BATCH_PROPERTY_ID, batch);
  Map<String, String> mapRequestProps = new HashMap<String, String>();
  mapRequestProps.put("context", "Called from a test");
  Request request = PropertyHelper.getUpdateRequest(properties, mapRequestProps);
  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();
  resourceProvider.updateResources(request, predicate);
  verify(managementController, clusters, cluster, requestExecution,
    response, requestScheduleResponse, executionScheduleManager);
}