Spring 容器内的引导测试

Spring Boot Tests within a Container

我编写了一个 Spring 基于引导的 Web 应用程序,预计在 WildFly 服务器中是 运行。应用程序 运行 很好,但问题在于测试。

我有服务器处理的数据库连接、缓存和事务管理。现在,我需要能够测试它们。虽然我能够通过模拟 JNDI 连接和事务管理解决数据库连接问题,但我不确定如何处理缓存测试。

一种解决方案是使用 Arquillian 项目。但是,要么这个项目无法识别 Spring Boot/我做错了什么,这让我很难测试应用程序。

有人可以提出解决问题的建议吗?以下是我的休眠特定属性

spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.SQLServer2008Dialect
spring.jpa.properties.hibernate.cache.region.factory_class=org.jboss.as.jpa.hibernate4.infinispan.InfinispanRegionFactory
spring.jpa.properties.hibernate.cache.infinispan.cachemanager=java:jboss/infinispan/container/hibernate
spring.jpa.properties.hibernate.transaction.manager_lookup_class=org.hibernate.transaction.JBossTransactionManagerLookup
spring.jpa.properties.hibernate.cache.use_second_level_cache=true
spring.jpa.properties.hibernate.show_sql=false
spring.jpa.properties.hibernate.cache.use_query_cache=false
spring.jpa.properties.hibernate.hbm2ddl.auto=none
spring.jpa.properties.hibernate.generate_statistics=true
spring.jpa.properties.hibernate.cache.infinispan.statistics=true
spring.jpa.properties.hibernate.search.default.directory_provider=infinispan
spring.jpa.properties.hibernate.search.infinispan.cachemanager_jndiname=java:jboss/infinispan/container/hibernate

我建议为测试创建一个单独的配置。此配置将包含 TransactionManager bean 的定义 - here is an example from other post. The next step is to provide your own implementation of TransactionManagerLookup and applying it to Transport configuration - as described in the manual.