Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ryan Morgan
committed
Jul 13, 2009
1 parent
1fadbf3
commit 4816b05
Showing
6 changed files
with
327 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.hyperic.hq.hqapi1.test; | ||
|
||
import org.hyperic.hq.hqapi1.types.AlertDefinition; | ||
import org.hyperic.hq.hqapi1.types.AlertsResponse; | ||
import org.hyperic.hq.hqapi1.types.Alert; | ||
import org.hyperic.hq.hqapi1.types.StatusResponse; | ||
import org.hyperic.hq.hqapi1.AlertApi; | ||
|
||
public class AlertAck_test extends AlertTestBase { | ||
|
||
public AlertAck_test(String name) { | ||
super(name); | ||
} | ||
|
||
public void testAckAlert() throws Exception { | ||
AlertDefinition d = generateAlerts(); | ||
AlertApi api = getAlertApi(); | ||
|
||
AlertsResponse response = api.findAlerts(0, System.currentTimeMillis(), | ||
10, 1, false, false); | ||
hqAssertSuccess(response); | ||
assertTrue(response.getAlert().size() <= 10); | ||
assertTrue(response.getAlert().size() > 0); | ||
|
||
// Test ack | ||
Alert a = response.getAlert().get(0); | ||
|
||
StatusResponse ackResponse = api.ackAlert(a.getId(), "Test ACK", 60000l); | ||
hqAssertSuccess(ackResponse); | ||
|
||
// TODO: Valididate ack? Will require a getById API. | ||
|
||
// Cleanup | ||
StatusResponse deleteResponse = getApi(). | ||
getAlertDefinitionApi().deleteAlertDefinition(d.getId()); | ||
hqAssertSuccess(deleteResponse); | ||
} | ||
|
||
public void testAckInvalidAlert() throws Exception { | ||
|
||
AlertApi api = getAlertApi(); | ||
|
||
StatusResponse response = api.ackAlert(Integer.MAX_VALUE, "Test ACK", 60000l); | ||
hqAssertFailureObjectNotFound(response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.hyperic.hq.hqapi1.test; | ||
|
||
import org.hyperic.hq.hqapi1.types.AlertDefinition; | ||
import org.hyperic.hq.hqapi1.types.AlertsResponse; | ||
import org.hyperic.hq.hqapi1.types.Alert; | ||
import org.hyperic.hq.hqapi1.types.StatusResponse; | ||
import org.hyperic.hq.hqapi1.AlertApi; | ||
|
||
public class AlertDelete_test extends AlertTestBase { | ||
|
||
public AlertDelete_test(String name) { | ||
super(name); | ||
} | ||
|
||
public void testDeleteAlert() throws Exception { | ||
AlertDefinition d = generateAlerts(); | ||
AlertApi api = getAlertApi(); | ||
|
||
AlertsResponse response = api.findAlerts(0, System.currentTimeMillis(), | ||
10, 1, false, false); | ||
hqAssertSuccess(response); | ||
assertTrue(response.getAlert().size() <= 10); | ||
assertTrue(response.getAlert().size() > 0); | ||
|
||
// Test delete | ||
Alert a = response.getAlert().get(0); | ||
|
||
StatusResponse deleteResponse = api.delete(a.getId()); | ||
hqAssertSuccess(deleteResponse); | ||
|
||
// TODO: Valididate alert was deleted? Will require a getById API. | ||
|
||
// Cleanup | ||
StatusResponse deleteDefResponse = getApi(). | ||
getAlertDefinitionApi().deleteAlertDefinition(d.getId()); | ||
hqAssertSuccess(deleteDefResponse); | ||
} | ||
|
||
public void testDeleteInvalidAlert() throws Exception { | ||
|
||
AlertApi api = getAlertApi(); | ||
|
||
StatusResponse response = api.delete(Integer.MAX_VALUE); | ||
hqAssertFailureObjectNotFound(response); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
src/org/hyperic/hq/hqapi1/test/AlertFindByResource_test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package org.hyperic.hq.hqapi1.test; | ||
|
||
import org.hyperic.hq.hqapi1.types.AlertDefinition; | ||
import org.hyperic.hq.hqapi1.types.AlertsResponse; | ||
import org.hyperic.hq.hqapi1.types.StatusResponse; | ||
import org.hyperic.hq.hqapi1.types.Resource; | ||
import org.hyperic.hq.hqapi1.AlertApi; | ||
|
||
public class AlertFindByResource_test extends AlertTestBase { | ||
|
||
public AlertFindByResource_test(String name) { | ||
super(name); | ||
} | ||
|
||
public void testFindValid() throws Exception { | ||
Resource r = getLocalPlatformResource(false, false); | ||
AlertDefinition d = generateAlerts(); | ||
|
||
AlertApi api = getAlertApi(); | ||
|
||
AlertsResponse response = api.findAlerts(r, 0, System.currentTimeMillis(), | ||
10, 1, false, false); | ||
hqAssertSuccess(response); | ||
assertTrue(response.getAlert().size() <= 10); | ||
|
||
// Cleanup | ||
StatusResponse deleteResponse = getApi().getAlertDefinitionApi(). | ||
deleteAlertDefinition(d.getId()); | ||
hqAssertSuccess(deleteResponse); | ||
} | ||
|
||
public void testFindInvalidSeverity() throws Exception { | ||
Resource r = getLocalPlatformResource(false, false); | ||
AlertApi api = getAlertApi(); | ||
AlertsResponse response = api.findAlerts(r, 0, System.currentTimeMillis(), | ||
10, 4, false, false); | ||
hqAssertFailureInvalidParameters(response); | ||
} | ||
|
||
public void testFindInvalidCount() throws Exception { | ||
Resource r = getLocalPlatformResource(false, false); | ||
AlertApi api = getAlertApi(); | ||
AlertsResponse response = api.findAlerts(r, 0, System.currentTimeMillis(), | ||
-5, 2, false, false); | ||
hqAssertFailureInvalidParameters(response); | ||
} | ||
|
||
public void testFindInvalidRange() throws Exception { | ||
Resource r = getLocalPlatformResource(false, false); | ||
AlertApi api = getAlertApi(); | ||
|
||
AlertsResponse response = api.findAlerts(r, System.currentTimeMillis(), 0, | ||
10, 2, false, false); | ||
hqAssertFailureInvalidParameters(response); | ||
} | ||
|
||
public void testFindInvalidResource() throws Exception { | ||
Resource r = new Resource(); | ||
r.setId(Integer.MAX_VALUE); | ||
r.setName("Invalid resource"); | ||
AlertApi api = getAlertApi(); | ||
AlertsResponse response = api.findAlerts(r, 0, System.currentTimeMillis(), | ||
10, 1, false, false); | ||
hqAssertFailureObjectNotFound(response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.hyperic.hq.hqapi1.test; | ||
|
||
import org.hyperic.hq.hqapi1.types.AlertDefinition; | ||
import org.hyperic.hq.hqapi1.AlertApi; | ||
import org.hyperic.hq.hqapi1.types.AlertsResponse; | ||
import org.hyperic.hq.hqapi1.types.StatusResponse; | ||
|
||
public class AlertFind_test extends AlertTestBase { | ||
|
||
public AlertFind_test(String name) { | ||
super(name); | ||
} | ||
|
||
public void testFindValid() throws Exception { | ||
AlertDefinition d = generateAlerts(); | ||
AlertApi api = getAlertApi(); | ||
|
||
AlertsResponse response = api.findAlerts(0, System.currentTimeMillis(), | ||
10, 1, false, false); | ||
hqAssertSuccess(response); | ||
assertTrue(response.getAlert().size() <= 10); | ||
|
||
// Cleanup | ||
StatusResponse deleteResponse = getApi(). | ||
getAlertDefinitionApi().deleteAlertDefinition(d.getId()); | ||
hqAssertSuccess(deleteResponse); | ||
} | ||
|
||
public void testFindInvalidSeverity() throws Exception { | ||
AlertApi api = getAlertApi(); | ||
AlertsResponse response = api.findAlerts(0, System.currentTimeMillis(), | ||
10, 4, false, false); | ||
hqAssertFailureInvalidParameters(response); | ||
} | ||
|
||
public void testFindInvalidCount() throws Exception { | ||
AlertApi api = getAlertApi(); | ||
AlertsResponse response = api.findAlerts(0, System.currentTimeMillis(), | ||
-5, 2, false, false); | ||
hqAssertFailureInvalidParameters(response); | ||
} | ||
|
||
public void testFindInvalidRange() throws Exception { | ||
AlertApi api = getAlertApi(); | ||
AlertsResponse response = api.findAlerts(System.currentTimeMillis(), 0, | ||
10, 2, false, false); | ||
hqAssertFailureInvalidParameters(response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.hyperic.hq.hqapi1.test; | ||
|
||
import org.hyperic.hq.hqapi1.types.AlertDefinition; | ||
import org.hyperic.hq.hqapi1.types.AlertsResponse; | ||
import org.hyperic.hq.hqapi1.types.StatusResponse; | ||
import org.hyperic.hq.hqapi1.types.Alert; | ||
import org.hyperic.hq.hqapi1.AlertApi; | ||
|
||
public class AlertFix_test extends AlertTestBase { | ||
|
||
public AlertFix_test(String name) { | ||
super(name); | ||
} | ||
|
||
public void testFixAlert() throws Exception { | ||
AlertDefinition d = generateAlerts(); | ||
AlertApi api = getAlertApi(); | ||
|
||
AlertsResponse response = api.findAlerts(0, System.currentTimeMillis(), | ||
10, 1, false, false); | ||
hqAssertSuccess(response); | ||
assertTrue(response.getAlert().size() <= 10); | ||
assertTrue(response.getAlert().size() > 0); | ||
|
||
// Test marking fixed | ||
Alert a = response.getAlert().get(0); | ||
|
||
StatusResponse fixResponse = api.fixAlert(a.getId()); | ||
hqAssertSuccess(fixResponse); | ||
|
||
// TODO: Valididate fix flag was set? Will require a getById API. | ||
|
||
// Cleanup | ||
StatusResponse deleteResponse = getApi(). | ||
getAlertDefinitionApi().deleteAlertDefinition(d.getId()); | ||
hqAssertSuccess(deleteResponse); | ||
} | ||
|
||
public void testFixInvalidAlert() throws Exception { | ||
|
||
AlertApi api = getAlertApi(); | ||
|
||
StatusResponse response = api.fixAlert(Integer.MAX_VALUE); | ||
hqAssertFailureObjectNotFound(response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package org.hyperic.hq.hqapi1.test; | ||
|
||
import org.hyperic.hq.hqapi1.AlertApi; | ||
import org.hyperic.hq.hqapi1.AlertDefinitionBuilder; | ||
import org.hyperic.hq.hqapi1.AlertDefinitionApi; | ||
import org.hyperic.hq.hqapi1.types.AlertDefinition; | ||
import org.hyperic.hq.hqapi1.types.Resource; | ||
import org.hyperic.hq.hqapi1.types.StatusResponse; | ||
import org.hyperic.hq.hqapi1.types.AlertDefinitionsResponse; | ||
import org.hyperic.hq.hqapi1.types.AlertsResponse; | ||
|
||
import java.util.Random; | ||
import java.util.List; | ||
import java.util.ArrayList; | ||
|
||
public class AlertTestBase extends HQApiTestBase { | ||
|
||
public AlertTestBase(String name) { | ||
super(name); | ||
} | ||
|
||
protected AlertApi getAlertApi() { | ||
return getApi().getAlertApi(); | ||
} | ||
|
||
/** | ||
* Setup an AlertDefinition that will fire Alert instances waiting for | ||
* at least 1 alert to be generated. | ||
* | ||
* @return The AlertDefinition that was created to generate the alerts. | ||
*/ | ||
protected AlertDefinition generateAlerts() throws Exception { | ||
Resource platform = getLocalPlatformResource(false, false); | ||
AlertDefinition d = new AlertDefinition(); | ||
|
||
Random r = new Random(); | ||
d.setName("Test Alert Definition" + r.nextInt()); | ||
d.setDescription("Definition that will always fire, allowing for testing of Alerts"); | ||
d.setPriority(AlertDefinitionBuilder.AlertPriority.MEDIUM.getPriority()); | ||
d.setActive(true); | ||
d.setResource(platform); | ||
d.getAlertCondition().add(AlertDefinitionBuilder. | ||
createThresholdCondition(true, "Availability", | ||
AlertDefinitionBuilder.AlertComparator.GREATER_THAN, -1)); | ||
|
||
AlertDefinitionApi defApi = getApi().getAlertDefinitionApi(); | ||
|
||
List<AlertDefinition> definitions = new ArrayList<AlertDefinition>(); | ||
definitions.add(d); | ||
AlertDefinitionsResponse response = defApi.syncAlertDefinitions(definitions); | ||
hqAssertSuccess(response); | ||
|
||
// Now we wait.. | ||
for (int i = 0; i < 120; i++) { | ||
// Wait for alerts | ||
System.out.println("Waiting for alerts..."); | ||
AlertsResponse alerts = getAlertApi().findAlerts(platform, 0, | ||
System.currentTimeMillis(), | ||
10, 1, false, false); | ||
hqAssertSuccess(alerts); | ||
if (alerts.getAlert().size() > 0) { | ||
break; | ||
} | ||
|
||
try { | ||
Thread.sleep(1000); | ||
} catch (InterruptedException e) { | ||
// Ignore | ||
} | ||
} | ||
|
||
return response.getAlertDefinition().get(0); | ||
} | ||
} |