Package io.mats3.test.junit
Class Rule_Mats
- All Implemented Interfaces:
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() } }
- 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_Mats
(MatsSerializer<String> matsSerializer) protected
Rule_Mats
(MatsSerializer<String> 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 Rule_Mats
create()
Creates aRule_Mats
utilizing theMats default serializer
static Rule_Mats
create
(MatsSerializer<String> matsSerializer) Creates aRule_Mats
utilizing the user providedMatsSerializer
which serializes to the type of String.static Rule_Mats
static Rule_Mats
createWithDb
(MatsSerializer<String> 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_Mats
-
Rule_Mats
-
-
Method Details
-
create
Creates aRule_Mats
utilizing theMats default serializer
-
create
Creates aRule_Mats
utilizing the user providedMatsSerializer
which serializes to the type of String. -
createWithDb
-
createWithDb
-
getDataSource
- Overrides:
getDataSource
in classAbstractMatsTest<String>
- 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
-