Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create datetime string in soapui using groovy [closed]

Tags:

groovy

soapui

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?

like image 766
Arunkumar Avatar asked Apr 16 '10 04:04

Arunkumar


People also ask

How do I convert a date to a string in groovy?

String newDate = Date. parse('MM/dd/yyyy',dt). format("yyyy-MM-dd'T'HH:mm:ss'Z'");

How do I get the current date in SoapUI?

In SOAPUI you can use groovy code directly in your SOAP Request using the follow notation ${=groovy expression} , so in your case you can use ${=new java. text. SimpleDateFormat("yyyy-MM-dd"). format(new java.

How do I change the date format in groovy?

Date object and will have the Default formatting of 'E MMM dd HH:mm:ss z yyyy'. So the string date of '2012-12-11 00:00:00' will now appear as 'Tue Dec 11 00:00:00 EST 2012'. If you wish to change from the default date formatting you can append a . format() to function and pass it a string paramater.

How do I create a groovy script in SoapUI?

Create and Test a Groovy Script in a SoapUI ToolStep 1: Select the CalculatorSoap TestSuite and then select the Test Case in which we are going to create the Groovy script. Right-click on the Test Steps, and then go to the Add Step to select the Groovy Script from the available service, as shown below.


1 Answers

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

  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.

like image 100
Artem Zankovich Avatar answered Oct 02 '22 15:10

Artem Zankovich