public class Rule_Mats extends AbstractMatsTest<java.lang.String> implements org.junit.rules.TestRule
ClassRule which provides a full Mats harness for unit testing by creating MatsFactory
utilizing an in-vm Active MQ broker, and optionally a TestH2DataSource for database tests.
Notice: If you are in a Spring-context, this is probably not what you are looking for, as the MatsFactory then
should reside as a bean in the Spring context. Look in the 'mats-spring-test' package for testing tools for Spring.
By default the rule will create a MatsSerializerJson which will be the serializer utilized
by the created MatsFactory. Should one want to use a different serializer which serializes to
the type of String then this can be specified using the method create(MatsSerializer). However
should one want to specify a serializer which serializes into anything other than String, then
Rule_MatsGeneric offers this possibility.
Rule_Mats 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_Mats one should add it to a test
class in this fashion:
public class YourTestClass {
@ClassRule
public static final Rule_Mats MATS = Rule_Mats.create() // Or provide your own serializer
}
To get a variant that has a TestH2DataSource contained, and the MatsFactory set up with transactional
handling of that, use the createWithDb() methods. In this case, you might want to clean the database before
each test method, which can be accomplished as such:
public class YourTestClass {
@ClassRule
public static Rule_Mats MATS = Rule_Mats.createWithDb() // Or provide your own serializer
@Before // Will clean the database before each test - if this is what you want.
public void cleanDatabase() {
MATS.getDataSource().cleanDatabase()
}
}
Rule_MatsGeneric_createdMatsFactories, _dataSource, _matsFactory, _matsFuturizer, _matsInitiator, _matsSerializer, _matsTestBroker, _matsTestBrokerInterface, _matsTestLatch, log| Modifier | Constructor and Description |
|---|---|
protected |
Rule_Mats(MatsSerializer<java.lang.String> matsSerializer) |
protected |
Rule_Mats(MatsSerializer<java.lang.String> 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 Rule_Mats |
create()
Creates a
Rule_Mats utilizing the Mats default serializer |
static Rule_Mats |
create(MatsSerializer<java.lang.String> matsSerializer)
Creates a
Rule_Mats utilizing the user provided MatsSerializer which serializes to the type of
String. |
static Rule_Mats |
createWithDb() |
static Rule_Mats |
createWithDb(MatsSerializer<java.lang.String> matsSerializer) |
TestH2DataSource |
getDataSource() |
afterAll, beforeAll, cleanMatsFactories, cleanMatsFactory, createMatsFactory, getJmsConnectionFactory, getMatsFactory, getMatsFuturizer, getMatsInitiator, getMatsInterceptableMatsFactory, getMatsTestBrokerInterface, getMatsTestLatch, idprotected Rule_Mats(MatsSerializer<java.lang.String> matsSerializer)
protected Rule_Mats(MatsSerializer<java.lang.String> matsSerializer, javax.sql.DataSource dataSource)
public static Rule_Mats create()
Rule_Mats utilizing the Mats default serializerpublic static Rule_Mats create(MatsSerializer<java.lang.String> matsSerializer)
Rule_Mats utilizing the user provided MatsSerializer which serializes to the type of
String.public static Rule_Mats createWithDb()
public static Rule_Mats createWithDb(MatsSerializer<java.lang.String> matsSerializer)
public TestH2DataSource getDataSource()
getDataSource in class AbstractMatsTest<java.lang.String>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