Class PubSubPlusExtension

java.lang.Object
com.solace.connector.test.resources.PubSubPlusExtension
All Implemented Interfaces:
org.junit.jupiter.api.extension.Extension, org.junit.jupiter.api.extension.ParameterResolver, org.junit.jupiter.api.extension.TestInstantiationAwareExtension

public class PubSubPlusExtension extends Object implements org.junit.jupiter.api.extension.ParameterResolver

Junit 5 extension for Micro-Integration Testing

Overview

The PubSubPlusExtension simplifies writing integration tests for applications that interact with Solace PubSub+ event brokers. It provides automatic provisioning of PubSub+ resources (sessions, queues, etc.) for tests and manages their lifecycle according to JUnit 5 extension context principles. The extension can work with both containerized brokers (using TestContainers) and external PubSub+ brokers, allowing for flexible testing environments.

PubSub+ Resource Lifecycle

The lifecycle of resources (e.g. sessions and queues) created through this extension are bound to the earliest JUnit context that they were defined in.

e.g.:

  • if a resource was only defined as a parameter of a @Test method, then that resource's lifecycle is bound to the test, and will be cleaned up after the test completes.
  • If a resource was only defined as a parameter of a @BeforeAll method, then the resource's lifecycle is bound to the class, and will be cleaned up after the test class completes.
  • If you had the same resource defined as parameters of both @BeforeAll and @Test, then both methods will use the same resource, and its lifecycle would be bound to the test class (i.e. the earliest definition of the resource).

Note that the only exception to this is the PubSub+ event broker container. Which, if created, is bound to JUnit's root context. i.e. it will be cleaned up with the JVM.

Basic Usage:


 @ExtendWith(PubSubPlusExtension.class)
 public class Test {
  @Test
  void testMethod(@SolaceQueue(name = "input-0") Queue input0,
                  @SolaceQueue(name = "output-0") Queue output0,
                  SolaceMessaging solaceMessaging,
                  ConnectorArgsBuilder connectorArgsBuilder) {
                // Queues "input-0" and "output-0" are automatically created and are deleted after the test
                // solaceMessaging instance is ready to generate traffic or retrieve messages
            // connectorArgsBuilder has the properties needed to start a micro-integration application and can receive additional properties
        }
 }
 
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension

    org.junit.jupiter.api.extension.TestInstantiationAwareExtension.ExtensionContextScope
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension

    getTestInstantiationExtensionContextScope
  • Constructor Details

    • PubSubPlusExtension

      public PubSubPlusExtension()