🎄 Happy Holidays! 🥳
Most of Solace is closed December 24–January 1 so our employees can spend time with their families. We will re-open Thursday, January 2, 2024. Please expect slower response times during this period and open a support ticket for anything needing immediate assistance.
Happy Holidays!
Please note: most of Solace is closed December 25–January 2, and will re-open Tuesday, January 3, 2023.
Integration/Functional Testing with JUnit and Solace
When developing event driven Java services for Solace PubSub+, at some stage you want to move from unit testing Java code to testing services against a broker.
This repository demonstrates a base class for JUnit tests that launches a new PubSub+ instance in docker for use in tests.
It utilises testcontainers, manages the container life cycle manually as there is no testcontainers wrapper (yet) for PubSub+ and follows the singleton container pattern.
Port Mapping and Ports Exposed by Container
When the container is created the mapped ports are provided. This tells testcontainers which ports it shall expose for the container. testcontainers exposes random ports and maps these to the internal ports of the container.
For example - the base class maps port 55555 (SMF plain). This may be exposed as any port. The base class logs the SMF port used and output will look similar to this:
INFO: Started Solace PubSub+ Docker Container, available on host [localhost], SMF port [32872]
So an SMF client needs to connect on port 32872
.
Base class - AbstractPubSubPlusTestCase
This class starts the docker container. It logs a message when the container before and after start up.
It exposes many of the plain services such as SMF, REST/HTTP, MQTT/TCP. The ports used by the container can be obtained from the class with getXxxxx
methods.
The class also provides getAdminUser
and getAdminPassword
methods so SEMP v2 calls can be sent to configure the broker.
Example test - SolaceIntegrationTest
This is an example unit test, extends the AbstractPubSubPlusTestCase
class.
It includes some test cases to demo how the base class can be used:
- Publish message using SMF
- Publish and subscribe to message using SMF
- Publish using REST/HTTP and subscribe using SMF
- Obtain a. list of message vpns form the broker using SEMPv2/HTTP
Comments
-
At the same time I put my original version of this together spierepf (Peter-Frank Spierenburg) created an example using JUnit 5, check it out here:
https://github.com/spierepf/solace-junit5-test1