Skip to content

Commit

Permalink
Improve integration test validation when syncing resource type alert …
Browse files Browse the repository at this point in the history
…definitions
  • Loading branch information
pnguyen committed Dec 24, 2009
1 parent 6175a74 commit 16a30b5
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 23 deletions.
90 changes: 69 additions & 21 deletions src/org/hyperic/hq/hqapi1/test/AlertDefinitionSync_test.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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());
}
Expand Down Expand Up @@ -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();
Expand All @@ -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());
}
Expand Down Expand Up @@ -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());
}

Expand All @@ -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());
}
Expand Down Expand Up @@ -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());
}

Expand All @@ -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());
}

Expand Down
6 changes: 4 additions & 2 deletions src/org/hyperic/hq/hqapi1/test/AlertDefinitionTestBase.java
Expand Up @@ -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,
Expand Down

0 comments on commit 16a30b5

Please sign in to comment.