How to create datetime string in soapui using groovy

Arunkumar picture Arunkumar · Apr 16, 2010 · Viewed 73.6k times · Source

Hi I am using SoapUI for testing web services. I need to create a customer record with email address and password. Create customer record service contains emailid and password, when I click the run(submit request) button in create customer record in SoapUI, I should get the emailid appended with current time of creation and any password.

How to do this with groovy?

Answer

Artem Zankovich picture Artem Zankovich · Apr 1, 2011

There are two common cases of inserting dynamic dateTime value in soapUI using :

  1. Insert formatted timestamp value. Use SimpleDateFormat in this case:

    ${=new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(new Date())}

  2. Format timestamp as xsd:dateTime value. Use DatatypeFactory to create instance of newXMLGregorianCalendar:

    ${=javax.xml.datatype.DatatypeFactory.newInstance().newXMLGregorianCalendar(GregorianCalendar.getInstance())}

I think that the first case works for you. Insert the code in your request and adjust timestamp format for your needs. BTW, it also works in responses for mock servers.