Package io.mats3.test.abstractunit
Class AbstractMatsTest<Z>
java.lang.Object
io.mats3.test.abstractunit.AbstractMatsTest<Z>
- Direct Known Subclasses:
Extension_Mats
,Extension_MatsGeneric
,Rule_Mats
,Rule_MatsGeneric
Base class containing common code for Rule_Mats and Extension_Mats located in the following modules:
- mats-test-junit
- mats-test-jupiter
MatsTestBroker
which is again utilized to
create the MatsFactory
which can be utilized to create unit tests which rely on testing functionality
utilizing MATS.
The setup and creation of these objects are located in the beforeAll()
method, this method should be called
through the use JUnit and Jupiters life
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected CopyOnWriteArrayList<MatsFactory>
protected DataSource
protected MatsInterceptableMatsFactory
protected MatsFuturizer
protected MatsInitiator
protected MatsSerializer<Z>
protected MatsTestBroker
protected MatsTestBrokerInterface
protected MatsTestLatch
protected static final org.slf4j.Logger
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractMatsTest
(MatsSerializer<Z> matsSerializer) protected
AbstractMatsTest
(MatsSerializer<Z> matsSerializer, DataSource dataSource) -
Method Summary
Modifier and TypeMethodDescriptionvoid
afterAll()
Tear down method, stopping allMatsFactory
created during a test setup and close the AMQ broker.void
Creates an in-vm ActiveMQ Broker which again is utilized to create aJmsMatsFactory
.void
Loops through all theMatsFactory
's contained in this Rule (default + any specifically created), and removes all endpoints from each of them, this ensures that all factories are "clean".void
Deprecated.You should probably NOT use this method, but instead thegetMatsFactory()
!.javax.jms.ConnectionFactory
protected String
-
Field Details
-
log
protected static final org.slf4j.Logger log -
_matsSerializer
-
_dataSource
-
_matsTestBroker
-
_matsFactory
-
_createdMatsFactories
-
_matsInitiator
-
_matsTestLatch
-
_matsFuturizer
-
_matsTestBrokerInterface
-
-
Constructor Details
-
AbstractMatsTest
-
AbstractMatsTest
-
-
Method Details
-
beforeAll
public void beforeAll()Creates an in-vm ActiveMQ Broker which again is utilized to create aJmsMatsFactory
.This method should be called as a result of the following life cycle events for either JUnit or Jupiter:
- BeforeClass - JUnit - static ClassRule
- BeforeAllCallback - Jupiter - static Extension
-
afterAll
public void afterAll()Tear down method, stopping allMatsFactory
created during a test setup and close the AMQ broker.This method should be called as a result of the following life cycle events for either JUnit or Jupiter:
- AfterClass - JUnit - static ClassRule
- AfterAllCallback - Jupiter - static Extension
-
getMatsInitiator
- Returns:
- the default
MatsInitiator
from this rule'sMatsFactory
.
-
getMatsTestLatch
- Returns:
- a singleton
MatsTestLatch
-
getMatsFuturizer
- Returns:
- a convenience singleton
MatsFuturizer
created with this rule'sMatsFactory
.
-
getMatsTestBrokerInterface
- Returns:
- a
MatsTestBrokerInterface
instance for getting DLQs (and hopefully other snacks at a later time).
-
getJmsConnectionFactory
public javax.jms.ConnectionFactory getJmsConnectionFactory()- Returns:
- the JMS ConnectionFactory that this JUnit Rule sets up.
-
getMatsFactory
- Returns:
- the
MatsFactory
that this JUnit Rule sets up.
-
getMatsInterceptableMatsFactory
- Returns:
- the
MatsInterceptableMatsFactory
that this JUnit Rule sets up - This should not be used unless testing the Interceptor API!
-
createMatsFactory
You should probably NOT use this method, but instead thegetMatsFactory()
!. This method is public for a single reason: If you need a new, separateMatsFactory
using the same JMS ConnectionFactory as the one provided bygetMatsFactory()
. The only currently known reason for this is if you want to register two endpoints with the same endpointId, and the only reason for this again is to testsubscriptionTerminators
.- Returns:
- a new, separate
MatsFactory
in addition to the one provided bygetMatsFactory()
.
-
getDataSource
- Returns:
- the DataSource if this Rule/Extension was created with one, throws
IllegalStateException
otherwise. - Throws:
IllegalStateException
- if this Rule/Extension wasn't created with a DataSource.
-
cleanMatsFactory
Deprecated.usecleanMatsFactories()
. -
cleanMatsFactories
public void cleanMatsFactories()Loops through all theMatsFactory
's contained in this Rule (default + any specifically created), and removes all endpoints from each of them, this ensures that all factories are "clean". You may want to utilize this if you have multiple tests in a class, and set up the Endpoints using a @Before type annotation in the test, as opposed to @BeforeClass. This because otherwise you will on the second test try to create the endpoints one more time, and they will already exist, thus you'll get an Exception from the MatsFactory. Another scenario is that you have a bunch of @Test methods, which inside the test sets up an endpoint in the "Arrange" section. If you employ the same endpointId for each of those setups (that is, inside the @Test method itself), you will get "duplicate endpoint" (which is good, as your test would probably randomly fail anyhow). Thus, as the first statement of each test, before creating the endpoint, invoke this method. -
id
-
cleanMatsFactories()
.