Skip to content

Commit 852f5b3

Browse files
committed
refactor: move a category dao class into shared dao configutation.
Part of and fixes #1150
1 parent 0b32030 commit 852f5b3

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

src/main/java/ru/mystamps/web/config/DaoConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020

2121
import org.springframework.context.annotation.Configuration;
2222
import org.springframework.context.annotation.Import;
23+
import ru.mystamps.web.feature.category.CategoryConfig;
2324
import ru.mystamps.web.feature.country.CountryConfig;
2425

2526
@Configuration
2627
@Import({
28+
CategoryConfig.Daos.class,
2729
CountryConfig.Daos.class
2830
})
2931
public class DaoConfig {

src/main/java/ru/mystamps/web/feature/category/CategoryConfig.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
2626
/**
2727
* Spring configuration that is required for using categories in an application.
2828
*
29-
* The beans are grouped into two classes to make possible to register a controller
30-
* and the services in the separated application contexts.
29+
* The beans are grouped into different classes to make possible to register a controller
30+
* and the services in the separate application contexts. DAOs have been extracted to use
31+
* them independently from services in the tests.
3132
*/
3233
@Configuration
3334
public class CategoryConfig {
@@ -52,16 +53,23 @@ public SuggestionController suggestionCategoryController() {
5253
@RequiredArgsConstructor
5354
public static class Services {
5455

55-
private final NamedParameterJdbcTemplate jdbcTemplate;
56+
private final CategoryDao categoryDao;
5657

5758
@Bean
58-
public CategoryService categoryService(CategoryDao categoryDao) {
59+
public CategoryService categoryService() {
5960
return new CategoryServiceImpl(
6061
LoggerFactory.getLogger(CategoryServiceImpl.class),
6162
categoryDao
6263
);
6364
}
6465

66+
}
67+
68+
@RequiredArgsConstructor
69+
public static class Daos {
70+
71+
private final NamedParameterJdbcTemplate jdbcTemplate;
72+
6573
@Bean
6674
public CategoryDao categoryDao() {
6775
return new JdbcCategoryDao(jdbcTemplate);

src/test/java/ru/mystamps/web/feature/category/JdbcCategoryDaoTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
import org.springframework.test.context.TestPropertySource;
2828
import org.springframework.test.context.jdbc.Sql;
2929
import org.springframework.test.context.junit4.SpringRunner;
30+
import ru.mystamps.web.config.DaoConfig;
3031
import ru.mystamps.web.tests.Random;
3132

3233
import java.util.Map;
3334

3435
@JdbcTest
35-
// @todo #1143 Introduce a dedicated config for DAO classes
36-
@ContextConfiguration(classes = CategoryConfig.Services.class)
36+
@ContextConfiguration(classes = DaoConfig.class)
3737
@TestPropertySource(
3838
properties = {
3939
// don't load test data, start with an empty database

0 commit comments

Comments
 (0)