Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SoapUI - REST Mocking with Query Parameter

I have several mocks with responses. But for some of them I want to create response based on additional query parameter. For example: I have mock for REST request such as "GET /order/item" and it works fine. But I tried to create mock for "GET /order/item?status=queued" and created response for it, but I get the same response as for "GET /order/item" when I test it out.

Is it possible to create REST Mock with Query in SoapUI Pro (5.1.2)?

Thanks for answers in advance.

like image 635
Di Grey Avatar asked Apr 09 '15 15:04

Di Grey


2 Answers

You have to add script dispatch to your mock action GET /order/item as it is shown on below picture: enter image description here Additionally, You have to define two MockResponse for above mock action:

  • queuedItem
  • item

Then the script will dispatch to queuedItem if http parameter status = queued

like image 168
snieguu Avatar answered Oct 16 '22 10:10

snieguu


if("queued".equals(mockRequest.getHttpRequest().getParameter("status"))) {
  log.info("queued");
  mockRequest.getHttpResponse().getWriter().write("queued");
} else {
  log.info("nope");
  mockRequest.getHttpResponse().getWriter().write("nope");  
}
like image 25
William Avatar answered Oct 16 '22 09:10

William