REST mocks implementation sample with SoapUI

Part of five-cents demo

This topic is part of the ‘contract’ system of the Five-cents demo :

Five cents demo general schema - backend - contract

GitHubThe source code is available on GitHub, under /backends/contract folder.

 

Build REST mocks with SOAPUi

Our only concern, for this part of the demo, is to build a quick and dirty contract system that responds to contract requests. A great full-featured mocking tool that can be used to mock full parts of systems is Microcks, and it will be the subject of a few blogs to come up. For now, we will just stick to simple SOAPUi mocks to fulfill our needs.

You will find the SOAPUi project with our mocks under https://github.com/lcailleteau/fivecents-microservices-demo/blob/master/backends/contract/soapui-mocks/contract-soapui-project.xml. Basically it just displays JSON responses to contracts request for a given client :

SOAPUi - contract mock.png

And that’s it !

We can launch the mock service outside SOAPUi program with the help of those commands :

export SOAPUI_HOME_FOLDER="/home/cailleteau/SmartBear/SoapUI-5.4.0"
export SOAPUI_PROJECT="/media/Donnees/Users/Laurent/blog/fivecents-microservices-demo/backends/contract/soapui-mocks/contract-soapui-project.xml"
fivecents-microservices-demo/backends/contract/launch-contracts-mocks.sh

It should display :

SOAPUI_HOME_FOLDER : /home/cailleteau/SmartBear/SoapUI-5.4.0
SOAPUI_PROJECT : /media/Donnees/Users/Laurent/blog/fivecents-microservices-demo/backends/contract/soapui-mocks/contract-soapui-project.xml
================================
=
= SOAPUI_HOME = /home/cailleteau/SmartBear/SoapUI-5.4.0
=
================================
SoapUI 5.4.0 MockService Runner
Configuring log4j from [/home/cailleteau/SmartBear/SoapUI-5.4.0/bin/soapui-log4j.xml]
17:11:10,683 INFO [DefaultSoapUICore] initialized soapui-settings from [/home/cailleteau/soapui-settings.xml]
17:11:11,237 INFO [PluginManager] 0 plugins loaded in 1 ms
17:11:11,237 INFO [DefaultSoapUICore] All plugins loaded
17:11:11,975 INFO [WsdlProject] Loaded project from [file:/media/Donnees/Users/Laurent/blog/fivecents-microservices-demo/backends/contract/soapui-mocks/contract-soapui-project.xml]
17:11:11,981 INFO [SoapUIMockServiceRunner] Running MockService [REST MockService] in project [contract]
17:11:11,981 INFO [SoapUIMockServiceRunner] Press any key to terminate
17:11:12,111 INFO [JettyMockEngine] Started mockService [REST MockService] on port [8080] at path [/]
17:11:12,111 INFO [SoapUIMockServiceRunner] MockService started on port 8080 at path [/]
17:11:12,111 INFO [SoapUIMockServiceRunner] Started 1 runner
Press any key to terminate...

We can try a request on the mock, to fetch all contracts of client with id 0 :

curl http://localhost:8080/0/contracts

And ckeck the result :

{
  "car-contracts": [
    {
      "id": 4870,
      "start-day": 28,
      "start-month": 11,
      "start-year": 2011,
      "model": "renault twingo"
    }
  ],
  "home-contracts": [
    {
      "id": 4871,
      "start-day": 28,
      "start-month": 11,
      "start-year": 2011}
  ]
}

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: