Z
- The type definition for the MatsSerializer
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.public class Rule_MatsGeneric<Z> extends AbstractMatsTest<Z> implements org.junit.rules.TestRule
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(); }
AbstractMatsTest
_createdMatsFactories, _dataSource, _matsFactory, _matsFuturizer, _matsInitiator, _matsSerializer, _matsTestBroker, _matsTestBrokerInterface, _matsTestLatch, log
Modifier | Constructor and Description |
---|---|
protected |
Rule_MatsGeneric(MatsSerializer<Z> matsSerializer) |
protected |
Rule_MatsGeneric(MatsSerializer<Z> matsSerializer,
javax.sql.DataSource dataSource) |
Modifier and Type | Method and Description |
---|---|
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
|
static <Z> Rule_MatsGeneric<Z> |
create(MatsSerializer<Z> matsSerializer) |
static <Z> Rule_MatsGeneric<Z> |
createWithDb(MatsSerializer<Z> matsSerializer) |
TestH2DataSource |
getDataSource() |
afterAll, beforeAll, cleanMatsFactories, cleanMatsFactory, createMatsFactory, getJmsConnectionFactory, getMatsFactory, getMatsFuturizer, getMatsInitiator, getMatsInterceptableMatsFactory, getMatsTestBrokerInterface, getMatsTestLatch, id
protected Rule_MatsGeneric(MatsSerializer<Z> matsSerializer)
protected Rule_MatsGeneric(MatsSerializer<Z> matsSerializer, javax.sql.DataSource dataSource)
public static <Z> Rule_MatsGeneric<Z> create(MatsSerializer<Z> matsSerializer)
public static <Z> Rule_MatsGeneric<Z> createWithDb(MatsSerializer<Z> matsSerializer)
public TestH2DataSource getDataSource()
getDataSource
in class AbstractMatsTest<Z>
IllegalStateException
otherwise.public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runner.Description description)
apply
in interface org.junit.rules.TestRule