14 years ago
How do I POST a Complex JSON request?
Is it possible to POST (as opposed to GET which appears as parameters in the URL) a complex JSON object using SoapUI?
I have Groovy scripts that builds a complex JSON object that I want to set on a TestStep.
// Inside my Groovy script, I have the following code:
def step2 = context.testCase.getTestStepByName("Step 2 -- POST - Reservation");
// Create a complex JSON object, for example, is is part of one...
// here is a small sample of a JSON object we need to POST
def jsonTextReadable = """\
{
"createBooking": {
"createBookingInput": {
"reservation": {
"departureDate": "2012-01-05T00:00:00.000Z",
"arrivalDate": "2012-01-08T00:00:00.000Z",
"hotelCode": "1234567",
"resGuestPaymentRoomStayMappings": {
"resGuestPaymentRoomStayMapping": [
{
"roomStay": "0",
"resGuest": "0",
"paymentType": "0"
}
]
}
}
}
}
}
""";
// But how do you set it as a object for the TestStep to POST?
step2.getProperty("THIS_WOULD_BE_A_URL_PARAM_NOT_A_JSON_OBJECT").value = jsonTextReadable;
The Http method on the test is set to "POST". Reading up on the types of REST parameters did not clarify this for me:
http://www.soapui.org/REST-Testing/unde ... eters.html
There are other approaches such as using groovyx library (link below), but groovyx is not included in the groovy-all-1.8.0.jar. For portability purposes, I don't want to add another library.
http://groovy.codehaus.org/HTTP+Builder
Please advise. We need to know this is doable in order to justify purchasing the Pro edition.
Thank you.
I have Groovy scripts that builds a complex JSON object that I want to set on a TestStep.
// Inside my Groovy script, I have the following code:
def step2 = context.testCase.getTestStepByName("Step 2 -- POST - Reservation");
// Create a complex JSON object, for example, is is part of one...
// here is a small sample of a JSON object we need to POST
def jsonTextReadable = """\
{
"createBooking": {
"createBookingInput": {
"reservation": {
"departureDate": "2012-01-05T00:00:00.000Z",
"arrivalDate": "2012-01-08T00:00:00.000Z",
"hotelCode": "1234567",
"resGuestPaymentRoomStayMappings": {
"resGuestPaymentRoomStayMapping": [
{
"roomStay": "0",
"resGuest": "0",
"paymentType": "0"
}
]
}
}
}
}
}
""";
// But how do you set it as a object for the TestStep to POST?
step2.getProperty("THIS_WOULD_BE_A_URL_PARAM_NOT_A_JSON_OBJECT").value = jsonTextReadable;
The Http method on the test is set to "POST". Reading up on the types of REST parameters did not clarify this for me:
http://www.soapui.org/REST-Testing/unde ... eters.html
There are other approaches such as using groovyx library (link below), but groovyx is not included in the groovy-all-1.8.0.jar. For portability purposes, I don't want to add another library.
http://groovy.codehaus.org/HTTP+Builder
Please advise. We need to know this is doable in order to justify purchasing the Pro edition.
Thank you.