use get as a template for post in RESTful server
Hello all,
I'm new to SOUPUI, and I'm using the free version of SOUPUI. I’m trying to write some test cases.
I spent all morning looking for this and I can't believe this has never been asked. I'm sure I'm using the wrong nomenclature to ask this and so my search is failing.
What I want to do is:
- make a GET request
[{
"id": "123",
"name": “abc”,
"encrypted": false,
“happy”: true
}]
- Modify one or two items in the JSON response
[{
"id": "123",
"name": “ghi”,
"encrypted": true,
“happy”: true
}]
- Send the JSON response to my server as a POST – thus modifying the record (123) on the server
If someone could point me to a simple example that would be great.
I see lots of examples on how to do a property transfer and such but nothing on reusing a response.
I might have to use Groovy to do this but it seems like SOAPUI can do it already.
Thanks in advance
Hi,
As simple as you expected? I thought you were surprised that it wasn't simpler to do in your first post! I am happy you are happy anyway! :-)
I notice you used JSONPath rather than JSON Slurper, which is fair enough, but I would say that JSON Slurper is a little neater e.g. no need to import and a little nicer syntax - would make the solution something like:
import groovy.json.JsonSlurper
def response = context.expand('${GetRecord#Response}')
slurper = new JsonSlurper().parseText(response)
slurper.name = 'abc123'
testRunner.testCase.testSteps["UpdateRecord"].setPropertyValue("Request", slurper)
(I have tested this now, whereas before I was guessing :-) )
Also instead of setting a context property, you have now decided to update the TestStep request property directly:
testRunner.testCase.testSteps["UpdateRecord"].setP
ropertyValue("Request", jsonString) quite nice though!
If you're happy to please can you mark the topic as solved so that others might benefit?
Thanks for sharing your solution back,
Cheers,
Rup