From: <rm...@hy...> - 2009-01-27 23:02:47
|
Author: rmorgan Date: 2009-01-27 14:32:49 -0800 (Tue, 27 Jan 2009) New Revision: 508 URL: http://svn.hyperic.org/?view=rev&root=HQApi&revision=508 Modified: trunk/hqu/hqapi1/app/EscalationController.groovy trunk/src/org/hyperic/hq/hqapi1/test/EscalationUpdateEscalation_test.java Log: Fix escalation update for non-existant escalation. Modified: trunk/hqu/hqapi1/app/EscalationController.groovy =================================================================== --- trunk/hqu/hqapi1/app/EscalationController.groovy 2009-01-27 21:47:05 UTC (rev 507) +++ trunk/hqu/hqapi1/app/EscalationController.groovy 2009-01-27 22:32:49 UTC (rev 508) @@ -137,9 +137,16 @@ } def update(params) { + def failureXml def syncRequest = new XmlParser().parseText(getUpload('postdata')) - - for (xmlEsc in syncRequest['Escalation']) { + def esc + + if (syncRequest['Escalation'].size() != 1) { + failureXml = getFailureXML(ErrorCode.INVALID_PARAMETERS, + "Single escalation not passed to update"); + } else { + + def xmlEsc = syncRequest['Escalation'][0] def id = xmlEsc.'@id'?.toInteger() def name = xmlEsc.'@name' def desc = xmlEsc.'@description' @@ -148,14 +155,25 @@ def notifyAll = xmlEsc.'@notifyAll'.toBoolean() def repeat = xmlEsc.'@repeat'.toBoolean() - def esc = escalationHelper.getEscalation(id, name) - escalationHelper.updateEscalation(esc, name, desc, pauseAllowed, - maxWaitTime, notifyAll, repeat) + esc = escalationHelper.getEscalation(id, name) + + if (!esc) { + failureXml = getFailureXML(ErrorCode.OBJECT_NOT_FOUND, + "Unable to find escalation with id=" + + id + " name=" + name) + } else { + escalationHelper.updateEscalation(esc, name, desc, pauseAllowed, + maxWaitTime, notifyAll, repeat) - syncActions(esc, xmlEsc['Action']) - - renderXml() { - out << EscalationResponse() { + syncActions(esc, xmlEsc['Action']) + } + } + + renderXml() { + out << EscalationResponse() { + if (failureXml) { + out << failureXml + } else { out << getSuccessXML() out << getEscalationXML(esc) } Modified: trunk/src/org/hyperic/hq/hqapi1/test/EscalationUpdateEscalation_test.java =================================================================== --- trunk/src/org/hyperic/hq/hqapi1/test/EscalationUpdateEscalation_test.java 2009-01-27 21:47:05 UTC (rev 507) +++ trunk/src/org/hyperic/hq/hqapi1/test/EscalationUpdateEscalation_test.java 2009-01-27 22:32:49 UTC (rev 508) @@ -59,4 +59,23 @@ cleanup(updated); } + + public void testUpdateNonExistantEscalation() throws Exception { + + EscalationApi api = getEscalationApi(); + + Escalation e = generateEscalation(); + e.getAction().add(EscalationActionBuilder.createNoOpAction(1000)); + EscalationResponse createResponse = api.updateEscalation(e); + hqAssertFailureObjectNotFound(createResponse); + } + + public void testUpdateEmptyEscalation() throws Exception { + + EscalationApi api = getEscalationApi(); + + Escalation e = generateEscalation(); + EscalationResponse createResponse = api.updateEscalation(e); + hqAssertFailureObjectNotFound(createResponse); + } } |