|
49 | 49 | import org.seasar.doma.jdbc.criteria.NativeSql; |
50 | 50 | import org.seasar.doma.jdbc.criteria.QueryDsl; |
51 | 51 | import org.seasar.doma.jdbc.dialect.Dialect; |
52 | | -import org.seasar.doma.jdbc.dialect.H2Dialect; |
53 | 52 | import org.seasar.doma.jdbc.dialect.MysqlDialect; |
54 | 53 | import org.seasar.doma.jdbc.dialect.PostgresDialect; |
55 | 54 | import org.seasar.doma.jdbc.dialect.StandardDialect; |
|
58 | 57 | import org.seasar.doma.message.Message; |
59 | 58 | import org.springframework.beans.factory.NoSuchBeanDefinitionException; |
60 | 59 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; |
| 60 | +import org.springframework.boot.autoconfigure.jdbc.JdbcConnectionDetails; |
61 | 61 | import org.springframework.context.ConfigurableApplicationContext; |
62 | 62 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; |
63 | 63 | import org.springframework.context.annotation.Bean; |
@@ -263,11 +263,44 @@ public void testDialectByDataSourceUrl() { |
263 | 263 | MutablePropertySources sources = context.getEnvironment() |
264 | 264 | .getPropertySources(); |
265 | 265 | sources.addFirst(new MapPropertySource("test", |
266 | | - Collections.singletonMap("spring.datasource.url", "jdbc:h2:mem:example"))); |
| 266 | + Map.of("spring.datasource.url", "jdbc:postgresql://localhost:1234/example", |
| 267 | + "doma.exception-translation-enabled", |
| 268 | + "false" /* prevent database connections */))); |
267 | 269 | this.context.register(DomaAutoConfiguration.class, DataSourceAutoConfiguration.class); |
268 | 270 | this.context.refresh(); |
269 | 271 | Dialect dialect = this.context.getBean(Dialect.class); |
270 | | - assertThat(dialect, is(instanceOf(H2Dialect.class))); |
| 272 | + assertThat(dialect, is(instanceOf(PostgresDialect.class))); |
| 273 | + } |
| 274 | + |
| 275 | + @Test |
| 276 | + public void testDialectByJdbConnectionDetails() { |
| 277 | + MutablePropertySources sources = context.getEnvironment() |
| 278 | + .getPropertySources(); |
| 279 | + sources.addFirst(new MapPropertySource("test", |
| 280 | + Map.of("doma.exception-translation-enabled", |
| 281 | + "false"/* prevent database connections */))); |
| 282 | + EnvironmentTestUtils.addEnvironment(this.context, |
| 283 | + "doma.exception-translation-enabled:false"); // Prevent database connections |
| 284 | + this.context.register(DomaAutoConfiguration.class, DataSourceAutoConfiguration.class); |
| 285 | + this.context.registerBean(JdbcConnectionDetails.class, () -> new JdbcConnectionDetails() { |
| 286 | + @Override |
| 287 | + public String getUsername() { |
| 288 | + return "dummy"; |
| 289 | + } |
| 290 | + |
| 291 | + @Override |
| 292 | + public String getPassword() { |
| 293 | + return "dummy"; |
| 294 | + } |
| 295 | + |
| 296 | + @Override |
| 297 | + public String getJdbcUrl() { |
| 298 | + return "jdbc:postgresql://localhost:1234/example"; |
| 299 | + } |
| 300 | + }); |
| 301 | + this.context.refresh(); |
| 302 | + Dialect dialect = this.context.getBean(Dialect.class); |
| 303 | + assertThat(dialect, is(instanceOf(PostgresDialect.class))); |
271 | 304 | } |
272 | 305 |
|
273 | 306 | @Test |
|
0 commit comments