Groovy Property Expansion

A very useful feature of #soapui property expansion is that you can use it to coerce values from Java static methods, including factories, as properties directly use these directly requests to achieve some useful shortcuts. In all of these example the code that appear inside the context.expand('') can appear directly in property.

correlationID = context.expand('${=java.util.UUID.randomUUID()}')
testRunner.testCase.setPropertyValue("correlationID", correlationID)
log.info("correlationID="+testRunner.testCase.getPropertyValue("correlationID"))
 
startTime = context.expand('${=System.currentTimeMillis()}')
testRunner.testCase.setPropertyValue("startTime", startTime)
log.info("startTime="+testRunner.testCase.getPropertyValue("startTime"))
 
currentTime = context.expand('${=Calendar.getInstance().getTime()}')
testRunner.testCase.setPropertyValue("currentTime", currentTime)
log.info("currentTime="+testRunner.testCase.getPropertyValue("currentTime"))
 
isoDate = context.expand('${=new java.text.SimpleDateFormat("yyyy-mm-dd").format(Calendar.getInstance().getTime())}')
testRunner.testCase.setPropertyValue("isoDate", isoDate)
log.info("isoDate="+testRunner.testCase.getPropertyValue("isoDate"))
 
currentLocale = context.expand('${=Locale.getDefault()}')
testRunner.testCase.setPropertyValue("currentLocale", currentLocale)
log.info("currentLocale="+testRunner.testCase.getPropertyValue("currentLocale"))
 
systemProperty = context.expand('${=System.getProperty("soapui.home")}')
testRunner.testCase.setPropertyValue("systemProperty", systemProperty)
log.info("systemProperty="+testRunner.testCase.getPropertyValue("systemProperty"))

leverage_groovy_property_expansion.txt ยท Last modified: 2015/07/16 12:41 by Martin Spamer