Skip to content

Commit

Permalink
Improve validation of recovery alert definitions and add one more tes…
Browse files Browse the repository at this point in the history
…t case
  • Loading branch information
pnguyen committed Nov 2, 2009
1 parent 2953703 commit 06fb8ad
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
Expand Up @@ -91,14 +91,14 @@ public void testValidRecoveryConditionTypeAlert() throws Exception {
// Find availability metric for the passed in resource
Metric m = findAvailabilityMetric(platform);

AlertDefinition def = generateTestDefinition("Test Problem Alert");
AlertDefinition def = generateTestDefinition("Test Resource Type Problem Alert");
def.setResourcePrototype(platform.getResourcePrototype());
final double THRESHOLD = 0;
def.getAlertCondition().add(
AlertDefinitionBuilder.createThresholdCondition(true, m.getName(),
AlertComparator.EQUALS,
THRESHOLD));
AlertDefinition recoveryDef = generateTestDefinition("Test Recovery Alert");
AlertDefinition recoveryDef = generateTestDefinition("Test Resource Type Recovery Alert");
recoveryDef.setResourcePrototype(platform.getResourcePrototype());
AlertCondition threshold =
AlertDefinitionBuilder.createThresholdCondition(true, m.getName(),
Expand Down Expand Up @@ -173,7 +173,7 @@ public void testSyncRecoveryWithoutProblemDefTypeAlert() throws Exception {
Metric m = findAvailabilityMetric(platform);

// First sync the problem definition
AlertDefinition def = generateTestDefinition("Test Problem Alert");
AlertDefinition def = generateTestDefinition("Test Resource Type Problem Alert");
def.setResourcePrototype(platform.getResourcePrototype());
final double THRESHOLD = 0;
def.getAlertCondition().add(
Expand All @@ -184,7 +184,7 @@ public void testSyncRecoveryWithoutProblemDefTypeAlert() throws Exception {
validateTypeDefinition(parentDown);

// Next, sync the recovery
AlertDefinition recoveryDef = generateTestDefinition("Test Recovery Alert");
AlertDefinition recoveryDef = generateTestDefinition("Test Resource Type Recovery Alert");
recoveryDef.setResourcePrototype(platform.getResourcePrototype());
AlertCondition threshold =
AlertDefinitionBuilder.createThresholdCondition(true, m.getName(),
Expand Down
3 changes: 2 additions & 1 deletion src/org/hyperic/hq/hqapi1/test/AlertDefinitionTestBase.java
Expand Up @@ -225,7 +225,8 @@ protected void validateRecoveryAlertDefinition(AlertDefinition recoveryDef,
Set actualAlertActions = new HashSet();

for (AlertAction a : recovery.getAlertAction()) {
actualAlertActions.add(a.getClassName());
assertTrue("There was a duplicate alert action: " + a.getClassName(),
actualAlertActions.add(a.getClassName()));
}

assertEquals("Recovery alert definition has unexpected alert actions.",
Expand Down
34 changes: 28 additions & 6 deletions src/org/hyperic/hq/hqapi1/test/AlertFireRecovery_test.java
Expand Up @@ -34,10 +34,18 @@ public void testFireRecoveryAlert() throws Exception {
createAndFireAlerts(false, false);
}

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

// Cleanup
deleteEscalation(e);
}

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

/**
* To validate HQ-1894
*/
Expand Down Expand Up @@ -82,13 +90,26 @@ 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 addRecoveryPostCreate,
boolean willRecover)
throws Exception {

Resource platform = getLocalPlatformResource(false, false);

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

Alert problemAlert = fireProblemAlert(problemDef, willRecover);
Expand Down Expand Up @@ -151,10 +172,6 @@ private Alert fireRecoveryAlert(AlertDefinition recoveryDef,
return recoveryAlert;
}

// TODO testWillRecoverAndFireRecoveryTypeAlert
// TODO testFireRecoveryAlertWithEscalation
// TODO testFireRecoveryTypeAlertWithEscalation

private AlertDefinition createProblemAlertDefinition(Resource resource,
Escalation e,
boolean willRecover)
Expand All @@ -179,6 +196,11 @@ private AlertDefinition createProblemAlertDefinition(Resource resource,

validateProblemAlertDefinitionAttributes(newDef, willRecover, true);

assertTrue("The problem alert definition should have "
+ ((e == null) ? "no" : "an") + " escalation",
(e == null) ? newDef.getEscalation() == null
: newDef.getEscalation() != null);

return newDef;
}

Expand Down

0 comments on commit 06fb8ad

Please sign in to comment.