|
1 | 1 | /* |
2 | | - * Copyright 2012-2023 the original author or authors. |
| 2 | + * Copyright 2012-2024 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
54 | 54 | import org.springframework.orm.jpa.JpaVendorAdapter; |
55 | 55 | import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; |
56 | 56 | import org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager; |
| 57 | +import org.springframework.orm.jpa.persistenceunit.ManagedClassNameFilter; |
57 | 58 | import org.springframework.orm.jpa.persistenceunit.PersistenceManagedTypes; |
58 | 59 | import org.springframework.orm.jpa.persistenceunit.PersistenceUnitManager; |
59 | 60 | import org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter; |
|
69 | 70 | * @author Phillip Webb |
70 | 71 | * @author Dave Syer |
71 | 72 | * @author Stephane Nicoll |
| 73 | + * @author Yanming Zhou |
72 | 74 | */ |
73 | 75 | abstract class AbstractJpaAutoConfigurationTests { |
74 | 76 |
|
@@ -279,6 +281,16 @@ void customPersistenceUnitPostProcessors() { |
279 | 281 | }); |
280 | 282 | } |
281 | 283 |
|
| 284 | + @Test |
| 285 | + void customManagedClassNameFilter() { |
| 286 | + this.contextRunner.withBean(ManagedClassNameFilter.class, () -> (s) -> !s.endsWith("City")) |
| 287 | + .withUserConfiguration(AutoConfigurePackageForCountry.class) |
| 288 | + .run((context) -> { |
| 289 | + EntityManager entityManager = context.getBean(EntityManagerFactory.class).createEntityManager(); |
| 290 | + assertThat(getManagedJavaTypes(entityManager)).contains(Country.class).doesNotContain(City.class); |
| 291 | + }); |
| 292 | + } |
| 293 | + |
282 | 294 | private Class<?>[] getManagedJavaTypes(EntityManager entityManager) { |
283 | 295 | Set<ManagedType<?>> managedTypes = entityManager.getMetamodel().getManagedTypes(); |
284 | 296 | return managedTypes.stream().map(ManagedType::getJavaType).toArray(Class<?>[]::new); |
@@ -423,6 +435,12 @@ TransactionManager testTransactionManager() { |
423 | 435 |
|
424 | 436 | } |
425 | 437 |
|
| 438 | + @Configuration(proxyBeanMethods = false) |
| 439 | + @TestAutoConfigurationPackage(Country.class) |
| 440 | + static class AutoConfigurePackageForCountry { |
| 441 | + |
| 442 | + } |
| 443 | + |
426 | 444 | @Configuration(proxyBeanMethods = false) |
427 | 445 | @TestAutoConfigurationPackage(AbstractJpaAutoConfigurationTests.class) |
428 | 446 | static class TestConfigurationWithCustomPersistenceUnitManager { |
|
0 commit comments