From: <rm...@hy...> - 2009-01-16 02:45:45
|
Author: rmorgan Date: 2009-01-15 18:45:32 -0800 (Thu, 15 Jan 2009) New Revision: 460 URL: http://svn.hyperic.org/?view=rev&root=HQApi&revision=460 Modified: trunk/hqu/hqapi1/app/AlertdefinitionController.groovy trunk/src/org/hyperic/hq/hqapi1/test/AlertDefinitionSync_test.java Log: Add addtional alert definition tests. Modified: trunk/hqu/hqapi1/app/AlertdefinitionController.groovy =================================================================== --- trunk/hqu/hqapi1/app/AlertdefinitionController.groovy 2009-01-15 04:24:11 UTC (rev 459) +++ trunk/hqu/hqapi1/app/AlertdefinitionController.groovy 2009-01-16 02:45:32 UTC (rev 460) @@ -580,10 +580,18 @@ try { def sessionId = SessionManager.instance.put(user) if (adv.id == null) { - def newDef = eventBoss.createResourceTypeAlertDefinition(sessionId, - aeid, adv) + def newDef + if (typeBased) { + newDef = + eventBoss.createResourceTypeAlertDefinition(sessionId, + aeid, adv) + } else { + newDef = eventBoss.createAlertDefinition(sessionId, + adv) + } adv.id = newDef.id } else { + log.info "Updating alert definition with id = " + adv.id eventBoss.updateAlertDefinition(sessionId, adv) } } catch (Exception e) { Modified: trunk/src/org/hyperic/hq/hqapi1/test/AlertDefinitionSync_test.java =================================================================== --- trunk/src/org/hyperic/hq/hqapi1/test/AlertDefinitionSync_test.java 2009-01-15 04:24:11 UTC (rev 459) +++ trunk/src/org/hyperic/hq/hqapi1/test/AlertDefinitionSync_test.java 2009-01-16 02:45:32 UTC (rev 460) @@ -129,11 +129,32 @@ hqAssertFailureInvalidParameters(response); } - public void testSyncBasicDefinition() throws Exception { + public void testSyncCreateDefinition() throws Exception { AlertDefinitionApi api = getApi().getAlertDefinitionApi(); Resource platform = getLocalPlatformResource(false, false); AlertDefinition d = createTestDefinition(); + d.setResource(platform); + d.getAlertCondition().add(AlertDefinitionBuilder.createPropertyCondition(true, "myProp")); + 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); + } + + // Cleanup + cleanup(response.getAlertDefinition()); + } + + public void testSyncCreateTypeDefinition() throws Exception { + AlertDefinitionApi api = getApi().getAlertDefinitionApi(); + Resource platform = getLocalPlatformResource(false, false); + + AlertDefinition d = createTestDefinition(); d.setResourcePrototype(platform.getResourcePrototype()); d.getAlertCondition().add(AlertDefinitionBuilder.createPropertyCondition(true, "myProp")); List<AlertDefinition> definitions = new ArrayList<AlertDefinition>(); @@ -173,6 +194,8 @@ cleanup(response.getAlertDefinition()); } + // TODO: test sync multi broken with type alerts + public void testSyncMulti() throws Exception { AlertDefinitionApi api = getApi().getAlertDefinitionApi(); Resource platform = getLocalPlatformResource(false, false); @@ -181,7 +204,7 @@ List<AlertDefinition> definitions = new ArrayList<AlertDefinition>(); for (int i = 0; i < NUM_DEFS; i++) { AlertDefinition d = createTestDefinition(); - d.setResourcePrototype(platform.getResourcePrototype()); + d.setResource(platform); d.getAlertCondition().add(AlertDefinitionBuilder.createPropertyCondition(true, "myProp")); definitions.add(d); } @@ -193,6 +216,26 @@ validateDefinition(def); } + // Re-sync for update + definitions = response.getAlertDefinition(); + final String UPDATED_DESCRIPTION = "Updated Alert Description"; + final AlertCondition newCond = + AlertDefinitionBuilder.createPropertyCondition(true, "otherProp"); + for (AlertDefinition d : definitions) { + 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 (AlertCondition c : d.getAlertCondition()) { + assertTrue(c.getProperty().equals("otherProp")); + } + } + // Cleanup cleanup(response.getAlertDefinition()); } @@ -267,6 +310,59 @@ escApi.deleteEscalation(escalationResponse.getEscalation().getId()); } + // TODO: sync update with esclation broken with type alerts + + public void testSyncUpdateWithEscalation() throws Exception { + + HQApi api = getApi(); + AlertDefinitionApi defApi = api.getAlertDefinitionApi(); + EscalationApi escApi = api.getEscalationApi(); + + Resource platform = getLocalPlatformResource(false, false); + + AlertDefinition d = createTestDefinition(); + d.setResource(platform); + d.getAlertCondition().add(AlertDefinitionBuilder.createPropertyCondition(true, "myProp")); + List<AlertDefinition> definitions = new ArrayList<AlertDefinition>(); + definitions.add(d); + + AlertDefinitionsResponse response = defApi.syncAlertDefinitions(definitions); + hqAssertSuccess(response); + assertEquals(response.getAlertDefinition().size(), 1); + for (AlertDefinition def : response.getAlertDefinition()) { + validateDefinition(def); + assertNotNull("Resource was null", def.getResource()); + assertNull("Escalation was not null", def.getEscalation()); + } + + // Re-sync with escalation + Random r = new Random(); + Escalation e = new Escalation(); + e.setName("Test Escalation" + r.nextInt()); + EscalationResponse escalationResponse = + escApi.createEscalation(e); + hqAssertSuccess(escalationResponse); + + definitions = response.getAlertDefinition(); + for (AlertDefinition def : definitions) { + def.setEscalation(e); + } + + response = defApi.syncAlertDefinitions(definitions); + hqAssertSuccess(response); + assertEquals(response.getAlertDefinition().size(), 1); + for (AlertDefinition def : response.getAlertDefinition()) { + validateDefinition(def); + // TODO: Fix me + //assertNotNull("Escalation was null", def.getEscalation()); + //assertEquals(d.getEscalation().getName(), e.getName()); + } + + // Cleanup + cleanup(response.getAlertDefinition()); + escApi.deleteEscalation(escalationResponse.getEscalation().getId()); + } + // AlertCondition tests public void testSyncNoConditions() throws Exception { |