34
34
import org .springframework .boot .web .servlet .ServletRegistrationBean ;
35
35
import org .springframework .context .annotation .Bean ;
36
36
import org .springframework .context .annotation .Configuration ;
37
- import org .springframework .context .annotation .Primary ;
37
+ import org .springframework .core .annotation .Order ;
38
38
39
39
import static org .assertj .core .api .Assertions .assertThat ;
40
40
import static org .mockito .BDDMockito .given ;
@@ -120,30 +120,30 @@ void singleDataSourceUrlIsLoggedWhenOnlyOneAvailable(CapturedOutput output) {
120
120
this .contextRunner .withConfiguration (AutoConfigurations .of (DataSourceAutoConfiguration .class ))
121
121
.withPropertyValues ("spring.h2.console.enabled=true" ).run ((context ) -> {
122
122
try (Connection connection = context .getBean (DataSource .class ).getConnection ()) {
123
- assertThat (output )
124
- . contains ( "H2 console available at '/h2-console'. Database(s) available at '" + connection .getMetaData ().getURL () + "'" );
123
+ assertThat (output ). contains ( "H2 console available at '/h2-console'. Database available at '"
124
+ + connection .getMetaData ().getURL () + "'" );
125
125
}
126
126
});
127
127
}
128
128
129
- @ Test
130
- @ ExtendWith (OutputCaptureExtension .class )
131
- void allDataSourceUrlsAreLoggedWhenMultipleAvailable (CapturedOutput output ) {
132
- this .contextRunner .withUserConfiguration (MultiDataSourceConfiguration .class )
133
- .withPropertyValues ("spring.h2.console.enabled=true" ).run ((context ) ->
134
- assertThat (output ).contains ("H2 console available at '/h2-console'. Database(s) available at 'primaryUrl', 'secondaryUrl'" ));
135
- }
136
-
137
129
@ Test
138
130
@ ExtendWith (OutputCaptureExtension .class )
139
131
void noDataSourceIsLoggedWhenNoneAvailable (CapturedOutput output ) {
140
132
this .contextRunner .withUserConfiguration (FailingDataSourceConfiguration .class )
141
133
.withPropertyValues ("spring.h2.console.enabled=true" )
142
- .run ((context ) -> assertThat (output ).isEmpty ( ));
134
+ .run ((context ) -> assertThat (output ).doesNotContain ( "H2 console available" ));
143
135
}
144
136
137
+ @ Test
138
+ @ ExtendWith (OutputCaptureExtension .class )
139
+ void allDataSourceUrlsAreLoggedWhenMultipleAvailable (CapturedOutput output ) {
140
+ this .contextRunner
141
+ .withUserConfiguration (FailingDataSourceConfiguration .class , MultiDataSourceConfiguration .class )
142
+ .withPropertyValues ("spring.h2.console.enabled=true" ).run ((context ) -> assertThat (output ).contains (
143
+ "H2 console available at '/h2-console'. Databases available at 'someJdbcUrl', 'anotherJdbcUrl'" ));
144
+ }
145
145
146
- @ Test
146
+ @ Test
147
147
void h2ConsoleShouldNotFailIfDatabaseConnectionFails () {
148
148
this .contextRunner .withUserConfiguration (FailingDataSourceConfiguration .class )
149
149
.withPropertyValues ("spring.h2.console.enabled=true" )
@@ -163,20 +163,21 @@ DataSource dataSource() throws SQLException {
163
163
}
164
164
165
165
@ Configuration (proxyBeanMethods = false )
166
- static class MultiDataSourceConfiguration extends FailingDataSourceConfiguration {
166
+ static class MultiDataSourceConfiguration {
167
167
168
168
@ Bean
169
- @ Primary
170
- DataSource primaryDataSource () throws SQLException {
171
- return getDataSource ( "primaryUrl " );
169
+ @ Order ( 5 )
170
+ DataSource anotherDataSource () throws SQLException {
171
+ return mockDataSource ( "anotherJdbcUrl " );
172
172
}
173
173
174
174
@ Bean
175
- DataSource anotherDataSource () throws SQLException {
176
- return getDataSource ("secondaryUrl" );
175
+ @ Order (0 )
176
+ DataSource someDataSource () throws SQLException {
177
+ return mockDataSource ("someJdbcUrl" );
177
178
}
178
179
179
- private DataSource getDataSource (String url ) throws SQLException {
180
+ private DataSource mockDataSource (String url ) throws SQLException {
180
181
DataSource dataSource = mock (DataSource .class );
181
182
given (dataSource .getConnection ()).willReturn (mock (Connection .class ));
182
183
given (dataSource .getConnection ().getMetaData ()).willReturn (mock (DatabaseMetaData .class ));
0 commit comments