Class AbstractMatsTestEndpoint<R,I>

java.lang.Object
io.mats3.test.abstractunit.AbstractMatsTestEndpoint<R,I>
Type Parameters:
R - The reply class of the message generated by this endpoint. (Reply Class)
I - The incoming message class for this endpoint. (Request Class)
Direct Known Subclasses:
Extension_MatsEndpoint, Rule_MatsEndpoint

public abstract class AbstractMatsTestEndpoint<R,I> extends Object
Common base class which consolidates the common logic utilized by both Rule_MatsEndpoint and Extension_MatsEndpoint.
  • mats-test-junit
  • mats-test-jupiter
Set's up a MatsEndpoint which processor can be modified on the fly. Also provides utility methods to extract incoming requests and verify that endpoint har or hasn't been invoked.
  • Field Details

  • Constructor Details

    • AbstractMatsTestEndpoint

      protected AbstractMatsTestEndpoint(String endpointId, Class<R> replyMsgClass, Class<I> incomingMsgClass)
      Base constructor for AbstractMatsTestEndpoint, takes all values needed to setup the test endpoint.
      Parameters:
      endpointId - Identifier of the endpoint being created.
      replyMsgClass - Class of the reply message.
      incomingMsgClass - Class of the incoming message. (Request)
  • Method Details

    • setMatsFactory

      public abstract AbstractMatsTestEndpoint<R,I> setMatsFactory(MatsFactory matsFactory)
      Set the MatsFactory of this class _matsFactory. Shall be implemented by the extending class.
      Parameters:
      matsFactory - instance to store internally.
      Returns:
      this for chaining.
    • setProcessLambda

      public abstract AbstractMatsTestEndpoint<R,I> setProcessLambda(MatsEndpoint.ProcessSingleLambda<R,I> processLambda)
      Specify the processing lambda to be executed by the endpoint aka the endpoint logic. This is typically invoked either as part of the directly inside a test method to setup the behavior for that specific test or once through the initial setup when creating the test endpoint.
      Parameters:
      processLambda - which the endpoint should execute on an incoming request.
    • waitForRequest

      public I waitForRequest()
      Blocks and waits for the endpoint to be invoked, then returns the incoming message DTO of the type (I). Will use a default timout value of 30 seconds.
      Returns:
      the first incoming message it encounters after calling this method.
    • waitForRequest

      public I waitForRequest(long millisToWait)
      Blocks and waits for the endpoint to be invoked, then returns the incoming message DTO of the type (I).
      Parameters:
      millisToWait - time to wait before timing out.
      Returns:
      the first incoming message it encounters after calling this method.
    • waitForRequests

      public List<I> waitForRequests(int expectedNumberOfRequests)
      Blocks and waits for the endpoint to be invoked x number of times, then returns the x number of corresponding incoming message DTO's of the type (I). Will utilize a default timeout value of 30 seconds.
      Parameters:
      expectedNumberOfRequests - the number of requests before unblocking and returning the received objects.
      Returns:
      the x number of incoming message it encounters after calling this method as a List<I>.
    • waitForRequests

      public List<I> waitForRequests(int expectedNumberOfRequests, long millisToWait)
      Blocks and waits for the endpoint to be invoked x number of times, then returns the x number of corresponding incoming message DTO's of the type (I).
      Parameters:
      expectedNumberOfRequests - the number of requests before unblocking and returning the received objects.
      millisToWait - time to wait before timing out.
      Returns:
      the x number of incoming message it encounters after calling this method as a List<I>.
    • verifyNotInvoked

      public void verifyNotInvoked()
      Verifies that this endpoint has not been invoked. This can be useful in scenarios where an endpoint has multiple routes x,y and z. For example, given request a, the request should be processed and forwarded to y endpoint and this endpoint should not be invoked.
      Throws:
      io.mats3.test.abstractunit.AbstractMatsTestEndpoint.UnexpectedMatsTestEndpointInvocationError - exception thrown if the endpoint has been invoked.
    • idThis

      protected String idThis()
    • before

      public void before()
      Registers a MatsEndpoint with the provided MatsFactory, notice that the MatsFactory is not set or provided directly through this class through the use of the constructor or a method. It is up to the extending class to provide this factory.

      The created endpoint is created as a MatsFactory.staged(java.lang.String, java.lang.Class<R>, java.lang.Class<S>) endpoint, the reason behind this is that a staged endpoint does not require a return unlike a MatsFactory.single(java.lang.String, java.lang.Class<R>, java.lang.Class<I>, io.mats3.MatsEndpoint.ProcessSingleLambda<R, I>).

      This method should be called as a result of the following life cycle events for either JUnit or Jupiter:

      • Before - JUnit - Rule
      • BeforeEachCallback - Jupiter
    • after

      public void after()
      Shutdown and remove the endpoint from the MatsFactory after test and remove reference to endpoint from field.

      This method should be called as a result of the following life cycle events for either JUnit or Jupiter:

      • After - JUnit - Rule
      • AfterEachCallback - Jupiter