Skip to content

Instantly share code, notes, and snippets.

@raidzero
Last active December 22, 2015 19:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raidzero/0c88b0285bcdb76745fa to your computer and use it in GitHub Desktop.
Save raidzero/0c88b0285bcdb76745fa to your computer and use it in GitHub Desktop.
groovy extract date range in days from xml (for soapui)
import groovy.time.TimeCategory
// create XmlHolder for request content
def holder = new com.eviware.soapui.support.XmlHolder( mockRequest.requestContent )
// get arguments
def startDateStr = holder["//b:StartDate"]
def endDateStr = holder["//b:EndDate"]
log.info "start: " + startDateStr + " end:" + endDateStr
try
{
def startDate = Date.parse("yyyy-MM-dd", startDateStr)
def endDate = Date.parse("yyyy-MM-dd", endDateStr)
log.info "RANGE: " + startDate + " - " + endDate
def range = TimeCategory.minus(endDate, startDate).days + "d"
log.info "range string: " + range
// range is known. return it (response name)
return range
} catch(e) {
log.info "Error: " + e
return "Invalid Input Response"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment