Skip to content

Commit

Permalink
Added 5 more test cases when test firing recovery alerts, including t…
Browse files Browse the repository at this point in the history
…ests with escalations and resource type alert definitions
  • Loading branch information
pnguyen committed Nov 2, 2009
1 parent 06fb8ad commit f2b1ae7
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 36 deletions.
11 changes: 6 additions & 5 deletions src/org/hyperic/hq/hqapi1/test/AlertDefinitionTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,12 @@ protected void validateRecoveryAlertDefinition(AlertDefinition recoveryDef,
actualAlertActions.add(a.getClassName()));
}

assertEquals("Recovery alert definition has unexpected alert actions.",
assertEquals("Recovery alert definition has missing or unexpected alert actions.",
expectedAlertActions, actualAlertActions);

// if it is a resource type alert definition
// then validate the child recovery alert definition
if (recoveryDef.getParent() != null
&& recoveryDef.getParent().intValue() == 0) {
if (recoveryDef.getResourcePrototype() != null) {
validateChildRecoveryAlertDefinition(recoveryDef, problemDef);
}
}
Expand All @@ -252,12 +251,14 @@ private void validateChildRecoveryAlertDefinition(AlertDefinition parentRecovery
// get child alert definitions
AlertDefinitionsResponse childRecoveryResponse = defApi.getAlertDefinitions(parentRecoveryDef);
hqAssertSuccess(childRecoveryResponse);
assertEquals(1, childRecoveryResponse.getAlertDefinition().size());
assertEquals("These tests assume only one child alert definition",
1, childRecoveryResponse.getAlertDefinition().size());
AlertDefinition childRecoveryDef = childRecoveryResponse.getAlertDefinition().get(0);

AlertDefinitionsResponse childProblemResponse = defApi.getAlertDefinitions(parentProblemDef);
hqAssertSuccess(childProblemResponse);
assertEquals(1, childProblemResponse.getAlertDefinition().size());
assertEquals("These tests assume only one child alert definition",
1, childProblemResponse.getAlertDefinition().size());
AlertDefinition childProblemDef = childProblemResponse.getAlertDefinition().get(0);

// validate child recovery alert definition
Expand Down
145 changes: 114 additions & 31 deletions src/org/hyperic/hq/hqapi1/test/AlertFireRecovery_test.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.hyperic.hq.hqapi1.types.Alert;
import org.hyperic.hq.hqapi1.types.AlertCondition;
import org.hyperic.hq.hqapi1.types.AlertDefinition;
import org.hyperic.hq.hqapi1.types.AlertDefinitionsResponse;
import org.hyperic.hq.hqapi1.types.AlertResponse;
import org.hyperic.hq.hqapi1.types.AlertsResponse;
import org.hyperic.hq.hqapi1.types.DataPoint;
Expand All @@ -31,19 +32,39 @@ public AlertFireRecovery_test(String name) {
}

public void testFireRecoveryAlert() throws Exception {
createAndFireAlerts(false, false);
createAndFireAlerts(null, false, false, false);
}

public void testFireResourceTypeRecoveryAlert() throws Exception {
createAndFireAlerts(null, true, false, false);
}

public void testFireRecoveryAlertWithEscalation() throws Exception {
Escalation e = createEscalation();
createAndFireAlerts(e, false, false, true);
createAndFireAlerts(e, false, false, false);

// Cleanup
deleteEscalation(e);
}

public void testFireResourceTypeRecoveryAlertWithEscalation()
throws Exception {

Escalation e = createEscalation();
createAndFireAlerts(e, true, false, false);

// Cleanup
deleteEscalation(e);
}

public void testWillRecoverAndFireRecoveryAlert() throws Exception {
createAndFireAlerts(false, true);
createAndFireAlerts(null, false, false, true);
}

public void testWillRecoverAndFireResourceTypeRecoveryAlert()
throws Exception {

createAndFireAlerts(null, true, false, true);
}

/**
Expand All @@ -52,7 +73,16 @@ public void testWillRecoverAndFireRecoveryAlert() throws Exception {
public void testAddRecoveryPostCreateAndFireRecoveryAlert()
throws Exception {

createAndFireAlerts(true, false);
createAndFireAlerts(null, false, true, false);
}

/**
* To validate HQ-1894
*/
public void testAddRecoveryPostCreateAndFireResourceTypeRecoveryAlert()
throws Exception {

createAndFireAlerts(null, true, true, false);
}

/**
Expand All @@ -61,9 +91,18 @@ public void testAddRecoveryPostCreateAndFireRecoveryAlert()
public void testWillRecoverAddRecoveryPostCreateAndFireRecoveryAlert()
throws Exception {

createAndFireAlerts(true, true);
createAndFireAlerts(null, false, true, true);
}

/**
* To validate HQ-1894
*/
public void testWillRecoverAddRecoveryPostCreateAndFireResourceTypeRecoveryAlert()
throws Exception {

createAndFireAlerts(null, true, true, true);
}

/**
* To validate HQ-1903
*/
Expand All @@ -76,10 +115,10 @@ public void testFireProblemAlertAndThenCreateAndFireRecoveryAlert()
Resource platform = getLocalPlatformResource(false, false);
boolean willRecover = false;
AlertDefinition problemDef = createProblemAlertDefinition(platform, null, willRecover);
AlertDefinition problemDef = createProblemAlertDefinition(platform, null, false, willRecover);
Alert problemAlert = fireProblemAlert(problemDef, willRecover);
AlertDefinition recoveryDef = createRecoveryAlertDefinition(problemDef, false);
AlertDefinition recoveryDef = createRecoveryAlertDefinition(platform, problemDef, false);
fireRecoveryAlert(recoveryDef, problemAlert, willRecover);
// Cleanup
Expand All @@ -90,30 +129,36 @@ public void testFireProblemAlertAndThenCreateAndFireRecoveryAlert()
*/
}

// TODO testFireResourceTypeRecoveryAlert
// TODO testWillRecoverAndFireRecoveryTypeAlert
// TODO testFireRecoveryTypeAlertWithEscalation

private void createAndFireAlerts(boolean addRecoveryPostCreate,
boolean willRecover)
throws Exception {

createAndFireAlerts(null, false, addRecoveryPostCreate, willRecover);
}

private void createAndFireAlerts(Escalation escalation,
boolean resourceType,
boolean isResourceType,
boolean addRecoveryPostCreate,
boolean willRecover)
throws Exception {

Resource platform = getLocalPlatformResource(false, false);

AlertDefinition problemDef = createProblemAlertDefinition(platform, escalation, willRecover);
AlertDefinition recoveryDef = createRecoveryAlertDefinition(problemDef, addRecoveryPostCreate);
AlertDefinition problemDef =
createProblemAlertDefinition(platform, escalation, isResourceType, willRecover);
AlertDefinition recoveryDef =
createRecoveryAlertDefinition(platform, problemDef, addRecoveryPostCreate);

Alert problemAlert = fireProblemAlert(problemDef, willRecover);
fireRecoveryAlert(recoveryDef, problemAlert, willRecover);
AlertDefinition problemDefToFire = null;
if (isResourceType) {
problemDefToFire = getChildAlertDefinition(problemDef);
} else {
problemDefToFire = problemDef;
}

Alert problemAlert = fireProblemAlert(problemDefToFire, willRecover);

AlertDefinition recoveryDefToFire = null;
if (isResourceType) {
recoveryDefToFire = getChildAlertDefinition(recoveryDef);
} else {
recoveryDefToFire = recoveryDef;
}

fireRecoveryAlert(recoveryDefToFire, problemAlert, willRecover);

// Cleanup
List<AlertDefinition> definitions = new ArrayList<AlertDefinition>();
Expand All @@ -137,8 +182,8 @@ private Alert fireProblemAlert(AlertDefinition problemDef,
problemAlert.isFixed());

// Get the updated problem alert definition
problemDef = getAlertDefinition(problemAlert.getAlertDefinitionId());
validateProblemAlertDefinitionAttributes(problemDef,
AlertDefinition updatedDef = getAlertDefinition(problemAlert.getAlertDefinitionId());
validateProblemAlertDefinitionAttributes(updatedDef,
willRecover,
willRecover ? false : true);

Expand Down Expand Up @@ -174,16 +219,22 @@ private Alert fireRecoveryAlert(AlertDefinition recoveryDef,

private AlertDefinition createProblemAlertDefinition(Resource resource,
Escalation e,
boolean isResourceType,
boolean willRecover)
throws IOException {

// Find availability metric for the passed in resource
Metric availMetric = findAvailabilityMetric(resource);

// Create alert definition
AlertDefinition d = generateTestDefinition("Test Problem Alert");
String name = "Test" + (isResourceType ? " Resource Type " : " ") + "Problem Alert";
AlertDefinition d = generateTestDefinition(name);
d.setWillRecover(willRecover);
d.setResource(resource);
if (isResourceType) {
d.setResourcePrototype(resource.getResourcePrototype());
} else {
d.setResource(resource);
}
if (e != null) {
d.setEscalation(e);
}
Expand All @@ -194,6 +245,10 @@ private AlertDefinition createProblemAlertDefinition(Resource resource,
d.getAlertCondition().add(threshold);
AlertDefinition newDef = syncAlertDefinition(d);

if (isResourceType) {
validateTypeDefinition(newDef);
}

validateProblemAlertDefinitionAttributes(newDef, willRecover, true);

assertTrue("The problem alert definition should have "
Expand All @@ -204,17 +259,24 @@ private AlertDefinition createProblemAlertDefinition(Resource resource,
return newDef;
}

private AlertDefinition createRecoveryAlertDefinition(AlertDefinition problemDef,
private AlertDefinition createRecoveryAlertDefinition(Resource resource,
AlertDefinition problemDef,
boolean addRecoveryPostCreate)
throws Exception {

// Find availability metric for the passed in resource
Metric availMetric = findAvailabilityMetric(problemDef.getResource());
Metric availMetric = findAvailabilityMetric(resource);

// Create recovery alert definition
AlertDefinition recoveryDef = generateTestDefinition("Test Recovery Alert");
boolean isResourceType = (problemDef.getResourcePrototype() != null);
String name = "Test" + (isResourceType ? " Resource Type " : " ") + "Recovery Alert";
AlertDefinition recoveryDef = generateTestDefinition(name);
recoveryDef.setDescription("Recovery Alert for " + problemDef.getName());
recoveryDef.setResource(problemDef.getResource());
if (isResourceType) {
recoveryDef.setResourcePrototype(problemDef.getResourcePrototype());
} else {
recoveryDef.setResource(resource);
}
AlertCondition threshold =
AlertDefinitionBuilder.createThresholdCondition(
true, availMetric.getName(),
Expand All @@ -234,11 +296,32 @@ private AlertDefinition createRecoveryAlertDefinition(AlertDefinition problemDef
newDef = syncAlertDefinition(recoveryDef);
}

if (isResourceType) {
validateTypeDefinition(newDef);
}

validateRecoveryAlertDefinition(newDef, problemDef);

return newDef;
}

private AlertDefinition getChildAlertDefinition(AlertDefinition parent)
throws IOException {

AlertDefinitionsResponse childAlertDefResponse =
getApi().getAlertDefinitionApi().getAlertDefinitions(parent);

hqAssertSuccess(childAlertDefResponse);

assertEquals("These tests assume only one child alert definition",
1, childAlertDefResponse.getAlertDefinition().size());

AlertDefinition child = childAlertDefResponse.getAlertDefinition().get(0);
validateDefinition(child);

return child;
}

private void validateProblemAlertDefinitionAttributes(AlertDefinition def,
boolean willRecover,
boolean enabled) {
Expand Down

0 comments on commit f2b1ae7

Please sign in to comment.