From: <rm...@hy...> - 2009-01-27 22:41:40
|
Author: rmorgan Date: 2009-01-27 14:41:33 -0800 (Tue, 27 Jan 2009) New Revision: 509 URL: http://svn.hyperic.org/?view=rev&root=HQApi&revision=509 Added: trunk/src/org/hyperic/hq/hqapi1/test/EscalationCreate_test.java Modified: trunk/hqu/hqapi1/app/EscalationController.groovy Log: Clean up escalation create error handling. Modified: trunk/hqu/hqapi1/app/EscalationController.groovy =================================================================== --- trunk/hqu/hqapi1/app/EscalationController.groovy 2009-01-27 22:32:49 UTC (rev 508) +++ trunk/hqu/hqapi1/app/EscalationController.groovy 2009-01-27 22:41:33 UTC (rev 509) @@ -111,9 +111,18 @@ } def create(params) { + + def failureXml def syncRequest = new XmlParser().parseText(getUpload('postdata')) + def esc - for (xmlEsc in syncRequest['Escalation']) { + if (syncRequest['Escalation'].size() != 1) { + failureXml = getFailureXML(ErrorCode.INVALID_PARAMETERS, + "Single escalation not passed to create"); + } else { + + def xmlEsc = syncRequest['Escalation'][0] + def id = xmlEsc.'@id'?.toInteger() def name = xmlEsc.'@name' def desc = xmlEsc.'@description' def pauseAllowed = xmlEsc.'@pauseAllowed'.toBoolean() @@ -121,14 +130,27 @@ def notifyAll = xmlEsc.'@notifyAll'.toBoolean() def repeat = xmlEsc.'@repeat'.toBoolean() - def esc = escalationHelper.createEscalation(name, desc, + esc = escalationHelper.getEscalation(id, name) + + if (!name || name.length() == 0) { + failureXml = getFailureXML(ErrorCode.INVALID_PARAMETERS, + "Invalid name " + name + " for " + + "escalation") + } else { + esc = escalationHelper.createEscalation(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) } Added: trunk/src/org/hyperic/hq/hqapi1/test/EscalationCreate_test.java =================================================================== --- trunk/src/org/hyperic/hq/hqapi1/test/EscalationCreate_test.java (rev 0) +++ trunk/src/org/hyperic/hq/hqapi1/test/EscalationCreate_test.java 2009-01-27 22:41:33 UTC (rev 509) @@ -0,0 +1,52 @@ +package org.hyperic.hq.hqapi1.test; + +import org.hyperic.hq.hqapi1.EscalationApi; +import org.hyperic.hq.hqapi1.EscalationActionBuilder; +import org.hyperic.hq.hqapi1.types.Escalation; +import org.hyperic.hq.hqapi1.types.EscalationResponse; + +public class EscalationCreate_test extends EscalationTestBase { + + public EscalationCreate_test(String name) { + super(name); + } + + public void testCreateValidEscalation() throws Exception { + + EscalationApi api = getEscalationApi(); + + Escalation e = generateEscalation(); + e.getAction().add(EscalationActionBuilder.createNoOpAction(1000)); + EscalationResponse createResponse = api.createEscalation(e); + hqAssertSuccess(createResponse); + } + + public void testCreateEscalationNoActions() throws Exception { + + EscalationApi api = getEscalationApi(); + + Escalation e = generateEscalation(); + EscalationResponse createResponse = api.createEscalation(e); + hqAssertSuccess(createResponse); + } + + public void testCreateEscalationEmptyName() throws Exception { + + EscalationApi api = getEscalationApi(); + + Escalation e = generateEscalation(); + e.setName(""); + EscalationResponse createResponse = api.createEscalation(e); + hqAssertFailureInvalidParameters(createResponse); + } + + public void testCreateEscalationNullName() throws Exception { + + EscalationApi api = getEscalationApi(); + + Escalation e = generateEscalation(); + e.setName(null); + EscalationResponse createResponse = api.createEscalation(e); + hqAssertFailureInvalidParameters(createResponse); + } +} |