|
| 1 | +/* |
| 2 | + * Copyright 2025 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package org.springframework.data.jdbc.repository; |
| 17 | + |
| 18 | +import org.springframework.beans.factory.annotation.Autowired; |
| 19 | +import org.springframework.context.ApplicationContext; |
| 20 | +import org.springframework.context.annotation.Bean; |
| 21 | +import org.springframework.context.annotation.ComponentScan; |
| 22 | +import org.springframework.context.annotation.Configuration; |
| 23 | +import org.springframework.context.annotation.FilterType; |
| 24 | +import org.springframework.data.jdbc.core.dialect.JdbcH2Dialect; |
| 25 | +import org.springframework.data.jdbc.repository.aot.AotFragmentTestConfigurationSupport; |
| 26 | +import org.springframework.data.jdbc.repository.aot.UserRepository; |
| 27 | +import org.springframework.data.jdbc.repository.config.EnableJdbcRepositories; |
| 28 | +import org.springframework.data.jdbc.testing.DatabaseType; |
| 29 | +import org.springframework.data.jdbc.testing.EnabledOnDatabase; |
| 30 | +import org.springframework.data.jdbc.testing.IntegrationTest; |
| 31 | +import org.springframework.data.jdbc.testing.TestClass; |
| 32 | +import org.springframework.data.repository.core.support.RepositoryComposition; |
| 33 | + |
| 34 | +/** |
| 35 | + * Integration test for {@link DummyEntityRepository} using JavaConfig with mounted AOT-generated repository methods. |
| 36 | + * |
| 37 | + * @author Mark Paluch |
| 38 | + */ |
| 39 | +@IntegrationTest |
| 40 | +@EnabledOnDatabase(DatabaseType.H2) |
| 41 | +class AotJdbcRepositoryIntegrationTests extends JdbcRepositoryIntegrationTests { |
| 42 | + |
| 43 | + @Configuration |
| 44 | + @EnableJdbcRepositories(includeFilters = { |
| 45 | + @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = AotJdbcRepositoryIntegrationTests.class) }) |
| 46 | + static class AotConfig extends Config { |
| 47 | + |
| 48 | + @Autowired ApplicationContext context; |
| 49 | + |
| 50 | + @Bean |
| 51 | + TestClass testClass() { |
| 52 | + return TestClass.of(JdbcRepositoryIntegrationTests.class); |
| 53 | + } |
| 54 | + |
| 55 | + @Bean |
| 56 | + static AotFragmentTestConfigurationSupport aot() { |
| 57 | + return new AotFragmentTestConfigurationSupport(UserRepository.class, JdbcH2Dialect.INSTANCE, AotConfig.class, |
| 58 | + false); |
| 59 | + } |
| 60 | + |
| 61 | + @Bean |
| 62 | + @Override |
| 63 | + DummyEntityRepository dummyEntityRepository() { |
| 64 | + |
| 65 | + RepositoryComposition.RepositoryFragments fragments = RepositoryComposition.RepositoryFragments |
| 66 | + .just(context.getBean("fragment")); |
| 67 | + |
| 68 | + return factory.getRepository(DummyEntityRepository.class, fragments); |
| 69 | + } |
| 70 | + |
| 71 | + } |
| 72 | + |
| 73 | +} |
0 commit comments