Skip to content

Commit 0b32030

Browse files
committed
refactor: move a country dao class into shared dao configutation.
Now JdbcCountryDaoTest doesn't depend on a service class and we can stop @ignore this test. This removes a hack that has been added in e004fa3 commit (#1163). Part of #1150
1 parent e004fa3 commit 0b32030

File tree

4 files changed

+45
-9
lines changed

4 files changed

+45
-9
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
@Configuration
3030
@Import({
31+
DaoConfig.class,
3132
SecurityConfig.class,
3233
ServicesConfig.class,
3334
TaskExecutorConfig.class,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (C) 2009-2019 Slava Semushin <[email protected]>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17+
*/
18+
19+
package ru.mystamps.web.config;
20+
21+
import org.springframework.context.annotation.Configuration;
22+
import org.springframework.context.annotation.Import;
23+
import ru.mystamps.web.feature.country.CountryConfig;
24+
25+
@Configuration
26+
@Import({
27+
CountryConfig.Daos.class
28+
})
29+
public class DaoConfig {
30+
}

src/main/java/ru/mystamps/web/feature/country/CountryConfig.java

+12-4
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828
/**
2929
* Spring configuration that is required for using countries in an application.
3030
*
31-
* The beans are grouped into two classes to make possible to register a controller
32-
* and the services in the separated application contexts.
31+
* The beans are grouped into different classes to make possible to register a controller
32+
* and the services in the separate application contexts. DAOs have been extracted to use
33+
* them independently from services in the tests.
3334
*/
3435
@Configuration
3536
public class CountryConfig {
@@ -54,12 +55,12 @@ public SuggestionController suggestionCountryController() {
5455
@RequiredArgsConstructor
5556
public static class Services {
5657

58+
private final CountryDao countryDao;
5759
private final Environment env;
58-
private final NamedParameterJdbcTemplate jdbcTemplate;
5960
private final RestTemplateBuilder restTemplateBuilder;
6061

6162
@Bean
62-
public CountryService countryService(CountryDao countryDao) {
63+
public CountryService countryService() {
6364
return new TogglzWithFallbackCountryService(
6465
new ApiCountryService(restTemplateBuilder, env),
6566
new CountryServiceImpl(
@@ -69,6 +70,13 @@ public CountryService countryService(CountryDao countryDao) {
6970
);
7071
}
7172

73+
}
74+
75+
@RequiredArgsConstructor
76+
public static class Daos {
77+
78+
private final NamedParameterJdbcTemplate jdbcTemplate;
79+
7280
@Bean
7381
public CountryDao countryDao() {
7482
return new JdbcCountryDao(jdbcTemplate);

src/test/java/ru/mystamps/web/feature/country/JdbcCountryDaoTest.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package ru.mystamps.web.feature.country;
2020

2121
import org.assertj.core.api.WithAssertions;
22-
import org.junit.Ignore;
2322
import org.junit.Test;
2423
import org.junit.runner.RunWith;
2524
import org.springframework.beans.factory.annotation.Autowired;
@@ -28,15 +27,13 @@
2827
import org.springframework.test.context.TestPropertySource;
2928
import org.springframework.test.context.jdbc.Sql;
3029
import org.springframework.test.context.junit4.SpringRunner;
30+
import ru.mystamps.web.config.DaoConfig;
3131
import ru.mystamps.web.tests.Random;
3232

3333
import java.util.Map;
3434

35-
// FIXME: deal with failing tests
36-
@Ignore
3735
@JdbcTest
38-
// LATER: use a single application context with DAOs (see #1150)
39-
@ContextConfiguration(classes = CountryConfig.Services.class)
36+
@ContextConfiguration(classes = DaoConfig.class)
4037
@TestPropertySource(
4138
properties = {
4239
// don't load test data, start with an empty database

0 commit comments

Comments
 (0)