Package io.mats3.test.jupiter
Class Extension_Mats
- java.lang.Object
-
- io.mats3.test.abstractunit.AbstractMatsTest
-
- io.mats3.test.jupiter.Extension_Mats
-
- All Implemented Interfaces:
org.junit.jupiter.api.extension.AfterAllCallback,org.junit.jupiter.api.extension.BeforeAllCallback,org.junit.jupiter.api.extension.Extension
public class Extension_Mats extends io.mats3.test.abstractunit.AbstractMatsTest implements org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.AfterAllCallbackProvides a full MATS harness for unit testing by creatingMatsFactoryutilizing an in-vm Active MQ broker, and optionally aTestH2DataSourcefor 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 theextensionwill create aMatsSerializerJsonwhich will be the serializer utilized by the createdMatsFactory. Should one want to use a different serializer then this can be specified using the methodcreate(MatsSerializer).Extension_Matsshall be annotated with@RegisterExtensionand the instance field shall be static for the Jupiter life cycle to pick up the extension at the correct time.Extension_Matscan be viewed in the same manner as one would view a ClassRule in JUnit4. Example:public class YourTestClass { @RegisterExtension public static final Extension_Mats MATS = Extension_Mats.createRule() }To get a variant that has aTestH2DataSourcecontained, and the MatsFactory set up with transactional handling of that, use thecreateWithDb()methods. In this case, you might want to clean the database before each test method, which can be accomplished as such:public class YourTestClass { @RegisterExtension public static final Extension_Mats MATS = Extension_Mats.createRule() @Before // Will clean the database before each test - if this is what you want. public void cleanDatabase() { MATS.getDataSource().cleanDatabase() } }
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedExtension_Mats(io.mats3.serial.MatsSerializer<?> matsSerializer)protectedExtension_Mats(io.mats3.serial.MatsSerializer<?> matsSerializer, javax.sql.DataSource dataSource)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterAll(org.junit.jupiter.api.extension.ExtensionContext context)Executed by Jupiter after all test methods have been executed.voidbeforeAll(org.junit.jupiter.api.extension.ExtensionContext context)Executed by Jupiter before any test method is executed.static Extension_Matscreate()Creates anExtension_Matsutilizing theMATS default serializerstatic Extension_Matscreate(io.mats3.serial.MatsSerializer<?> matsSerializer)Creates anExtension_Matsutilizing the user providedMatsSerializerwhich serializes to the type of String.static Extension_MatscreateWithDb()static Extension_MatscreateWithDb(io.mats3.serial.MatsSerializer<?> matsSerializer)static Extension_MatsgetExtension(org.junit.jupiter.api.extension.ExtensionContext extensionContext)Returns theExtension_Matsfrom the test context, provided that this has been initialized prior to calling this method.
-
-
-
Method Detail
-
create
public static Extension_Mats create()
Creates anExtension_Matsutilizing theMATS default serializer
-
create
public static Extension_Mats create(io.mats3.serial.MatsSerializer<?> matsSerializer)
Creates anExtension_Matsutilizing the user providedMatsSerializerwhich serializes to the type of String.
-
createWithDb
public static Extension_Mats createWithDb()
-
createWithDb
public static Extension_Mats createWithDb(io.mats3.serial.MatsSerializer<?> matsSerializer)
-
getExtension
public static Extension_Mats getExtension(org.junit.jupiter.api.extension.ExtensionContext extensionContext)
Returns theExtension_Matsfrom the test context, provided that this has been initialized prior to calling this method. This is intended for use by other extensions that rely on the presence of aExtension_Matsto function. TheExtension_Matsis not set in theExtensionContextuntil after thebeforeAll(ExtensionContext)has been called for an instance ofExtension_Mats.Note that if you crate multiple
Extension_Mats, then this will only provide the last created extension. In that case, you should instead provide the actual MatsFactory to each extension.- Parameters:
extensionContext- to getExtension_Matsfrom- Returns:
- the
Extension_Matsfrom the test context - Throws:
java.lang.IllegalStateException- if noExtension_Matsis found in the test context
-
beforeAll
public void beforeAll(org.junit.jupiter.api.extension.ExtensionContext context)
Executed by Jupiter before any test method is executed. (Once at the start of the class.)- Specified by:
beforeAllin interfaceorg.junit.jupiter.api.extension.BeforeAllCallback
-
afterAll
public void afterAll(org.junit.jupiter.api.extension.ExtensionContext context)
Executed by Jupiter after all test methods have been executed. (Once at the end of the class.)- Specified by:
afterAllin interfaceorg.junit.jupiter.api.extension.AfterAllCallback
-
-