@Test
public void testGetResourcesWithCluster() throws Exception {
Resource.Type type = Resource.Type.Request;
AmbariManagementController managementController = createMock(AmbariManagementController.class);
ActionManager actionManager = createNiceMock(ActionManager.class);
HostRoleCommand hostRoleCommand = createNiceMock(HostRoleCommand.class);
Clusters clusters = createNiceMock(Clusters.class);
Cluster cluster = createNiceMock(Cluster.class);
List<HostRoleCommand> hostRoleCommands = new LinkedList<HostRoleCommand>();
hostRoleCommands.add(hostRoleCommand);
org.apache.ambari.server.actionmanager.Request requestMock =
createNiceMock(org.apache.ambari.server.actionmanager.Request.class);
expect(requestMock.getCommands()).andReturn(hostRoleCommands).anyTimes();
expect(requestMock.getRequestContext()).andReturn("this is a context").anyTimes();
expect(requestMock.getClusterName()).andReturn("c1").anyTimes();
expect(requestMock.getRequestId()).andReturn(100L).anyTimes();
Capture<Collection<Long>> requestIdsCapture = new Capture<Collection<Long>>();
// set expectations
expect(managementController.getActionManager()).andReturn(actionManager).anyTimes();
expect(managementController.getClusters()).andReturn(clusters).anyTimes();
expect(clusters.getCluster("c1")).andReturn(cluster).anyTimes();
expect(clusters.getCluster("bad-cluster")).andThrow(new AmbariException("bad cluster!")).anyTimes();
expect(actionManager.getRequests(capture(requestIdsCapture))).andReturn(Collections.singletonList(requestMock));
expect(hostRoleCommand.getRequestId()).andReturn(100L).anyTimes();
expect(hostRoleCommand.getStatus()).andReturn(HostRoleStatus.IN_PROGRESS);
// replay
replay(managementController, actionManager, hostRoleCommand, clusters, cluster, requestMock);