Sunday, March 3, 2019

More embedding dependencies when testing in Spring Boot

Full Stack Software Development Blog

In my last blog I wrote about mocking dependencies when running tests. Since then I've added Apache's Qpid (https://qpid.apache.org/) to mock out RabbitMQ.

The following is from the top of the readme in my github repository for the PoC (see https://github.com/gpratte/spring-boot-acceptance-test-mocks)


A Spring Boot project that connects to various resources (database, mongo, rest calls, JMS messaging, Rabbit messaging, legacy). Mock the connections for acceptance testing.

Embedded servers

When running tests the server uses
  1. An embedded ActiveMQ server (to mock JMS)
  2. Wiremock to mock the REST calls
  3. An embedded H2 in-memory database
  4. An embedded Qpid server (to mock RabbitMQ)
Listen to JMS message flow...
  1. Receive a Todo JMS message
  2. Make a REST call (for no good reason)
  3. Persist the Todo in a relational database
The server is setup to
  1. Listen to the mailbox queue of an external JMS ActiveMQ server
  2. Makes a REST call to http://worldclockapi.com/api/json/utc/now
  3. Inserts into a Postgres database
REST POST to create a Todo flow...
  1. Expose a POST endpoint to create a Todo
  2. Persist the Todo in a relational database
  3. Send the Todo as JSON to RabbitMQ

The server is setup
  1. With a RestController with a PostMapping on /api/todos
  2. The controller calls a service which calls the repository to insert into a Postgres database
  3. The service also sends JSON to RabbitMQ

No comments:

Post a Comment