|
17 | 17 |
|
18 | 18 | import static org.assertj.core.api.Assertions.*; |
19 | 19 |
|
| 20 | +import java.util.List; |
| 21 | +import java.util.Optional; |
| 22 | +import java.util.UUID; |
| 23 | + |
20 | 24 | import org.junit.jupiter.api.Test; |
21 | 25 | import org.junit.jupiter.api.extension.ExtendWith; |
22 | 26 | import org.mockito.Mockito; |
|
26 | 30 | import org.springframework.aop.framework.Advised; |
27 | 31 | import org.springframework.aot.hint.RuntimeHints; |
28 | 32 | import org.springframework.beans.factory.ListableBeanFactory; |
| 33 | +import org.springframework.beans.factory.config.BeanDefinition; |
| 34 | +import org.springframework.beans.factory.parsing.BeanComponentDefinition; |
29 | 35 | import org.springframework.beans.factory.support.RootBeanDefinition; |
30 | 36 | import org.springframework.context.annotation.AnnotationBeanNameGenerator; |
31 | 37 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; |
|
37 | 43 | import org.springframework.core.metrics.ApplicationStartup; |
38 | 44 | import org.springframework.core.type.AnnotationMetadata; |
39 | 45 | import org.springframework.core.type.StandardAnnotationMetadata; |
| 46 | +import org.springframework.data.mapping.Person; |
| 47 | +import org.springframework.data.repository.Repository; |
40 | 48 | import org.springframework.data.repository.config.RepositoryConfigurationDelegate.LazyRepositoryInjectionPointResolver; |
41 | 49 | import org.springframework.data.repository.config.annotated.MyAnnotatedRepository; |
42 | 50 | import org.springframework.data.repository.config.annotated.MyAnnotatedRepositoryImpl; |
43 | 51 | import org.springframework.data.repository.config.annotated.MyFragmentImpl; |
44 | 52 | import org.springframework.data.repository.config.excluded.MyOtherRepositoryImpl; |
45 | 53 | import org.springframework.data.repository.config.stereotype.MyStereotypeRepository; |
46 | 54 | import org.springframework.data.repository.core.support.DummyRepositoryFactoryBean; |
| 55 | +import org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport; |
47 | 56 | import org.springframework.data.repository.sample.AddressRepository; |
48 | 57 | import org.springframework.data.repository.sample.AddressRepositoryClient; |
49 | 58 | import org.springframework.data.repository.sample.ProductRepository; |
@@ -279,4 +288,43 @@ protected String getModulePrefix() { |
279 | 288 | return "commons"; |
280 | 289 | } |
281 | 290 | } |
| 291 | + |
| 292 | + @Test // GH-3074 |
| 293 | + void registersGenericsForConstrainingRepositoryFactoryBean() { |
| 294 | + |
| 295 | + AnnotationMetadata metadata = AnnotationMetadata.introspect(AnnotatedBeanNamesConfig.class); |
| 296 | + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); |
| 297 | + |
| 298 | + RepositoryConfigurationSource source = new AnnotationRepositoryConfigurationSource(metadata, |
| 299 | + EnableRepositories.class, context, context.getEnvironment(), |
| 300 | + context.getDefaultListableBeanFactory(), new AnnotationBeanNameGenerator()) { |
| 301 | + |
| 302 | + @Override |
| 303 | + public Optional<String> getRepositoryFactoryBeanClassName() { |
| 304 | + return Optional.of(IdConstrainingRepositoryFactoryBean.class.getName()); |
| 305 | + } |
| 306 | + }; |
| 307 | + |
| 308 | + RepositoryConfigurationDelegate delegate = new RepositoryConfigurationDelegate(source, context, |
| 309 | + context.getEnvironment()); |
| 310 | + |
| 311 | + List<BeanComponentDefinition> repositories = delegate.registerRepositoriesIn(context, extension); |
| 312 | + |
| 313 | + assertThat(repositories).hasSize(1).element(0) |
| 314 | + .extracting(BeanComponentDefinition::getBeanDefinition) |
| 315 | + .extracting(BeanDefinition::getResolvableType) |
| 316 | + .satisfies(it -> { |
| 317 | + assertThat(it.getGenerics()).hasSize(2); |
| 318 | + assertThat(it.getGeneric(0).resolve()).isEqualTo(MyAnnotatedRepository.class); |
| 319 | + assertThat(it.getGeneric(1).resolve()).isEqualTo(Person.class); |
| 320 | + }); |
| 321 | + } |
| 322 | + |
| 323 | + static abstract class IdConstrainingRepositoryFactoryBean<T extends Repository<S, UUID>, S> |
| 324 | + extends RepositoryFactoryBeanSupport<T, S, UUID> { |
| 325 | + |
| 326 | + protected IdConstrainingRepositoryFactoryBean(Class<? extends T> repositoryInterface) { |
| 327 | + super(repositoryInterface); |
| 328 | + } |
| 329 | + } |
282 | 330 | } |
0 commit comments