Permalink
Browse files

Improve integration test validation when syncing resource type alert …

…definitions
  • Loading branch information...
1 parent 6175a74 commit 16a30b5e2345f59923121ba5a0d3fca372fa73dc pnguyen committed Dec 24, 2009
@@ -29,6 +29,7 @@
import org.hyperic.hq.hqapi1.AlertDefinitionApi;
import org.hyperic.hq.hqapi1.AlertDefinitionBuilder;
+import org.hyperic.hq.hqapi1.AlertDefinitionBuilder.AlertPriority;
import org.hyperic.hq.hqapi1.EscalationApi;
import org.hyperic.hq.hqapi1.HQApi;
import org.hyperic.hq.hqapi1.types.AlertCondition;
@@ -179,30 +180,36 @@ public void testSyncCreateTypeDefinition() throws Exception {
hqAssertSuccess(response);
assertEquals(response.getAlertDefinition().size(), 1);
for (AlertDefinition def : response.getAlertDefinition()) {
- validateDefinition(def);
+ validateTypeDefinition(def);
}
// Cleanup
cleanup(response.getAlertDefinition());
}
- public void testSyncCountAndRange() throws Exception {
+ public void testSyncCountAndRangeTypeAlert() throws Exception {
AlertDefinitionApi api = getApi().getAlertDefinitionApi();
+ final int count = 3;
+ final int range = 1800;
Resource platform = getLocalPlatformResource(false, false);
AlertDefinition d = generateTestDefinition();
d.setResourcePrototype(platform.getResourcePrototype());
d.getAlertCondition().add(AlertDefinitionBuilder.createPropertyCondition(true, "myProp"));
- d.setCount(3);
- d.setRange(1800);
+ d.setCount(count);
+ d.setRange(range);
List<AlertDefinition> definitions = new ArrayList<AlertDefinition>();
definitions.add(d);
AlertDefinitionsResponse response = api.syncAlertDefinitions(definitions);
hqAssertSuccess(response);
assertEquals(response.getAlertDefinition().size(), 1);
for (AlertDefinition def : response.getAlertDefinition()) {
- validateDefinition(def);
+ validateTypeDefinition(def);
+ assertEquals(count, def.getCount());
+ assertEquals(range, def.getRange());
+
+ // TODO: validate child alert definitions
}
// Cleanup
@@ -394,10 +401,14 @@ public void testSyncMultiTypeAlert() throws Exception {
AlertDefinitionApi api = getApi().getAlertDefinitionApi();
Resource platform = getLocalPlatformResource(false, false);
+ final int INITIAL_PRIORITY = AlertPriority.LOW.getPriority();
+ final boolean INITIAL_ACTIVE = true;
final int NUM_DEFS = 10;
List<AlertDefinition> definitions = new ArrayList<AlertDefinition>();
for (int i = 0; i < NUM_DEFS; i++) {
AlertDefinition d = generateTestDefinition();
+ d.setPriority(INITIAL_PRIORITY);
+ d.setActive(INITIAL_ACTIVE);
d.setResourcePrototype(platform.getResourcePrototype());
d.getAlertCondition().add(AlertDefinitionBuilder.createPropertyCondition(true, "myProp"));
definitions.add(d);
@@ -407,31 +418,71 @@ public void testSyncMultiTypeAlert() throws Exception {
hqAssertSuccess(response);
assertEquals(response.getAlertDefinition().size(), NUM_DEFS);
for (AlertDefinition def : response.getAlertDefinition()) {
- validateDefinition(def);
- assertNotNull("ResourcePrototype was null", def.getResourcePrototype());
- assertNull("Resource was not null", def.getResource());
+ validateTypeDefinition(def);
+ assertEquals(INITIAL_PRIORITY, def.getPriority());
+ assertEquals(INITIAL_ACTIVE, def.isActive());
+
+ // validate child alert definitions
+ AlertDefinitionsResponse childrenResponse = api.getAlertDefinitions(def);
+ hqAssertSuccess(response);
+ List<AlertDefinition> childrenDefinitions = childrenResponse.getAlertDefinition();
+ assertTrue("No child alert definition exists for " + def.getName(),
+ childrenDefinitions.size() > 0);
+ for (AlertDefinition child : childrenDefinitions) {
+ validateDefinition(child);
+ }
}
// Re-sync for update
definitions = response.getAlertDefinition();
- final String UPDATED_DESCRIPTION = "Updated Alert Description";
+ final int UPDATED_PRIORITY = AlertPriority.HIGH.getPriority();
+ final boolean UPDATED_ACTIVE = false;
+ final String UPDATED_NAME = "Updated Alert Definition Name";
+ final String UPDATED_DESCRIPTION = "Updated Alert Definition Description";
final AlertCondition newCond =
AlertDefinitionBuilder.createPropertyCondition(true, "otherProp");
for (AlertDefinition d : definitions) {
+ d.setPriority(UPDATED_PRIORITY);
+ d.setActive(UPDATED_ACTIVE);
+ d.setName(UPDATED_NAME);
d.setDescription(UPDATED_DESCRIPTION);
d.getAlertCondition().clear();
d.getAlertCondition().add(newCond);
}
response = api.syncAlertDefinitions(definitions);
hqAssertSuccess(response);
- for (AlertDefinition d: definitions) {
- assertEquals(d.getDescription(), UPDATED_DESCRIPTION);
+ for (AlertDefinition d: response.getAlertDefinition()) {
+ validateTypeDefinition(d);
+
+ // validate updated properties
+ assertEquals(UPDATED_PRIORITY, d.getPriority());
+ assertEquals(UPDATED_ACTIVE, d.isActive());
+ assertEquals(UPDATED_NAME, d.getName());
+ assertEquals(UPDATED_DESCRIPTION, d.getDescription());
for (AlertCondition c : d.getAlertCondition()) {
assertTrue(c.getProperty().equals("otherProp"));
}
+
+ // validate child alert definitions
+ AlertDefinitionsResponse childrenResponse = api.getAlertDefinitions(d);
+ hqAssertSuccess(response);
+ List<AlertDefinition> childrenDefinitions = childrenResponse.getAlertDefinition();
+ assertTrue("No child alert definition exists for " + d.getName(),
+ childrenDefinitions.size() > 0);
+ for (AlertDefinition child : childrenDefinitions) {
+ validateDefinition(child);
+
+ // TODO: uncomment when HHQ-3624 is fixed
+ /*
+ assertEquals(UPDATED_PRIORITY, child.getPriority());
+ assertEquals(UPDATED_ACTIVE, child.isActive());
+ assertEquals(UPDATED_NAME, child.getName());
+ assertEquals(UPDATED_DESCRIPTION, child.getDescription());
+ */
+ }
}
-
+
// Cleanup
cleanup(response.getAlertDefinition());
}
@@ -471,7 +522,7 @@ public void testSyncEmptyEscalation() throws Exception {
hqAssertFailureObjectNotFound(response);
}
- public void testSyncEscalation() throws Exception {
+ public void testSyncEscalationTypeAlert() throws Exception {
HQApi api = getApi();
AlertDefinitionApi defApi = api.getAlertDefinitionApi();
EscalationApi escApi = api.getEscalationApi();
@@ -496,7 +547,7 @@ public void testSyncEscalation() throws Exception {
hqAssertSuccess(response);
assertEquals(response.getAlertDefinition().size(), 1);
for (AlertDefinition def : response.getAlertDefinition()) {
- validateDefinition(def);
+ validateTypeDefinition(def);
assertEquals(def.getEscalation().getId(),
escalationResponse.getEscalation().getId());
}
@@ -574,9 +625,7 @@ public void testSyncUpdateWithEscalationTypeAlert() throws Exception {
hqAssertSuccess(response);
assertEquals(response.getAlertDefinition().size(), 1);
for (AlertDefinition def : response.getAlertDefinition()) {
- validateDefinition(def);
- assertNotNull("ResourcePrototype was null", def.getResourcePrototype());
- assertNull("Resource was not null", def.getResource());
+ validateTypeDefinition(def);
assertNull("Escalation was not null", def.getEscalation());
}
@@ -597,7 +646,7 @@ public void testSyncUpdateWithEscalationTypeAlert() throws Exception {
hqAssertSuccess(response);
assertEquals(response.getAlertDefinition().size(), 1);
for (AlertDefinition def : response.getAlertDefinition()) {
- validateDefinition(def);
+ validateTypeDefinition(def);
assertNotNull("Escalation was null", def.getEscalation());
assertEquals(def.getEscalation().getName(), e.getName());
}
@@ -685,8 +734,7 @@ public void testSyncUpdateRemoveEscalationTypeAlert() throws Exception {
hqAssertSuccess(response);
assertEquals(response.getAlertDefinition().size(), 1);
for (AlertDefinition def : response.getAlertDefinition()) {
- validateDefinition(def);
- assertNotNull("ResourcePrototype was null", def.getResourcePrototype());
+ validateTypeDefinition(def);
assertNotNull("Escalation was null", def.getEscalation());
}
@@ -700,7 +748,7 @@ public void testSyncUpdateRemoveEscalationTypeAlert() throws Exception {
hqAssertSuccess(response);
assertEquals(response.getAlertDefinition().size(), 1);
for (AlertDefinition def : response.getAlertDefinition()) {
- validateDefinition(def);
+ validateTypeDefinition(def);
assertNull("Escalation was not null", def.getEscalation());
}
@@ -172,8 +172,10 @@ protected void validateTypeDefinition(AlertDefinition d) {
assertTrue("Invalid parent id " + d.getParent() +
" for type definition " + d.getName(),
d.getParent() == 0);
- assertTrue("No ResourcePrototype found for type based alert",
- d.getResourcePrototype() != null);
+ assertNotNull("No ResourcePrototype found for resource type alert definition",
+ d.getResourcePrototype());
+ assertNull("Resource type alert definition should have no resource",
+ d.getResource());
}
protected void validateAvailabilityAlertDefinition(AlertDefinition def,

0 comments on commit 16a30b5

Please sign in to comment.