Package io.mats3.test.junit
Class Rule_MatsGeneric<Z>
java.lang.Object
io.mats3.test.abstractunit.AbstractMatsTest<Z>
io.mats3.test.junit.Rule_MatsGeneric<Z>
- Type Parameters:
Z
- The type definition for theMatsSerializer
employed. This defines the type which STOs and DTOs are serialized into. When employing JSON for the "outer" serialization of MatsTrace, it does not make that much sense to use a binary (Z=byte[]) "inner" representation of the DTOs and STOs, because JSON is terrible at serializing byte arrays.
- All Implemented Interfaces:
org.junit.rules.TestRule
Similar to
Rule_Mats
, provides a full Mats harness for unit testing by creating MatsFactory
utilizing an in-vm Active MQ broker. The difference between the two is that this Rule is open to the
usage of more customized MatsSerializer
s.
Rule_MatsGeneric
shall be considered a ClassRule
and thus annotated as such, being a
ClassRule
also means that the instance field shall be static. Therefore to utilize
Rule_MatsGeneric
one should add it to a test class in this fashion:
public class YourTestClass { @ClassRule public static Rule_MatsGeneric<Z> mats = new Rule_MatsGeneric(new YourSerializer()) }This will ensure that Rule_MatsGeneric sets up the test harness correctly. However the factory needs to be cleaned in between tests to ensure that there are no endpoint collisions (One can only register a given endpointId once per MatsFactory), thus one should also implement a method within the test class which is annotated with
After
and executes a call to AbstractMatsTest.cleanMatsFactories()
as such:
@After public void cleanFactory() { mats.removeAllEndpoints(); }
- See Also:
-
Field Summary
Fields inherited from class io.mats3.test.abstractunit.AbstractMatsTest
_createdMatsFactories, _dataSource, _matsFactory, _matsFuturizer, _matsInitiator, _matsSerializer, _matsTestBroker, _matsTestBrokerInterface, _matsTestLatch, log
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Rule_MatsGeneric
(MatsSerializer<Z> matsSerializer) protected
Rule_MatsGeneric
(MatsSerializer<Z> matsSerializer, DataSource dataSource) -
Method Summary
Modifier and TypeMethodDescriptionorg.junit.runners.model.Statement
apply
(org.junit.runners.model.Statement base, org.junit.runner.Description description) Note: Shamelessly inspired from: How to combine @Rule and @ClassRule in JUnit 4.12static <Z> Rule_MatsGeneric<Z>
create
(MatsSerializer<Z> matsSerializer) static <Z> Rule_MatsGeneric<Z>
createWithDb
(MatsSerializer<Z> matsSerializer) Methods inherited from class io.mats3.test.abstractunit.AbstractMatsTest
afterAll, beforeAll, cleanMatsFactories, cleanMatsFactory, createMatsFactory, getJmsConnectionFactory, getMatsFactory, getMatsFuturizer, getMatsInitiator, getMatsInterceptableMatsFactory, getMatsTestBrokerInterface, getMatsTestLatch, id
-
Constructor Details
-
Rule_MatsGeneric
-
Rule_MatsGeneric
-
-
Method Details
-
create
-
createWithDb
-
getDataSource
- Overrides:
getDataSource
in classAbstractMatsTest<Z>
- Returns:
- the DataSource if this Rule/Extension was created with one, throws
IllegalStateException
otherwise.
-
apply
public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runner.Description description) Note: Shamelessly inspired from: How to combine @Rule and @ClassRule in JUnit 4.12- Specified by:
apply
in interfaceorg.junit.rules.TestRule
-