Forum Discussion

debargmi's avatar
13 years ago

Soap UI Mock Service Response Editing

Hi,

I am very much new to Soap UI...Was trying to invoke a mock service which ultimately gave me the below response message...

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:abcd="http://192.168.100.57:8080/axis/services/GetCurrentLevelAndBalanceService" xmlns:abcd1="http://localhost:8080/axis/services/CreateMemberService?wsdl">
<soapenv:Header/>
<soapenv:Body>
<ih:processReturn>
<ih1:getCurrentLevelAndBalanceResponse>
<ih1:currentBalance>200</abcd1:currentBalance>
<ih1:levelFlightsQualificationYear>2009</abcd1:levelFlightsQualificationYear>
<ih1:levelFlightsRolling12Months>12</abcd1:levelFlightsRolling12Months>
<ih1:levelMilesQualificationYear>2010</abcd1:levelMilesQualificationYear>
<abcd1:levelMilesRolling12Months>03</abcd1:levelMilesRolling12Months>
<abcd1:tierCode>1234</abcd1:tierCode>
<abcd1:voucherList>
<!--Zero or more repetitions:-->
<abcd:item>
<abcd1:voucherExpiryDate>12/26/2015</abcd1:voucherExpiryDate>
<abcd1:voucherNumber>4667</abcd1:voucherNumber>
<abcd1:voucherStatus>Active</abcd1:voucherStatus>
</abcd:item>
</abcd1:voucherList>
</abcd1:getCurrentLevelAndBalanceResponse>
<abcd1:transactionHeader>
<abcd1:messageId>67899</abcd1:messageId>
<abcd1:timestamp>1832329232</abcd1:timestamp>
<abcd1:transactionID>a3456gf</abcd1:transactionID>
<abcd1:userName>Deb</abcd1:userName>
</abcd1:transactionHeader>
</abcd:processReturn>
</soapenv:Body>
</soapenv:Envelope>

I need to edit any timestamp value giving current timestamp using scripts...

Can you let me know what exact script I need to add....The Soap UI Tutorial is not very much helpful for beginners...

Regards,
Deb
  • tjdurden's avatar
    tjdurden
    Frequent Contributor
    Hi Deb,

    One way to approach this is to use a Groovy script TestStep to create a timestamp and save the timestamp to a property (within a Property TestStep). Once the value is stored inside the Property step, this can be used within your SOAP request.

    1) The Groovy TestStep
    Place the following code inside a Groovy step, which should be the first item in your Test Case (or at least, before the property step and soap request):

    // Get the current date/time
    def startDate = new Date()
    // Format as necessary
    def timeStamp = startDate.format("yyyy-MM-dd'T'HH:mm:ss SSS")
    // Write to log to show it works as we want it to...
    log.info("The time sponsored by SoapUI is: " + timeStamp);

    // create a holder for properties
    def myProps = new java.util.Properties();
    // get the properties step from your test case
    myProps = testRunner.testCase.getTestStepByName("myProperties");
    // Save the current timestamp to a property
    myProps.setPropertyValue("currentTimestamp",timeStamp);


    2) Create a Property TestStep
    Add a property that will hold your timestamp. The above Groovy assumed you call your Property TestStep "myProperties", and you create a property inside that step called "currentTimestamp".

    3) Alter your XML to use your dynamic property.
    Having done the above, you will need to add a reference to to your property (the timestamp) within the SOAP request itself. To do this, simple add "${currentTimestamp}" in the request where you want the timestamp to be added. This can be added multiple times.
    Example:

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:enum="http://www.example.org/someExample/">
    <soapenv:Header/>
    <soapenv:Body>
    <enum:elem1>${currentTimestamp}</enum:elem1>
    </soapenv:Body>
    </soapenv:Envelope>

    Kind regards,
    Tim