Package io.mats3.spring.test
Class TestSpringMatsFactoryProvider
java.lang.Object
io.mats3.spring.test.TestSpringMatsFactoryProvider
A testing-oriented
MatsFactory
-provider which utilizes the MatsTestBroker
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. You can then use this class to get a "quick and dirty" MatsFactory (with an in-vm MQ Broker backing it) on
which your application's endpoints, and mocked-out endpoints in the test, can run.
If your requirements aren't all that exotic, you may get this indirectly invoked by using the
@MatsTestContext
annotation directly on the Test-class. If your requirements are slightly more
involved, check out the MatsTestInfrastructureConfiguration
and MatsTestInfrastructureDbConfiguration
Spring Configuration classes (loaded in a test with @ContextConfiguration
), which employs the
methods in this class.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic MatsFactory
createJmsTxOnlyTestMatsFactory
(int concurrency, MatsSerializer<?> matsSerializer) If you need aMatsFactory
that only handles the JMS transactions, this is your factory method - but if you DO make any database calls within any Mats endpoint lambda, you will now have no or poor transactional demarcation, usecreateSpringDataSourceTxTestMatsFactory(..)
instead.static MatsFactory
createJmsTxOnlyTestMatsFactory
(MatsSerializer<?> matsSerializer) Convenience variant ofcreateJmsTxOnlyTestMatsFactory(int, MatsSerializer)
where concurrency is 2, which should be adequate for most testing - unless you explicitly want to test concurrency.static MatsFactory
createSpringDataSourceTxTestMatsFactory
(int concurrency, DataSource sqlDataSource, MatsSerializer<?> matsSerializer) If you need aMatsFactory
employing Spring's DataSourceTransactionManager (which you probably do in a Spring environment utilizing SQL), this is your factory method.static MatsFactory
createSpringDataSourceTxTestMatsFactory
(int concurrency, org.springframework.transaction.PlatformTransactionManager platformTransactionManager, MatsSerializer<?> matsSerializer) If you need aMatsFactory
, but you need to make your ownPlatformTransactionManager
, this is your factory method - please note that the containedDataSource
should have been wrapped using the static methodJmsMatsTransactionManager_JmsAndSpringManagedSqlTx.wrapLazyConnectionDatasource(DataSource)
.static MatsFactory
createSpringDataSourceTxTestMatsFactory
(DataSource sqlDataSource, MatsSerializer<?> matsSerializer) Convenience variant ofcreateSpringDataSourceTxTestMatsFactory(int, DataSource, MatsSerializer)
where concurrency is 1, which should be adequate for most testing - unless you explicitly want to test concurrency.static MatsFactory
createSpringDataSourceTxTestMatsFactory
(org.springframework.transaction.PlatformTransactionManager platformTransactionManager, MatsSerializer<?> matsSerializer) Convenience variant ofcreateSpringDataSourceTxTestMatsFactory(int, PlatformTransactionManager, MatsSerializer)
where concurrency is 2, which should be adequate for most testing - unless you explicitly want to test concurrency.
-
Constructor Details
-
TestSpringMatsFactoryProvider
public TestSpringMatsFactoryProvider()
-
-
Method Details
-
createSpringDataSourceTxTestMatsFactory
public static MatsFactory createSpringDataSourceTxTestMatsFactory(int concurrency, DataSource sqlDataSource, MatsSerializer<?> matsSerializer) If you need aMatsFactory
employing Spring's DataSourceTransactionManager (which you probably do in a Spring environment utilizing SQL), this is your factory method. If you need to make y Usage: In the test, make a @Bean-annotated method which returns the result of this method - or employ the convenienceMatsTestInfrastructureDbConfiguration
.- Parameters:
concurrency
- The concurrency of the createdMatsFactory
, set withMatsFactory.FactoryConfig.setConcurrency(int)
.sqlDataSource
- the SQL DataSource which to stash into a SpringDataSourceTransactionManager
, and from which SQLConnection
s are fetched from, usingDataSource.getConnection()
. It is assumed that if username and password is needed, you have configured that on the DataSource.matsSerializer
- the MatsSerializer to use. If you employ the standard, useMatsSerializerJson.create()
.- Returns:
- the produced
MatsFactory
-
createSpringDataSourceTxTestMatsFactory
public static MatsFactory createSpringDataSourceTxTestMatsFactory(DataSource sqlDataSource, MatsSerializer<?> matsSerializer) Convenience variant ofcreateSpringDataSourceTxTestMatsFactory(int, DataSource, MatsSerializer)
where concurrency is 1, which should be adequate for most testing - unless you explicitly want to test concurrency.- Parameters:
sqlDataSource
- the SQL DataSource which to stash into a SpringDataSourceTransactionManager
, and from which SQLConnection
s are fetched from, usingDataSource.getConnection()
. It is assumed that if username and password is needed, you have configured that on the DataSource.matsSerializer
- the MatsSerializer to use. If you employ the standard, useMatsSerializerJson.create()
.- Returns:
- the produced
MatsFactory
-
createSpringDataSourceTxTestMatsFactory
public static MatsFactory createSpringDataSourceTxTestMatsFactory(int concurrency, org.springframework.transaction.PlatformTransactionManager platformTransactionManager, MatsSerializer<?> matsSerializer) If you need aMatsFactory
, but you need to make your ownPlatformTransactionManager
, this is your factory method - please note that the containedDataSource
should have been wrapped using the static methodJmsMatsTransactionManager_JmsAndSpringManagedSqlTx.wrapLazyConnectionDatasource(DataSource)
. Usage: In the test, make a @Bean-annotated method which returns the result of this method - or employ the convenienceMatsTestInfrastructureDbConfiguration
.- Parameters:
concurrency
- The concurrency of the createdMatsFactory
, set withMatsFactory.FactoryConfig.setConcurrency(int)
.platformTransactionManager
- thePlatformTransactionManager
that the SpringJmsMats transaction manager should employ. From this, theDataSource
is gotten using refelction to find a method 'getDataSource()'. please note that the containedDataSource
should have been wrapped using the static * methodJmsMatsTransactionManager_JmsAndSpringManagedSqlTx.wrapLazyConnectionDatasource(DataSource)
. It is assumed that if username and password is needed, you have configured that on the DataSource.matsSerializer
- the MatsSerializer to use. If you employ the standard, useMatsSerializerJson.create()
.- Returns:
- the produced
MatsFactory
-
createSpringDataSourceTxTestMatsFactory
public static MatsFactory createSpringDataSourceTxTestMatsFactory(org.springframework.transaction.PlatformTransactionManager platformTransactionManager, MatsSerializer<?> matsSerializer) Convenience variant ofcreateSpringDataSourceTxTestMatsFactory(int, PlatformTransactionManager, MatsSerializer)
where concurrency is 2, which should be adequate for most testing - unless you explicitly want to test concurrency.- Parameters:
platformTransactionManager
- thePlatformTransactionManager
that the SpringJmsMats transaction manager should employ. From this, theDataSource
is gotten using reflection to find a method 'getDataSource()'. please note that the containedDataSource
should have been wrapped using the static methodJmsMatsTransactionManager_JmsAndSpringManagedSqlTx.wrapLazyConnectionDatasource(DataSource)
. It is assumed that if username and password is needed, you have configured that on the DataSource.matsSerializer
- the MatsSerializer to use. If you employ the standard, useMatsSerializerJson.create()
.- Returns:
- the produced
MatsFactory
-
createJmsTxOnlyTestMatsFactory
public static MatsFactory createJmsTxOnlyTestMatsFactory(int concurrency, MatsSerializer<?> matsSerializer) If you need aMatsFactory
that only handles the JMS transactions, this is your factory method - but if you DO make any database calls within any Mats endpoint lambda, you will now have no or poor transactional demarcation, usecreateSpringDataSourceTxTestMatsFactory(..)
instead. Usage: In the test, make a @Bean-annotated method which returns the result of this method - or employ the convenienceMatsTestInfrastructureConfiguration
.- Parameters:
concurrency
- The concurrency of the createdMatsFactory
, set withMatsFactory.FactoryConfig.setConcurrency(int)
.matsSerializer
- the MatsSerializer to use. If you employ the standard, useMatsSerializerJson.create()
.- Returns:
- the produced
MatsFactory
-
createJmsTxOnlyTestMatsFactory
Convenience variant ofcreateJmsTxOnlyTestMatsFactory(int, MatsSerializer)
where concurrency is 2, which should be adequate for most testing - unless you explicitly want to test concurrency.- Parameters:
matsSerializer
- the MatsSerializer to use. If you employ the standard, useMatsSerializerJson.create()
.- Returns:
- the produced
MatsFactory
-