Skip to content

Commit

Permalink
Add control tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Morgan committed Sep 15, 2009
1 parent 5b35737 commit 05b1476
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/org/hyperic/hq/hqapi1/test/ControlExecute_test.java
Expand Up @@ -28,8 +28,12 @@
package org.hyperic.hq.hqapi1.test;

import org.hyperic.hq.hqapi1.ControlApi;
import org.hyperic.hq.hqapi1.HQApi;
import org.hyperic.hq.hqapi1.types.Resource;
import org.hyperic.hq.hqapi1.types.StatusResponse;
import org.hyperic.hq.hqapi1.types.User;

import java.util.List;

public class ControlExecute_test extends ControlTestBase {

Expand All @@ -46,4 +50,36 @@ public void testExecuteInvalidResource() throws Exception {
StatusResponse response = api.executeAction(r, "none", new String[] {});
hqAssertFailureObjectNotFound(response);
}

public void testExecuteValidResource() throws Exception {
HQApi api = getApi();
ControlApi cApi = getApi().getControlApi();

Resource controllableResource = createControllableResource(api);

String[] arguments = new String[0];
StatusResponse executeResponse = cApi.executeAction(controllableResource,
"run", arguments);
hqAssertSuccess(executeResponse);

cleanupControllableResource(api, controllableResource);
}

public void testExecuteNoPermission() throws Exception {
HQApi api = getApi();
Resource controllableResource = createControllableResource(api);

List<User> users = createTestUsers(1);
User user = users.get(0);

HQApi apiUnpriv = getApi(user.getName(), TESTUSER_PASSWORD);
ControlApi cApiUnpriv = apiUnpriv.getControlApi();

StatusResponse executeResponse = cApiUnpriv.executeAction(controllableResource,
"run", new String[0]);
hqAssertFailurePermissionDenied(executeResponse);

deleteTestUsers(users);
cleanupControllableResource(api, controllableResource);
}
}
65 changes: 65 additions & 0 deletions src/org/hyperic/hq/hqapi1/test/ControlHistory_test.java
Expand Up @@ -28,8 +28,13 @@
package org.hyperic.hq.hqapi1.test;

import org.hyperic.hq.hqapi1.ControlApi;
import org.hyperic.hq.hqapi1.HQApi;
import org.hyperic.hq.hqapi1.types.Resource;
import org.hyperic.hq.hqapi1.types.ControlHistoryResponse;
import org.hyperic.hq.hqapi1.types.User;
import org.hyperic.hq.hqapi1.types.StatusResponse;

import java.util.List;

public class ControlHistory_test extends ControlTestBase {

Expand All @@ -46,4 +51,64 @@ public void testControlHistoryInvalidResource() throws Exception {
ControlHistoryResponse response = api.getHistory(r);
hqAssertFailureObjectNotFound(response);
}

public void testControlHistoryNoControlPlugin() throws Exception {
ControlApi api = getApi().getControlApi();

Resource localPlatform = getLocalPlatformResource(false, false);

ControlHistoryResponse response = api.getHistory(localPlatform);
hqAssertSuccess(response);

assertEquals("Wrong number of items in control history", 0,
response.getControlHistory().size());
}

public void testControlHistoryValidResource() throws Exception {
HQApi api = getApi();
ControlApi cApi = getApi().getControlApi();

Resource controllableResource = createControllableResource(api);

StatusResponse executeResponse = cApi.executeAction(controllableResource,
"run", new String[0]);
hqAssertSuccess(executeResponse);

long start = System.currentTimeMillis();
while (System.currentTimeMillis() < (start + 60000)) {

ControlHistoryResponse historyResponse = cApi.getHistory(controllableResource);
hqAssertSuccess(historyResponse);
if (historyResponse.getControlHistory().size() > 0) {
assertEquals("Wrong number of items in control history for " +
controllableResource.getName(), 1,
historyResponse.getControlHistory().size());
cleanupControllableResource(api, controllableResource);
return;

}
Thread.sleep(1000);
}

cleanupControllableResource(api, controllableResource);
fail("Unable to find control history in timeout of 60 seconds");
}

public void testControlHistoryNoPermission() throws Exception {
HQApi api = getApi();

Resource controllableResource = createControllableResource(api);

List<User> users = createTestUsers(1);
User user = users.get(0);

HQApi apiUnpriv = getApi(user.getName(), TESTUSER_PASSWORD);
ControlApi cApiUnpriv = apiUnpriv.getControlApi();

ControlHistoryResponse response = cApiUnpriv.getHistory(controllableResource);
hqAssertFailurePermissionDenied(response);

deleteTestUsers(users);
cleanupControllableResource(api, controllableResource);
}
}

0 comments on commit 05b1476

Please sign in to comment.