-
Notifications
You must be signed in to change notification settings - Fork 2
Single Rest Simulator Usage
This project is an HTTP REST simulator.
- take the pom.
-
Download zip/tar.gz file from here
-
in the etc/config.properties set the port of the simulator-manager. This is the port you will manage your simulators through. The default port is 5000. example: restSimulator.http.port = 5000
-
run \utils\startSimulator
-
create your first simulator First thing you need to do is to add a simulator on a specific port you want to simulate
{simulator-root} - this is the root of the simulator-management: /simulator/{port} example: http://10.9.34.56:5000/simulator/8888 (10.9.34.56:5000 is the host & port the simulator-manager runs on, and 8888 is the port you want to simulate)
###POST {simulator-root}
This call will add a new simulator.
Add Simulator example:
POST /simulator/8888 HTTP/1.1 Host: localhost:5000 Cache-Control: no-cache
Clear Simulator This call will remove all the simulator 'expected-responses', the simulator will remain alive - but empty
Clear Simulator example
PUT /simulator/8888 HTTP/1.1 Host: localhost:5000 Content-Type: text/plain Cache-Control: no-cache
clear
Add an expected behavior to Simulator
This call will add the simulator a response which he'll retrieve if he get's the expected request. The expected request and the response are in the body.
Add an expected behavior to Simulator - example
PUT /simulator/8888 HTTP/1.1 Host: localhost:5000 Content-Type: application/json Cache-Control: no-cache
{ "expectedMethod" : "GET", "expectedHeaders":{"Sync-Mode":"true","Content-Type":"application/json"}, "expectedQueryParams":{"metadata":["true","false","sometimes"],"blabla":["false"]}, "expectedBody":"", "expectedUrl":"/expected/url", "responseCode":200, "responseHeaders":{"My-Header":"My-Header-Val","Location":"www.google.com"}, "responseBody":"responseBodyStr", "latencyMs":999 }
In the example above we want that when the simulator gets a GET call to '/expected/url', with the expected headers, the expected query-params and an empty body, he will retrieve 200 with 'responseBodyStr' as the body, the simulator will retrieve the response after a latency of 999 milliseconds.
This call will delete the simulator from the simulator-manager
This call will retrieve the simulator with all his expected-request & response that where added to him.
{queue} - {simulator-root}/queue - this is the root of the simulator-management: /simulator/{port}
The queue is enabled by default, it can be disabled by setting the following configuration: restSimulator.queue.enable = false
The size of the queue is by default 100 (it'll save only the 100 last messages), this could by changed by the following configuration: restSimulator.queue.maxSize =
Path params: the body will be replaced with path params which match the regex by groups: {$1} first match {$2} second match etc.
Query params: the body will be replaced with query params which match the regex by param name: {@areYouSure} will be replaced by the value of the areYouSure param in the url.
Example:
Insert to the simulator:
PUT /simulator/8888 HTTP/1.1 Host: localhost:1414 Content-Type: application/json Cache-Control: no-cache
{ "expectedMethod" : "GET", \n "expectedHeaders":{"Sync-Mode":"true","Content-Type":"application/json"}, "expectedQueryParams":{"howAreYou":["(\w*)"],"areYouSure":["(\w*)"]}, "expectedBody":"", "expectedUrl":"pps/households/(\w*)/catalog/(\w*)", "responseCode":200, "responseHeaders":{"My-Header":"My-Header-Val","Location":"www.google.com"}, "responseBody":"household {$1} catalog-item {$2}. (hh={$1})\nI am {@howAreYou}. {@areYouSure}, I am sure", "latencyMs":0 }
Call the simulator:
will give you the response:
household 1234 catalog-item abcde. (hh=1234) I am Happy. Yes, I am sure