Embedded JMS JUnit4 @Rule

Library that provides JUnit extensions setting up an embedded JMS broker (ActiveMQ) for testing. For JUnit 4 it provides a @Rule, while for JUnit 5 Jupiter it provides an extension that may be enabled by either the @ExtendWith or @RegisterExtension annotations provided by Jupiter

License

License

Categories

Categories

JUnit Unit Testing
GroupId

GroupId

org.zapodot
ArtifactId

ArtifactId

embedded-jms-junit
Last Version

Last Version

0.2
Release Date

Release Date

Type

Type

jar
Description

Description

Embedded JMS JUnit4 @Rule
Library that provides JUnit extensions setting up an embedded JMS broker (ActiveMQ) for testing. For JUnit 4 it provides a @Rule, while for JUnit 5 Jupiter it provides an extension that may be enabled by either the @ExtendWith or @RegisterExtension annotations provided by Jupiter

Download embedded-jms-junit

How to add to project

<!-- https://jarcasting.com/artifacts/org.zapodot/embedded-jms-junit/ -->
<dependency>
    <groupId>org.zapodot</groupId>
    <artifactId>embedded-jms-junit</artifactId>
    <version>0.2</version>
</dependency>
// https://jarcasting.com/artifacts/org.zapodot/embedded-jms-junit/
implementation 'org.zapodot:embedded-jms-junit:0.2'
// https://jarcasting.com/artifacts/org.zapodot/embedded-jms-junit/
implementation ("org.zapodot:embedded-jms-junit:0.2")
'org.zapodot:embedded-jms-junit:jar:0.2'
<dependency org="org.zapodot" name="embedded-jms-junit" rev="0.2">
  <artifact name="embedded-jms-junit" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.zapodot', module='embedded-jms-junit', version='0.2')
)
libraryDependencies += "org.zapodot" % "embedded-jms-junit" % "0.2"
[org.zapodot/embedded-jms-junit "0.2"]

Dependencies

compile (5)

Group / Artifact Type Version
org.zapodot : embedded-jms-core jar 0.2
org.slf4j : slf4j-api jar 1.7.25
junit : junit jar 4.12
org.apache.activemq : activemq-broker jar 5.15.6
com.google.guava : guava jar 26.0-jre

test (6)

Group / Artifact Type Version
org.junit.vintage : junit-vintage-engine jar 5.3.1
org.slf4j : jcl-over-slf4j jar 1.7.25
org.slf4j : slf4j-simple jar 1.7.25
org.springframework : spring-jms jar 4.3.10.RELEASE
org.apache.camel : camel-test jar 2.22.1
org.apache.activemq : activemq-camel jar 5.15.6

Project Modules

There are no modules declared in this project.

embedded-jms-junit

Build Status Maven Central Apache V2 License Libraries.io for GitHub Coverage Status DepShield Badge

JUnit extension that provides a ActiveMQ Embedded in-memory JMS Broker. It should be compatible with all the usual JMS integration tools such as Apache Camel and Spring JMS Template. Inspired by the Embedded DB JUnit Rule project.

Why?

  • because you want to test your JMS integration code without being dependent on a running external JMS Broker
  • setting up the broker manually for all your tests requires a lot of boilerplate code
  • I found myself repeating myself and decided that creating this library would make my life easier :-)

Status

This library is distributed through the Sonatype OSS repo and should thus be widely available. Java 8 or higher is required. Feedback is more than welcome. Feel free to create issues if you find bugs or have feature requests for future releases :-)

Changelog

  • version 0.2: rewritten core and added support for JUnit 5 Jupiter
  • version 0.1: initial release

Usage

JUnit 5 (v. 0.2+)

More information on JMS support is found in the project WIKI

Add dependency

<dependency>
    <groupId>org.zapodot</groupId>
    <artifactId>embedded-jms-junit5</artifactId>
    <version>0.2</version>
    <scope>test</scope>
</dependency>

Use ExtendWith to enable the extension and inject the connection factory using @EmbeddedJms

@ExtendWith(EmbeddedJmsBroker.class)
class EmbeddedJmsBrokerRequestReplySpringTest {

    private static final String TEST_MESSAGE = "Test message";

    private static final String DESTINATION = "queue:destination";

    /**
    *  The type of property must be either ConnectionFactory, ActiveMQFactory or URI.
    *  If it is a URI to the broker is injected
    */
    @EmbeddedJms 
    private ConnectionFactory connectionFactory;

    @DisplayName("My test")
    @Test
    void testJmsLogic() throws Exception {
       // make JMS magic
    }
    
    @DisplayName("parameterized test")
    @Test
    void connectionFactoryParameter(@EmbeddedJms ConnectionFactory connectionFactory) {
        // perform JMS magic
    }

}

JUnit 4

Add dependency

<dependency>
    <groupId>org.zapodot</groupId>
    <artifactId>embedded-jms-junit</artifactId>
    <version>0.2</version>
    <scope>test</scope>
</dependency>

Add to JUnit4 test

    @Rule
    public EmbeddedJmsRule embeddedJmsRule = EmbeddedJmsRule.builder().build();

    @Test
    public void jmsTest() throws Exception {
        final ConnectionFactory connectionFactory = embeddedJmsRule.connectionFactory();
        
        // work your JMS magic

    }

For more examples check the JUnit tests in this project

Versions

Version
0.2
0.1