Class SolaceMessaging

java.lang.Object
com.solace.connector.test.resources.resource.SolaceMessaging
All Implemented Interfaces:
org.junit.jupiter.api.extension.ExtensionContext.Store.CloseableResource

public class SolaceMessaging extends Object implements org.junit.jupiter.api.extension.ExtensionContext.Store.CloseableResource
A utility to either:
- generate traffic on a workflow in the `Solace -> Vendor` direction OR
- retrieve messages that were processed by a workflow in the `Vendor -> Solace` direction and assert for correctness

Currently, this utility assumes that the Solace input and output destinations are always Queues. This simplification is acceptable since the intent is not to test the Solace SCSt Binder. We can safely assume that the Solace SCSt Binder handles other destination types correctly. This means however, that Solace Bindings should bind to queues or proper subscriptions are in place.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Exception that can be thrown by message validators to indicate that a specific message should be excluded from the expected message count.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
  • Method Summary

    Modifier and Type
    Method
    Description
    List<com.solacesystems.jcsmp.BytesXMLMessage>
    consumeAll(int workflowIndex)
    Retrieve all messages that were processed by a workflow in the `Vendor -> Solace` direction.
    List<com.solacesystems.jcsmp.BytesXMLMessage>
    consumeAll(com.solacesystems.jcsmp.Destination destination)
    Consume all messages from a Solace queue.
    void
    consumeAndAssert(int numMessages, int workflowIndex, Consumer<com.solacesystems.jcsmp.BytesXMLMessage> messageValidator)
    Retrieve messages that were processed by a workflow in the `Vendor -> Solace` direction and perform validations on those messages.
    void
    consumeAndAssert(int numMessages, int workflowIndex, Consumer<com.solacesystems.jcsmp.BytesXMLMessage> messageValidator, Duration timeout)
    Retrieve messages that were processed by a workflow in the `Vendor -> Solace` direction and perform validations on those messages.
    void
    consumeAndAssert(int numMessages, com.solacesystems.jcsmp.Destination destination, Consumer<com.solacesystems.jcsmp.BytesXMLMessage> messageValidator)
    Retrieve messages from a Solace queue and validate for correctness.
    void
    consumeAndAssert(int numMessages, com.solacesystems.jcsmp.Destination destination, Consumer<com.solacesystems.jcsmp.BytesXMLMessage> messageValidator, Duration timeout)
    Retrieve messages from a Solace queue and validate for correctness.
    com.solacesystems.jcsmp.Destination
    getInputDestination(int workflowIdx)
    Gets the input destination configured for a specific workflow.
    com.solacesystems.jcsmp.Destination
    getOutputDestination(int workflowIdx)
    Gets the output destination configured for a specific workflow.
    produceAsync(int numMessages, int workflowIndex, Supplier<com.solacesystems.jcsmp.BytesXMLMessage> messageSupplier)
    Asynchronously publish messages to the Solace queue which is feeding a specific workflow.
    produceAsync(int numMessages, com.solacesystems.jcsmp.Destination destination, Supplier<com.solacesystems.jcsmp.BytesXMLMessage> messageSupplier)
    Asynchronously publish messages to a Solace queue.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • produceAsync

      public CompletableFuture<Void> produceAsync(int numMessages, int workflowIndex, Supplier<com.solacesystems.jcsmp.BytesXMLMessage> messageSupplier) throws com.solacesystems.jcsmp.JCSMPException
      Asynchronously publish messages to the Solace queue which is feeding a specific workflow.
      Use this method to generate traffic on a workflow in the `Solace -> Vendor` direction.
      This method returns immediately while messages are published on a different thread.
      This method must be used in combination with the @SolaceQueue resource.
      Parameters:
      numMessages - the number of messages to publish
      workflowIndex - the index of the workflow (must be between 0 and 19 inclusive)
      messageSupplier - a supplier providing the message to publish
      Returns:
      future for publishing that completes when all messages are published or fails if any publishing fails
      Throws:
      com.solacesystems.jcsmp.JCSMPException - if there is an error publishing messages to Solace
      IllegalStateException - if the input destination for the specified workflow hasn't been initialized
      IllegalArgumentException - if workflowIndex is not between 0 and 19 or numMessages is less than 1
    • produceAsync

      public CompletableFuture<Void> produceAsync(int numMessages, com.solacesystems.jcsmp.Destination destination, Supplier<com.solacesystems.jcsmp.BytesXMLMessage> messageSupplier) throws com.solacesystems.jcsmp.JCSMPException
      Asynchronously publish messages to a Solace queue.
      This method returns immediately while messages are published on a different thread.
      Parameters:
      numMessages - the number of messages to publish
      destination - the destination to publish messages to
      messageSupplier - a supplier providing the message to publish
      Returns:
      future for publishing that completes when all messages are published or fails if any publishing fails
      Throws:
      com.solacesystems.jcsmp.JCSMPException - if there is an error publishing messages to Solace
      IllegalArgumentException - if numMessages is not greater than zero or messageSupplier is null
    • consumeAndAssert

      public void consumeAndAssert(int numMessages, int workflowIndex, Consumer<com.solacesystems.jcsmp.BytesXMLMessage> messageValidator) throws com.solacesystems.jcsmp.JCSMPException
      Retrieve messages that were processed by a workflow in the `Vendor -> Solace` direction and perform validations on those messages. This method reads from the Solace queue which is the destination of the workflow's output binding. ExcludeMessageFromExpectedCountException can be thrown from the messageValidator to exclude a particular message from the expected message count.
      This method must be used in combination with the @SolaceQueue resource. This method uses a default timeout of 5 minutes.
      Parameters:
      numMessages - the number of messages to expect
      workflowIndex - the index of the workflow that processed the messages (must be between 0 and 19 inclusive)
      messageValidator - a validator which asserts that the received messages are as expected
      Throws:
      com.solacesystems.jcsmp.JCSMPException - if there is an error consuming messages from Solace
      IllegalStateException - if the output destination for the specified workflow hasn't been initialized
      IllegalArgumentException - if workflowIndex is not between 0 and 19 or numMessages is less than 1
      AssertionError - if the expected number of messages is not received within the timeout
    • consumeAndAssert

      public void consumeAndAssert(int numMessages, int workflowIndex, Consumer<com.solacesystems.jcsmp.BytesXMLMessage> messageValidator, Duration timeout) throws com.solacesystems.jcsmp.JCSMPException
      Retrieve messages that were processed by a workflow in the `Vendor -> Solace` direction and perform validations on those messages. This method reads from the Solace queue which is the destination of the workflow's output binding. ExcludeMessageFromExpectedCountException can be thrown from the messageValidator to exclude a particular message from the expected message count.
      This method must be used in combination with the @SolaceQueue resource.
      Parameters:
      numMessages - the number of messages to expect
      workflowIndex - the index of the workflow that processed the messages (must be between 0 and 19 inclusive)
      messageValidator - a validator which asserts that the received messages are as expected
      timeout - the duration to wait for all messages to be received
      Throws:
      com.solacesystems.jcsmp.JCSMPException - if there is an error consuming messages from Solace
      IllegalStateException - if the output destination for the specified workflow hasn't been initialized
      IllegalArgumentException - if workflowIndex is not between 0 and 19 or numMessages is less than 1
      AssertionError - if the expected number of messages is not received within the timeout
    • consumeAndAssert

      public void consumeAndAssert(int numMessages, com.solacesystems.jcsmp.Destination destination, Consumer<com.solacesystems.jcsmp.BytesXMLMessage> messageValidator) throws com.solacesystems.jcsmp.JCSMPException
      Retrieve messages from a Solace queue and validate for correctness. ExcludeMessageFromExpectedCountException can be thrown from the messageValidator to exclude a particular message from the expected message count. Default timeout is 5 minutes.
      Parameters:
      numMessages - the number of messages to expect
      destination - the queue to consume messages from
      messageValidator - a validator which asserts that the received messages are as expected
      Throws:
      com.solacesystems.jcsmp.JCSMPException - if there is an error consuming messages from Solace
      IllegalArgumentException - if numMessages is not greater than zero or messageValidator is null
      UnsupportedOperationException - if destination is not a Queue
      AssertionError - if the expected number of messages is not received within the timeout
    • consumeAndAssert

      public void consumeAndAssert(int numMessages, com.solacesystems.jcsmp.Destination destination, Consumer<com.solacesystems.jcsmp.BytesXMLMessage> messageValidator, Duration timeout) throws com.solacesystems.jcsmp.JCSMPException
      Retrieve messages from a Solace queue and validate for correctness. ExcludeMessageFromExpectedCountException can be thrown from the messageValidator to exclude a particular message from the expected message count.
      Parameters:
      numMessages - the number of messages to expect
      destination - the queue to consume messages from
      messageValidator - a validator which asserts that the received messages are as expected
      timeout - the duration to wait for all messages to be received
      Throws:
      com.solacesystems.jcsmp.JCSMPException - if there is an error consuming messages from Solace
      IllegalArgumentException - if numMessages is not greater than zero or messageValidator is null
      UnsupportedOperationException - if destination is not a Queue
      AssertionError - if the expected number of messages is not received within the timeout
    • consumeAll

      public List<com.solacesystems.jcsmp.BytesXMLMessage> consumeAll(int workflowIndex) throws com.solacesystems.jcsmp.JCSMPException
      Retrieve all messages that were processed by a workflow in the `Vendor -> Solace` direction. This method reads from the Solace queue which is the destination of the workflow's output binding.
      Parameters:
      workflowIndex - the index of the workflow that processed the messages (must be between 0 and 19 inclusive)
      Returns:
      a list of all messages consumed from the queue
      Throws:
      com.solacesystems.jcsmp.JCSMPException - if there is an error consuming messages from Solace
      IllegalStateException - if the output destination for the specified workflow hasn't been initialized
      IllegalArgumentException - if workflowIndex is not between 0 and 19
    • consumeAll

      public List<com.solacesystems.jcsmp.BytesXMLMessage> consumeAll(com.solacesystems.jcsmp.Destination destination) throws com.solacesystems.jcsmp.JCSMPException
      Consume all messages from a Solace queue.
      Parameters:
      destination - the queue to consume messages from
      Returns:
      a list of all messages consumed from the queue
      Throws:
      com.solacesystems.jcsmp.JCSMPException - if there is an error consuming messages from Solace
      UnsupportedOperationException - if destination is not a Queue
    • getInputDestination

      public com.solacesystems.jcsmp.Destination getInputDestination(int workflowIdx)
      Gets the input destination configured for a specific workflow.
      Parameters:
      workflowIdx - the index of the workflow
      Returns:
      the input destination for the specified workflow, or null if not set
    • getOutputDestination

      public com.solacesystems.jcsmp.Destination getOutputDestination(int workflowIdx)
      Gets the output destination configured for a specific workflow.
      Parameters:
      workflowIdx - the index of the workflow
      Returns:
      the output destination for the specified workflow, or null if not set