|
1 | 1 | package org.seasar.doma.boot.autoconfigure; |
2 | 2 |
|
3 | | -import static org.hamcrest.CoreMatchers.*; |
4 | | -import static org.hamcrest.MatcherAssert.*; |
5 | | -import static org.junit.jupiter.api.Assertions.*; |
| 3 | +import static org.hamcrest.CoreMatchers.instanceOf; |
| 4 | +import static org.hamcrest.CoreMatchers.is; |
| 5 | +import static org.hamcrest.CoreMatchers.notNullValue; |
| 6 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 7 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 8 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
6 | 9 |
|
7 | 10 | import java.sql.SQLException; |
8 | 11 | import java.sql.SQLTimeoutException; |
|
27 | 30 | import org.seasar.doma.jdbc.UtilLoggingJdbcLogger; |
28 | 31 | import org.seasar.doma.jdbc.criteria.Entityql; |
29 | 32 | import org.seasar.doma.jdbc.criteria.NativeSql; |
| 33 | +import org.seasar.doma.jdbc.criteria.QueryDsl; |
30 | 34 | import org.seasar.doma.jdbc.dialect.Dialect; |
31 | 35 | import org.seasar.doma.jdbc.dialect.H2Dialect; |
32 | 36 | import org.seasar.doma.jdbc.dialect.MysqlDialect; |
@@ -255,6 +259,24 @@ public void testJdbcLoggerSlf4J() { |
255 | 259 | assertThat(jdbcLogger.getClass().getSimpleName(), is("Slf4jJdbcLogger")); |
256 | 260 | } |
257 | 261 |
|
| 262 | + @Test |
| 263 | + public void testAutoRegisteredQueryDsl() { |
| 264 | + this.context.register(DomaAutoConfiguration.class, DataSourceAutoConfiguration.class); |
| 265 | + this.context.refresh(); |
| 266 | + QueryDsl queryDsl = this.context.getBean(QueryDsl.class); |
| 267 | + assertNotNull(queryDsl); |
| 268 | + } |
| 269 | + |
| 270 | + @Test |
| 271 | + public void testQueryDslWithConfig() { |
| 272 | + this.context.register(MyQueryDslConfig.class, DomaAutoConfiguration.class, |
| 273 | + DataSourceAutoConfiguration.class); |
| 274 | + this.context.refresh(); |
| 275 | + Map<String, QueryDsl> queryDslBeans = this.context.getBeansOfType(QueryDsl.class); |
| 276 | + assertEquals(1, queryDslBeans.size()); |
| 277 | + assertNotNull(queryDslBeans.get("myQueryDsl")); |
| 278 | + } |
| 279 | + |
258 | 280 | @After |
259 | 281 | public void tearDown() { |
260 | 282 | if (this.context != null) { |
@@ -341,4 +363,13 @@ public NativeSql myNativeSql(Config config) { |
341 | 363 | return new NativeSql(config); |
342 | 364 | } |
343 | 365 | } |
| 366 | + |
| 367 | + @Configuration |
| 368 | + public static class MyQueryDslConfig { |
| 369 | + |
| 370 | + @Bean |
| 371 | + public QueryDsl myQueryDsl(Config config) { |
| 372 | + return new QueryDsl(config); |
| 373 | + } |
| 374 | + } |
344 | 375 | } |
0 commit comments