Skip to content

Using with JUnit 5 Jupiter

Sondre Eikanger Kvalø edited this page Oct 11, 2018 · 1 revision

Add dependency

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

Use with default settings

The extension will inject fields or method parameters of type ConnectionFactory, ActiveMQConnection factory or URI.

@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 {
       // perform JMS magic
    }

    @DisplayName("supports parameter type javax.jms.ConnectionFactory")
    @Test
    void connectionFactoryParameter(@EmbeddedJms ConnectionFactory connectionFactory) {
        // perform JMS magic
    }

}

Providing configuration using the @BrokerConfig annotation

Configuration may be added on either class or method level.

@ExtendWith(EmbeddedJmsBroker.class)
@BrokerConfig(name = EmbeddedJmsBrokerWithConfigTest.STUFF_BROKER)
class EmbeddedJmsBrokerWithConfigTest {

    static final String STUFF_BROKER = "StuffBroker";

    private static final String PRETTY_BROKER = "PrettyBroker";

    @EmbeddedJms
    private URI uri;

    @DisplayName("class level")
    @Test
    void configuredUsingBrokerConfig() {
        ...

    @DisplayName("method level configuration which overrides class level")
    @BrokerConfig(name = PRETTY_BROKER)
    @Test
    void brokerConfigOverriddenOnMethod() {
        ...
    }
}

Default settings

By default the following settings will be used:

  • marshal: false
  • persistence: false
  • name: the name of the test method is used