Mock for RabbitMQ Java amqp-client.
Compatible with versions 4.0.0 to 5+ of com.rabbitmq:amqp-client
Compatible with versions 3.6.3 to 4.0.0 with the
com.github.fridujo.rabbitmq.mock.compatibility
package.
This project aims to emulate RabbitMQ behavior for test purposes, through com.rabbitmq.client.ConnectionFactory
with MockConnectionFactory
.
However today, you will have more robust results using a real RabbitMQ instance through the use of Testcontainers.
If Docker is not an acceptable option, you can still rely on RabbitMQ-mock.
Replace the use of com.rabbitmq.client.ConnectionFactory
by MockConnectionFactory
ConnectionFactory factory = new MockConnectionFactory();
try (Connection conn = factory.newConnection()) {
try (Channel channel = conn.createChannel()) {
GetResponse response = channel.basicGet(queueName, autoAck);
byte[] body = response.getBody();
long deliveryTag = response.getEnvelope().getDeliveryTag();
// Do what you need with the body
channel.basicAck(deliveryTag, false);
}
}
More details in integration-test
Change underlying RabbitMQ ConnectionFactory by MockConnectionFactory
@Configuration
@Import(AppConfiguration.class)
class TestConfiguration {
@Bean
ConnectionFactory connectionFactory() {
return new CachingConnectionFactory(new MockConnectionFactory());
}
}
More details in integration-test
Any contribution is greatly appreciated. Please check out the guide for more details.
Add the following dependency to your pom.xml
<dependency>
<groupId>com.github.fridujo</groupId>
<artifactId>rabbitmq-mock</artifactId>
<version>${rabbitmq-mock.version}</version>
<scope>test</scope>
</dependency>
Add the following dependency to your build.gradle
repositories {
mavenCentral()
}
// ...
dependencies {
// ...
testCompile('com.github.fridujo:rabbitmq-mock:$rabbitmqMockVersion')
// ...
}
You need [JDK-17(https://adoptium.net/temurin/releases/?version=17&package=jdk) to build RabbitMQ-Mock. The project can be built with Maven using the following command.
./mvnw install
Tests are split in:
mvn test
mvn integration-test
mvn org.pitest:pitest-maven:mutationCoverage
The master of the project pushes SNAPSHOTs in Sonatype's repo.
To use the latest master build add Sonatype OSS snapshot repository, for Maven:
<repositories>
...
<repository>
<id>sonatype-oss-spanshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
</repositories>
For Gradle:
repositories {
// ...
maven {
url "https://oss.sonatype.org/content/repositories/snapshots"
}
}