Cluster clusterMock = createMock(Cluster.class);
RequestExecution requestExecutionMock = createMock(RequestExecution.class);
Configuration configurationMock = createNiceMock(Configuration.class);
ExecutionScheduler executionSchedulerMock = createMock(ExecutionScheduler.class);
InternalTokenStorage tokenStorageMock = createMock(InternalTokenStorage.class);
ActionDBAccessor actionDBAccessorMock = createMock(ActionDBAccessor.class);
Gson gson = new Gson();
BatchRequest batchRequestMock = createMock(BatchRequest.class);
long executionId = 11L;
long batchId = 1L;
long requestId = 5L;
String clusterName = "mycluster";
String uri = "clusters";
String type = "post";
String body = "body";
Map<Long, RequestExecution> executionMap = new HashMap<Long, RequestExecution>();
executionMap.put(executionId, requestExecutionMock);
BatchRequestResponse batchRequestResponse = new BatchRequestResponse();
batchRequestResponse.setStatus(HostRoleStatus.IN_PROGRESS.toString());
batchRequestResponse.setRequestId(requestId);
batchRequestResponse.setReturnCode(202);
ExecutionScheduleManager scheduleManager = createMockBuilder(ExecutionScheduleManager.class).
withConstructor(configurationMock, executionSchedulerMock, tokenStorageMock, clustersMock,
actionDBAccessorMock, gson).
addMockedMethods("performApiRequest", "updateBatchRequest").createNiceMock();
//interesting easymock behavior, workaround to not to expect method called in constructor
expectLastCall().anyTimes();
expect(clustersMock.getCluster(clusterName)).andReturn(clusterMock).anyTimes();
expect(clusterMock.getAllRequestExecutions()).andReturn(executionMap).anyTimes();
expect(requestExecutionMock.getBatchRequest(eq(batchId))).andReturn(batchRequestMock).once();
expect(requestExecutionMock.getRequestBody(eq(batchId))).andReturn(body).once();
expect(batchRequestMock.getUri()).andReturn(uri).once();
expect(batchRequestMock.getType()).andReturn(type).once();
expect(scheduleManager.performApiRequest(eq(uri), eq(body), eq(type))).andReturn(batchRequestResponse).once();
scheduleManager.updateBatchRequest(eq(executionId), eq(batchId), eq(clusterName), eq(batchRequestResponse), eq(false));
expectLastCall().once();
actionDBAccessorMock.setSourceScheduleForRequest(eq(requestId), eq(executionId));
expectLastCall().once();
replay(clusterMock, clustersMock, configurationMock, requestExecutionMock, executionSchedulerMock,
tokenStorageMock, batchRequestMock, scheduleManager, actionDBAccessorMock);