Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

How do I parameterize XML

LegacyForum
LegacyForum Posts: 1,664 ✭✭
edited December 2016 in SOAtest
I'm brand new to SOATest, so this is probably a very basic question. The Rest service that I'm testing requires a unique name in the <name> field, so I'd like to use a date time stamp. At the moment, I have the following XML

<service>
<name>/registerService/update1</name>
<description>service to let implementers to register service</description>
<type>A</type>
<isActive>Y</isActive>
<tokenAgeUnit>D</tokenAgeUnit>
<tokenAgeValue>9</tokenAgeValue>
</service>

in the Payload section. I want to replace the "update1" with the date time stamp.

Scott
Tagged:

Comments

  • LegacyForum
    LegacyForum Posts: 1,664 ✭✭
    Hello Scott,

    To replace the "update1" value in the "name" element with a date and time stamp, first, you will need a script to generate the date and time stamp.

    Below is a sample script that will get the date and time, format it according to a given pattern, and return the "name" element containing the date and time stamp...

    CODE
    from java.text import *
    from java.util import *

    def getTime():
    # Get an instance of the calendar
    calendar = Calendar.getInstance()

    # Set the hour in the calendar
    hour = calendar.get(Calendar.HOUR_OF_DAY)
    calendar.set(Calendar.HOUR_OF_DAY, hour)

    # Retreive the date from the calendar
    date = calendar.getTime()

    # Create the date formatter
    myFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
    formatter = SimpleDateFormat(myFormat)

    # Create the date and time stamp, and print and return the name value
    timestamp = formatter.format(date)
    name = "/registerService/" + timestamp
    print name
    return name


    Now that you have a script written, you'll need to set up your REST client test to use it. To do this...

    1) Open the test configuration panel for your REST client test

    2) Switch to the "Payload" tab

    3) For "Input Mode", select "Form XML" from the drop-down menu

    4) Select the "name" element on the left

    5) Under "Value" on the right, select "Script" from the drop-down menu

    6) Click "Edit Script"

    7) For "Language", select "Jython"

    8) Make sure the "Text" radio button is selected

    9) Paste the script into the text box

    10) Click "Evaluate" and make sure no errors appear

    11) Make sure that getTime() is selected for "Method"

    12) Click "OK"

    13) Save your REST client test

    After running your test, you should open the "Traffic Viewer" for the test to verify that the request XML contains the properly formatted "name" element with the
    required date and time stamp. I've tested the sample XML you gave me along with the script and everything seems to work properly on my end.

    Let me know if you have any additional questions...

    Regards,
    Adam
  • LegacyForum
    LegacyForum Posts: 1,664 ✭✭
    Thanks Adam. This is by far the best answer I've ever received on a forum like this.

    Jython was not an available selection in the language drop down, and I don't see an evaluate button. I'm using v6.2. Could that be the reason?

    Your solution worked, however, with Python selected as the language.

    Thanks again,
    Scott
  • LegacyForum
    LegacyForum Posts: 1,664 ✭✭
    Hello Scott,

    No problem! Glad everything worked out.

    You're right about Jython not being available as a language and "Evaluate" being unavailable in version 6.2 of SOAtest.
    I just tested the script in my SOAtest 6.2 to verify.

    Regards,
    Adam
  • sailee
    sailee Posts: 7

    Hello Adam,
    I am currently looking to do input method scripting using java.
    if possible please suggest scripting code for method and URL in case of REST service.