List<Alert> alerts = getAlerts(resourceWithSchedules.getId());
assert alerts.size() == 1 : "1 alert should have fired: " + alerts;
Alert alert = alerts.get(0);
assert alert.getConditionLogs().size() == 1 : "1 condition log should exist";
AlertConditionLog conditionLog = alert.getConditionLogs().iterator().next();
Assert.assertEquals(conditionLog.getCondition().getId(), conditionId,
"original condition should have been associated with the alert");
// update a non-condition aspect of the def and then update the def
String updatedDesc = "Updated Description";
alertDef.setDescription(updatedDesc);
AlertDefinition updatedAlertDef = LookupUtil.getAlertDefinitionManager().updateAlertDefinition(getOverlord(),
alertDef.getId(), alertDef, false); // note that resetMatching is false
assert updatedDesc.equals(updatedAlertDef.getDescription()) : "Description should be updated";
assert updatedAlertDef.getConditions().size() == 1 : "1 alertDef condition should exist after the update";
assert updatedAlertDef.getConditions().iterator().next().getId() == condition.getId() : "condition should not be updated";
// get the alert again, and make sure it still has a log with the same condition
alerts = getAlerts(resourceWithSchedules.getId());
assert alerts.size() == 1 : "1 alert should have fired: " + alerts;
alert = alerts.get(0);
assert alert.getConditionLogs().size() == 1 : "1 condition log should exist after the update";
conditionLog = alert.getConditionLogs().iterator().next();
Assert.assertEquals(conditionLog.getCondition().getId(), conditionId,
"original condition should still have been associated with the alert");
// update the condition on the def and then update the def
condition.setThreshold(41.0);
updatedAlertDef = LookupUtil.getAlertDefinitionManager().updateAlertDefinition(getOverlord(), alertDef.getId(),
alertDef, true); // note that resetMatching is true
assert updatedAlertDef.getConditions().size() == 1 : "1 alertDef condition should exist after the update";
assert updatedAlertDef.getConditions().iterator().next().getId() != condition.getId() : "condition should be updated";
// get the alert again, and make sure it still has a log with the same condition
alerts = getAlerts(resourceWithSchedules.getId());
assert alerts.size() == 1 : "1 alert should have fired: " + alerts;
alert = alerts.get(0);
assert alert.getConditionLogs().size() == 1 : "1 condition log should exist after the update";
conditionLog = alert.getConditionLogs().iterator().next();
Assert.assertEquals(conditionLog.getCondition().getId(), conditionId,
"original condition should still have been associated with the alert");
}