-
Notifications
You must be signed in to change notification settings - Fork 40.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add JPA components only on single DataSource #6560
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,13 +29,15 @@ | |
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
|
||
import org.springframework.beans.factory.BeanCreationException; | ||
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; | ||
import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage; | ||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; | ||
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; | ||
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration; | ||
import org.springframework.boot.autoconfigure.jdbc.MultiDataSourceConfiguration; | ||
import org.springframework.boot.autoconfigure.jdbc.MultiDataSourceUsingPrimaryConfiguration; | ||
import org.springframework.boot.autoconfigure.orm.jpa.test.City; | ||
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; | ||
import org.springframework.boot.test.util.EnvironmentTestUtils; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.annotation.AnnotationConfigApplicationContext; | ||
|
@@ -58,6 +60,7 @@ | |
* | ||
* @author Phillip Webb | ||
* @author Dave Syer | ||
* @author Kazuki Shimizu | ||
*/ | ||
public abstract class AbstractJpaAutoConfigurationTests { | ||
|
||
|
@@ -77,10 +80,40 @@ public void close() { | |
public void testNoDataSource() throws Exception { | ||
this.context.register(PropertyPlaceholderAutoConfiguration.class, | ||
getAutoConfigureClass()); | ||
this.expected.expect(BeanCreationException.class); | ||
this.expected.expectMessage("No qualifying bean"); | ||
this.expected.expectMessage("DataSource"); | ||
this.context.refresh(); | ||
assertThat(this.context.getBeansOfType(JpaProperties.class).size()).isEqualTo(1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure I like that, you're changing the semantic a lot (and it's wider than the intent of this PR IMO). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @snicoll , i have a question for your opinion. Should i change to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. I am not sure I understand what triggers this change but previoulsy if you had no data source at all you'd get a |
||
assertThat(this.context.getBeansOfType(JpaVendorAdapter.class)).isEmpty(); | ||
assertThat(this.context.getBeansOfType(EntityManagerFactoryBuilder.class)).isEmpty(); | ||
assertThat(this.context.getBeansOfType(LocalContainerEntityManagerFactoryBean.class)).isEmpty(); | ||
assertThat(this.context.getBeansOfType(PlatformTransactionManager.class)).isEmpty(); | ||
} | ||
|
||
@Test | ||
public void testMultiDataSource() throws Exception { | ||
this.context.register(PropertyPlaceholderAutoConfiguration.class, | ||
MultiDataSourceConfiguration.class, | ||
getAutoConfigureClass()); | ||
this.context.refresh(); | ||
assertThat(this.context.getBeansOfType(DataSource.class).size()).isEqualTo(2); | ||
assertThat(this.context.getBeansOfType(JpaProperties.class).size()).isEqualTo(1); | ||
assertThat(this.context.getBeansOfType(JpaVendorAdapter.class)).isEmpty(); | ||
assertThat(this.context.getBeansOfType(EntityManagerFactoryBuilder.class)).isEmpty(); | ||
assertThat(this.context.getBeansOfType(LocalContainerEntityManagerFactoryBean.class)).isEmpty(); | ||
assertThat(this.context.getBeansOfType(PlatformTransactionManager.class)).isEmpty(); | ||
} | ||
|
||
@Test | ||
public void testMultiDataSourceUsingPrimary() throws Exception { | ||
this.context.register(PropertyPlaceholderAutoConfiguration.class, | ||
MultiDataSourceUsingPrimaryConfiguration.class, | ||
getAutoConfigureClass()); | ||
this.context.refresh(); | ||
assertThat(this.context.getBeansOfType(DataSource.class).size()).isEqualTo(2); | ||
assertThat(this.context.getBean(JpaProperties.class)).isNotNull(); | ||
assertThat(this.context.getBean(JpaVendorAdapter.class)).isNotNull(); | ||
assertThat(this.context.getBean(EntityManagerFactoryBuilder.class)).isNotNull(); | ||
assertThat(this.context.getBean(LocalContainerEntityManagerFactoryBean.class)).isNotNull(); | ||
assertThat(this.context.getBean(JpaTransactionManager.class)).isNotNull(); | ||
} | ||
|
||
@Test | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a bold move but I think I like it. I have a feeling it's going to break user's app, wdyt @wilkinsona ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might too. I don't think such a change belongs in 1.4.1.