regurgitator is a lightweight, modular, extendable java framework that you configure to “regurgitate” canned or clever responses to incoming requests; useful for quickly mocking or prototyping services without writing any code.
it provides a series of executable steps
and constructs
that you can combine / configure to apply simple or complex logic (as required) to a request message
that comes in, including generating and returning a response. you can even create your own steps and constructs, for whatever it doesn’t do out of the box.
it can be configured using xml
, json
or yml
files (or extended to use any other document format), allowing mocked logic to be created without writing any code - simply configure the behaviour you want!
it can work with http
to mock/stub http services, can work with mq
to mock jms services, or can be embedded within any other request / response mechanism.
it can work with jetty
to package configurations as containerized deployables, that you can stand up alongside your own, allowing you to test interactions between components that may not exist yet.
it is separated out into modules, so you only have to include the parts you need into your project, then configure it to do what you want, deploy it and go!
click on the highlighted terms
above to learn more, or see the reference projects here.
NEW you can now generate regurgitator configuration from an open api / swagger file. see here
the main modules are as follows:
each of the above has an accompanying module for each document type from which it can be configured, e.g.
below is an example pom.xml for a maven project that includes regurgitator:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my.group.id</groupId>
<artifactId>my-artifact</artifactId>
<version>0.0.1</version>
<name>My Regurgitator Example</name>
<dependencies>
<dependency>
<groupId>uk.emarte.regurgitator</groupId>
<artifactId>regurgitator-core</artifactId>
<version>0.1.3</version>
</dependency>
</dependencies>
</project>
include details for other build frameworks can be found here : mvnrepository
below is an example xml configuration file for regurgitator:
<?xml version="1.0" encoding="UTF-8"?>
<rg:regurgitator-configuration xmlns:rg="http://core.regurgitator.emarte.uk" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://core.regurgitator.emarte.uk regurgitatorCore.xsd" id="rock-paper-scissors">
<rg:decision id="determine-result">
<rg:steps>
<rg:create-response id="draw" value="a draw"/>
<rg:create-response id="player-win" value="player wins"/>
<rg:create-response id="computer-wins" value="computer wins"/>
</rg:steps>
<rg:rules default-step="computer-wins">
<rg:rule id="is-draw" step="draw">
<rg:condition id="player-got-same-as-computer" source="player-choice" equals-param="computer-choice"/>
</rg:rule>
<rg:rule id="rock-beats-paper" step="player-win">
<rg:condition id="player-rock" source="player-choice" equals="rock"/>
<rg:condition id="comp-scissors" source="computer-choice" equals="scissors"/>
</rg:rule>
<rg:rule id="paper-beats-rock" step="player-win">
<rg:condition id="player-paper" source="player-choice" equals="paper"/>
<rg:condition id="comp-rock" source="computer-choice" equals="rock"/>
</rg:rule>
<rg:rule id="scissors-beats-paper" step="player-win">
<rg:condition id="player-scissors" source="player-choice" equals="scissors"/>
<rg:condition id="comp-paper" source="computer-choice" equals="paper"/>
</rg:rule>
</rg:rules>
</rg:decision>
</rg:regurgitator-configuration>
the above example implements the rules of the well-known game - rock-paper-scissors
below is example code for loading a configuration file, creating a regurgitator instance, and processing a message:
import uk.emarte.regurgitator.core.*;
public class MyRegurgitatorExample {
public static void main(String[] args) throws RegurgitatorException {
Step rootStep = ConfigurationFile.loadFile("classpath:/rock-paper-scissors.xml");
Regurgitator regurgitator = new Regurgitator("my-regurgitator", rootStep);
ResponseCallBack callBack = (message,response) -> System.out.println(response);
Message message = new Message(callBack);
message.getParameters().setValue("player-choice", "paper");
message.getParameters().setValue("computer-choice", "rock");
regurgitator.processMessage(message);
}
}
by running the above (with the configuration above), this example executes a game of rock-paper-scissors, with the outcome being - "player wins"
the above shows programmatic use of regurgitator-core. regurgitator can do more by operating over http
or jms
, with or without writing code - see web, jetty, mq, or follow links below to some reference projects
reference projects for using regurgitator (over http) can be found below: