Reputation: 611
I have a series of creation steps as an example of the use case for the program I'm working on. For example, a user must first create a CASE and send the response _id (database key), as the case_id when creating an IDENTITY.
POST CASE request:
{ "display_name" : "Sample Case"}
Response:
[{
"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"
}]
Response 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>
POST IDENTITY Request:
{
"display_name" : "John Doe",
"case_id" : "53fb693fc41be928380d5fe0",
"type" : "person",
}
The issue I'm having is that while I can capture the _id value from a case response, and fill that into a set of properties, I can't figure out how to turn that properties object into a JSON request (which the program I'm working with requires for REST requests).
Is there a way to dynamically create JSON data for a REST request using the Test Suite?
Upvotes: 3
Views: 8900
Reputation: 10329
If you want to just insert something from a previous Response, you can use SoapUI property expansion:
${previous_step_name#ResponseAsXml#//*:_id}
So your example would look something like:
{
"display_name" : "John Doe",
"case_id" : "${previous_step_name#ResponseAsXml#//*:_id}",
"type" : "person",
}
If you need something more fancy to "dynamically create JSON data", you would need to explain what it is that you want. Here is something to possibly get you started: http://siking.wordpress.com/2013/07/05/dynamically-create-elements-in-a-soapui-request-json-version/
Upvotes: 5
Reputation: 251
JSONBuilder is an option like @SiKing says.
A very simple solution for this is adding to differents templates to your project with the format of every Request.
CaseTemplate.json ->
{ "display_name" : "${display_name}"}
IdentityTemplate.json ->
{
"display_name" : "Sample Case",
"case_id" : "${case_id}",
"type" : "${display_name}"
}
Then before every request test step, in a property transfer you can set the Request Property of a request test step with the content of one of this 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 correctly defined this properties in the interface of the rest request.
Upvotes: 0