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 io.mats3.test.abstractunit.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 MatsSerializers.
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| Modifier | Constructor and Description |
|---|---|
protected |
Rule_MatsGeneric(io.mats3.serial.MatsSerializer<Z> matsSerializer) |
protected |
Rule_MatsGeneric(io.mats3.serial.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(io.mats3.serial.MatsSerializer<Z> matsSerializer) |
static <Z> Rule_MatsGeneric<Z> |
createWithDb(io.mats3.serial.MatsSerializer<Z> matsSerializer) |
io.mats3.test.TestH2DataSource |
getDataSource() |
afterAll, beforeAll, cleanMatsFactories, cleanMatsFactory, createMatsFactory, getJmsConnectionFactory, getMatsFactory, getMatsFuturizer, getMatsInitiator, getMatsInterceptableMatsFactory, getMatsTestBrokerInterface, getMatsTestLatch, idprotected Rule_MatsGeneric(io.mats3.serial.MatsSerializer<Z> matsSerializer)
protected Rule_MatsGeneric(io.mats3.serial.MatsSerializer<Z> matsSerializer, javax.sql.DataSource dataSource)
public static <Z> Rule_MatsGeneric<Z> create(io.mats3.serial.MatsSerializer<Z> matsSerializer)
public static <Z> Rule_MatsGeneric<Z> createWithDb(io.mats3.serial.MatsSerializer<Z> matsSerializer)
public io.mats3.test.TestH2DataSource getDataSource()
getDataSource in class io.mats3.test.abstractunit.AbstractMatsTest<Z>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