I have two services MyRepo and RepoWrapper, RepoWrapper is composed of MyRepo which has some method annotated with some spring cache annotations.
I want to configure a test context with only the necessary classes and cache enabled, and most importantly without using @SpringBootTest which loads the entire application context.
here are my classes:
@Repository
interface MyRepo: CrudRepository<SomeEntity, Long>
@Repository
@Primary
class RepoWrapper(val myRepo: MyRepo): CrudRepository<SomeEntity, Long> by myRepo {
@Cacheable
fun foo(arg: Any) {
// ..
}
}
Here is my attempts to load smaller application context.
@ExtendsWith(SpringExtension::class)
@ContextConfiguration(classes = [TestConfig::class, RepoWrapper::class])
class MyIntegrationTest {
@MockBean
lateinit var myRepo: MyRepo
@Autowired
lateinit var cacheManager: CacheManager
@Autowired
lateinit repoWrapper: RepoWrapper
@Test
fun mytest() {
assertTrue(true)
}}
}
@TestConfiguration
class TestConfig {
@Bean
fun cacheManager() = ConcurrentMapCacheManager("mycache")
@Bean
fun repoWrapper(myRepo: MyRepo): RepoWrapper = RepoWrapper(cacheManager(), myRepo)
}
How come when I remove the RepoWrapper from the ContextConfiguration classes, or remove it’s bean from TestConfig, Spring seems not able to load the test context ?