/
MockServer

MockServer



Introduction

MockServer is an open source tool to mock any system with REST interface. The tool is implemented in java, and REST APIs are provided to configure and query it. See more details at http://www.mock-server.com/.

Installation

Install MockServer docker on Robot VM

>sudo docker pull jamesdbloom/mockserver
>sudo docker run --name mockserver -d -p 1080:1080 jamesdbloom/mockserver



You can restart MockServer container or reset it anytime with the following commands:

ubuntu@onap-robot:~/mockserverclient$ sudo docker restart mockserver
ubuntu@onap-robot:~/mockserverclient$ curl -v -X PUT "http://localhost:1080/reset"

Configuration

You can set the expectations in MockServer with REST APIs, e.g.:

# DCI Overlay curl -v -X PUT "http://localhost:1080/expectation" -d '{     "httpRequest": {         "method": "POST",         "path": "/v2.0/l3-dci-connects"     },     "httpResponse": {         "statusCode": 201     },     "times" : {         "unlimited" : true     },     "timeToLive" : {         "unlimited" : true     } }'

Verification

Verify all requests received by MockServer with REST API. e.g.:

ubuntu@onap-robot:~/mockserverclient$ curl -X PUT "http://localhost:1080/retrieve?type=REQUESTS&format=JSON"

or a particular request filtered by url, e.g.:

ubuntu@onap-robot:~/mockserverclient$ curl -X PUT "http://localhost:1080/retrieve?type=REQUESTS&format=JSON" -d '{
    "path""/controller/v2/tokens"
}'

Also, you can tail the log file inside MockServer container:

ubuntu@onap-robot:~/mockserverclient$ sudo docker exec -it mockserver bash bash-4.4# tail -f mockserver.lo