If you like this project, please give it a star
- TCP mocking support, with async messages sent (i.e: allows sending welcome messages which are not supported by mountebank).
- Load mocking specification from tcpdump
.jsondump files and provides a reduced
.yamlformat for easy versioning.
- Allows to easily run the mock embedded in Java projects for easy testing
- Allows both mocking servers and clients.
Take into consideration that this tool is very simple, and only replays TCP traffic that has previously been recorded, so if user (or server) interacts with the tool in unexpected ways, then the mock will not answer until next expected packet is received. For more complex scenarios consider using one of previously mentioned tools.
This tool (as previously listed ones) is particularly useful to implement integration tests without the hassle of flaky connections, or complex environment setup or restrictions (VPN, quotas, etc).
The general use case for the tool takes following steps:
User captures traffic with tcpdump (with something like
tcpdump port 23 -w ~/traffic.pcap) or Wireshark between a client application and a service.
If traffic has been captured with Wireshark then store the captured traffic, filtering with proper condition for service port, in a
.jsonfile (File -> Export Packet Dissections -> As JSON...)
At this point user might follow three potential courses:
Start Wiresham in standalone mode with stored
.jsonand connect to it with the client application to reproduce previously stored traffic.
java -jar wiresham-standalone.jar -p 2324 -a 0.0.0.0 wireshark-dump.json
Latest version of wiresham-standalone.jar can be downloaded from maven central.
A similar example for a tcpdump traffic:
java -jar wiresham-standalone.jar -p 2324 -a 0.0.0.0 traffic.pcap
java -jar wiresham-standalone.jar -hto get usage instructions and help.
Same as previous one but start Wiresham in standalong mode to emulate a client application (instead of a service application):
java -jar wiresham-standalone.jar -t 0.0.0.0:23 -a 0.0.0.0 wireshark-dump.json
Note that the only difference with previous example is the use of
-tto specify target server address instead of the
-poption to specify the local port.
Convert the tcpdump or Wireshark dump to a reduced
.yamlfile (an example file can be found in simple.yaml), optionally manually tune it (response times or binary packets), add it to the project repository and implement tests using VirtualTcpService class or VirtualTcpClient class.
To convert a script run something like
java -jar wiresham-standalone.jar -d reduced-dump.yml -a 0.0.0.0 wireshark-dump.json.
To add Wiresham as dependency in maven project include in
<dependency> <groupId>us.abstracta</groupId> <artifactId>wiresham</artifactId> <version>0.1</version> </dependency>
Check what is the latest version in releases
Then just run
mvn clean install and the library (and standalone version) will be built and installed in the local maven repository.
To release the project, define the version to be released by checking included changes since last release and following semantic versioning.
Then, create a release (including
v as prefix of the version, e.g.
v0.1), this will trigger a GitHub Actions workflow which will publish the jars to maven central repository (and make it general available to be used as maven dependency projects) in around 10 mins and can be found in maven central search after up to 2 hours.