Package io.mats3.test.abstractunit
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
Common base class which consolidates the common logic utilized by both Rule_MatsEndpoint and Extension_MatsEndpoint.
- mats-test-junit
- mats-test-jupiter
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 Summary
FieldsModifier and TypeFieldDescriptionprotected MatsFactory
protected MatsEndpoint.ProcessSingleLambda<R,
I> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Base constructor forAbstractMatsTestEndpoint
, takes all values needed to setup the test endpoint. -
Method Summary
Modifier and TypeMethodDescriptionvoid
after()
Shutdown and remove the endpoint from theMatsFactory
after test and remove reference to endpoint from field.void
before()
Registers aMatsEndpoint
with the providedMatsFactory
, notice that theMatsFactory
is not set or provided directly through this class through the use of the constructor or a method.protected String
idThis()
abstract AbstractMatsTestEndpoint<R,
I> setMatsFactory
(MatsFactory matsFactory) Set theMatsFactory
of this class_matsFactory
.abstract AbstractMatsTestEndpoint<R,
I> setProcessLambda
(MatsEndpoint.ProcessSingleLambda<R, I> processLambda) Specify the processing lambda to be executed by the endpoint aka the endpoint logic.void
Verifies that this endpoint has not been invoked.Blocks and waits for the endpoint to be invoked, then returns the incoming message DTO of the type (I
).waitForRequest
(long millisToWait) Blocks and waits for the endpoint to be invoked, then returns the incoming message DTO of the type (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
).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
).
-
Field Details
-
_matsFactory
-
_processLambda
-
-
Constructor Details
-
AbstractMatsTestEndpoint
protected AbstractMatsTestEndpoint(String endpointId, Class<R> replyMsgClass, Class<I> incomingMsgClass) Base constructor forAbstractMatsTestEndpoint
, 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
Set theMatsFactory
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
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
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
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
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
-
before
public void before()Registers aMatsEndpoint
with the providedMatsFactory
, notice that theMatsFactory
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 aMatsFactory.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 theMatsFactory
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
-