cancel
Showing results for 
Search instead for 
Did you mean: 

Tests with different payloads for same REST resource (endpoint)?

ChristianB
Contributor

Tests with different payloads for same REST resource (endpoint)?

Hi all,

 

Let's say I have a REST service that allows you to search for rail journeys - and that once you have selected them, you can book them. The endpoint is example.com/service/v1/book, and to create the booking, you use a POST.

 

Because in reality, when you get to the booking state, the request would require a lot of data, the details of the booking are send as JSON.

 

For simplicity's sake, let's assume the body just takes the journey legs at the moment:

 

{
    "journey" : {
        "type" : "return",
        "outgoing" : {
            "from" : "LON",
            "to" : "NCL"
        },
        "return" : {
            "from" : "NCL",
            "to" : "LON"
        }
    }
}

 

Now, for a one-way ticket, that bit would obviously look slightly different, yet the resource (or HTTP method) wouldn't change - it would still be POST example.com/service/v1/book:

 {
    "journey" : {
        "type" : "single",
        "outgoing" : {
            "from" : "LON",
            "to" : "NCL"
        }
    }
}

The service would have to deal with it slightly differently, though. So, we'd want to test both.

 

How would you structure that in SoapUI?

 

I thought you'd create the resource (with the POST method), then create two different test cases, "one-way" and "return".

 

What I'm not sure of is how I'd then be able to pass the different payloads in? And where they'd be defined...?

 

Any ideas?

 

Kind regards,

Christian

P.S.: I previously posted this on StackExchange: http://sqa.stackexchange.com/q/16368/6846

1 REPLY 1
nmrao
Community Hero

Re: Tests with different payloads for same REST resource (endpoint)?

IMO, you should use the data driven approach for the same.

It is possible to achieve data driven approach with Open Source edition as well.

All you need is a test case with following steps -
a. groovy script step
b. rest step
Groovy script will have -
- a groovy script that reads a data file which consists of test case in each row.
- typically a row (test case) contains different input data in column wise. In this case particularly, one of the column can be either request (as that is variable in each test) or keep request in a file and put that file path as column data.
- based on the above, you will be able to read the request, and set/update it as request(pay load) for the rest step.
- run the rest step from groovy itself
- loop the above till all the rows are processed.



Regards,
Rao.
New Here?
Join us and watch the welcome video:
Announcements