@ -19,6 +19,7 @@ package org.springframework.boot.autoconfigure.orm.jpa;
import java.io.File ;
import java.io.File ;
import java.util.HashMap ;
import java.util.HashMap ;
import java.util.Map ;
import java.util.Map ;
import java.util.Set ;
import java.util.UUID ;
import java.util.UUID ;
import javax.sql.DataSource ;
import javax.sql.DataSource ;
@ -236,8 +237,7 @@ abstract class AbstractJpaAutoConfigurationTests {
this . contextRunner . run ( ( context ) - > {
this . contextRunner . run ( ( context ) - > {
assertThat ( context ) . hasSingleBean ( PersistenceManagedTypes . class ) ;
assertThat ( context ) . hasSingleBean ( PersistenceManagedTypes . class ) ;
EntityManager entityManager = context . getBean ( EntityManagerFactory . class ) . createEntityManager ( ) ;
EntityManager entityManager = context . getBean ( EntityManagerFactory . class ) . createEntityManager ( ) ;
assertThat ( entityManager . getMetamodel ( ) . getManagedTypes ( ) . stream ( ) . map ( ManagedType : : getJavaType )
assertThat ( getManagedJavaTypes ( entityManager ) ) . contains ( City . class ) . doesNotContain ( Country . class ) ;
. toArray ( Class < ? > [ ] : : new ) ) . contains ( City . class ) . doesNotContain ( Country . class ) ;
} ) ;
} ) ;
}
}
@ -248,8 +248,7 @@ abstract class AbstractJpaAutoConfigurationTests {
. run ( ( context ) - > {
. run ( ( context ) - > {
assertThat ( context ) . hasSingleBean ( PersistenceManagedTypes . class ) ;
assertThat ( context ) . hasSingleBean ( PersistenceManagedTypes . class ) ;
EntityManager entityManager = context . getBean ( EntityManagerFactory . class ) . createEntityManager ( ) ;
EntityManager entityManager = context . getBean ( EntityManagerFactory . class ) . createEntityManager ( ) ;
assertThat ( entityManager . getMetamodel ( ) . getManagedTypes ( ) . stream ( ) . map ( ManagedType : : getJavaType )
assertThat ( getManagedJavaTypes ( entityManager ) ) . contains ( Country . class ) . doesNotContain ( City . class ) ;
. toArray ( Class < ? > [ ] : : new ) ) . contains ( Country . class ) . doesNotContain ( City . class ) ;
} ) ;
} ) ;
}
}
@ -277,6 +276,11 @@ abstract class AbstractJpaAutoConfigurationTests {
} ) ;
} ) ;
}
}
private Class < ? > [ ] getManagedJavaTypes ( EntityManager entityManager ) {
Set < ManagedType < ? > > managedTypes = entityManager . getMetamodel ( ) . getManagedTypes ( ) ;
return managedTypes . stream ( ) . map ( ManagedType : : getJavaType ) . toArray ( Class < ? > [ ] : : new ) ;
}
@Configuration ( proxyBeanMethods = false )
@Configuration ( proxyBeanMethods = false )
static class TestTwoDataSourcesConfiguration {
static class TestTwoDataSourcesConfiguration {