Pass properties as JSON in SoapUI

I have a series of steps to create as a use case for a program I am working on. For example, a user must first create a CASE and send a response _id (database key) as a case_id when creating an IDENTITY.

POST CASE request:

{ "display_name" : "Sample Case"}

      

Answer:

[{
   "synthetic": false,
   "last_updated": "2014-08-25 16:50:07.956611",
   "encrypted": false,
   "date_created": "2014-08-25 16:50:07.956602",
   "_id": "53fb693fc41be928380d5fe0",
   "display_name": "Sample Case"
}]

      

The answer is in XML:

<Response>
   <e>
      <_id>53fb693fc41be928380d5fe0</_id>
      <date_created>2014-08-25 16:50:07.956602</date_created>
      <display_name>Sample Case</display_name>
      <encrypted>false</encrypted>
      <last_updated>2014-08-25 16:50:07.956611</last_updated>
      <synthetic>false</synthetic>
   </e>
</Response>

      

IDENTIFICATION AFTER REQUEST:

{
    "display_name" : "John Doe",
    "case_id" : "53fb693fc41be928380d5fe0",
    "type" : "person",
}

      

The problem I'm running into is that while I can grab the _id value from the case response and populate it in the property set, I can't figure out how to turn that properties object into a JSON request (which is the program I am with working, requires REST requests).

Is there a way to dynamically generate JSON data for a REST request using Test Suite?

+3


source to share


2 answers


If you just want to paste something from the previous answer, you can use the SoapUI property extension:

${previous_step_name#ResponseAsXml#//*:_id}

      

So your example would look something like this:



{
    "display_name" : "John Doe",
    "case_id" : "${previous_step_name#ResponseAsXml#//*:_id}",
    "type" : "person",
}

      

If you want something more interesting to "dynamically create JSON data", you will need to explain exactly what you want. Here's a good place for you to start: http://siking.wordpress.com/2013/07/05/dynamically-create-elements-in-a-soapui-request-json-version/

+5


source


JSONBuilder is an option like @SiKing.

A very simple solution for this is to add differents templates to your project with the format of each request.

CaseTemplate.json →

{ "display_name" : "${display_name}"}

      

IdentityTemplate.json →



{
"display_name" : "Sample Case",
"case_id" : "${case_id}",
"type" : "${display_name}"
}

      

Then, before each test request step in property passing, you can set the Request Property of the test request step with the contents of one of these payloads.

Source: Name_of_your_project -> Property:IdentityTemplate
Target: Request_test_step_name -> Property: Request

      

And then set all the properties of your new template in another property transfer.

Make sure you have defined these properties correctly in the rest request interface.

0


source







All Articles