Package io.mats3.spring.test
package io.mats3.spring.test
Mats3 Spring-specific testing tools, for quickly firing up a test-harness using either JUnit or Jupiter
(JUnit 5) - read class doc of
MatsTestContext
and
MatsTestInfrastructureConfiguration
.-
ClassDescriptionOne-stop-shop for making simple Spring-based integration/unit tests of Mats endpoints (NOT utilizing SQL Connections), automatically importing the configuration .The reason for this obscure way to add the
MatsTestInfrastructureConfiguration
(as opposed to just point to it with "classes=..") is as follows: Spring's testing integration has this feature where any static inner @Configuration class of the test class is automatically loaded.Same asMatsTestContext
, but includes a H2 DataSource, as configured byMatsTestInfrastructureDbConfiguration
.The reason for this obscure way to add theMatsTestInfrastructureDbConfiguration
(as opposed to just point to it with "classes=..") is as follows: Spring's testing integration has this feature where any static inner @Configuration class of the test class is automatically loaded.Spring@Configuration
class that cooks up the simple test infrastructure, employing aMatsSerializer
from the Spring context if available, otherwise creates a defaultMatsSerializerJson
.Same asMatsTestInfrastructureConfiguration
, but includes a H2 DataSource, as configured byMatsTestInfrastructureDbConfiguration.MatsTestH2DataSourceConfiguration
, which uses theTestH2DataSource.createStandard()
convenience method.The only thing this annotation does, is to meta-annotate the test class with@ActiveProfiles(
.MatsProfiles.PROFILE_MATS_TEST
)Use this Test Execution Listener to autowire JUnit Rules and Jupiter Extensions, i.e.ThisTestExecutionListener
finds all fields in the test class instance which is annotated with JUnitRule
or JUnit 5 JupiterRegisterExtension
, and runsbeanFactory.autowireBean(fieldValue)
on them.A testing-orientedMatsFactory
-provider which utilizes theMatsTestBroker
for the produced MatsFactory to connect to - this is for the scenarios where you do NOT have your test load the entire application's Spring configuration, but instead "piece together" the relevant Spring@Components
containing test-relevant Mats endpoints and other beans from your application along with test-specific mocked-out endpoints: You will then probably not have the MatsFactory present in the Spring context.