Skip to content

Commit 325d9cc

Browse files
committed
Polishing.
Run tests only for a single database since it is actually not testing anything database related. Formatting. Original pull request #1187 See #1043
1 parent 246343f commit 325d9cc

15 files changed

+48
-96
lines changed

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/config/EnableJdbcRepositories.java

+2
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@
136136
/**
137137
* Returns the key of the {@link QueryLookupStrategy} to be used for lookup queries for query methods. Defaults to
138138
* {@link QueryLookupStrategy.Key#CREATE_IF_NOT_FOUND}.
139+
*
140+
* @since 2.1
139141
*/
140142
QueryLookupStrategy.Key queryLookupStrategy() default QueryLookupStrategy.Key.CREATE_IF_NOT_FOUND;
141143
}

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/support/JdbcQueryLookupStrategy.java

+15-20
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ abstract class JdbcQueryLookupStrategy implements QueryLookupStrategy {
9999
* {@link QueryLookupStrategy} to create a query from the method name.
100100
*
101101
* @author Diego Krupitza
102+
* @since 2.4
102103
*/
103104
static class CreateQueryLookupStrategy extends JdbcQueryLookupStrategy {
104105

@@ -125,6 +126,7 @@ public RepositoryQuery resolveQuery(Method method, RepositoryMetadata repository
125126
* {@link org.springframework.data.jdbc.repository.query.Query} annotation followed by a JPA named query lookup.
126127
*
127128
* @author Diego Krupitza
129+
* @since 2.4
128130
*/
129131
static class DeclaredQueryLookupStrategy extends JdbcQueryLookupStrategy {
130132

@@ -150,7 +152,7 @@ public RepositoryQuery resolveQuery(Method method, RepositoryMetadata repository
150152

151153
StringBasedJdbcQuery query = new StringBasedJdbcQuery(queryMethod, getOperations(), this::createMapper,
152154
getConverter());
153-
query.setBeanFactory(getBeanfactory());
155+
query.setBeanFactory(getBeanFactory());
154156
return query;
155157
}
156158

@@ -163,12 +165,9 @@ public RepositoryQuery resolveQuery(Method method, RepositoryMetadata repository
163165
* {@link QueryLookupStrategy} to try to detect a declared query first (
164166
* {@link org.springframework.data.jdbc.repository.query.Query}, JDBC named query). In case none is found we fall back
165167
* on query creation.
166-
* <p>
167-
* Modified based on original source: {@link org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy}
168168
*
169-
* @author Oliver Gierke
170-
* @author Thomas Darimont
171169
* @author Diego Krupitza
170+
* @since 2.4
172171
*/
173172
static class CreateIfNotFoundQueryLookupStrategy extends JdbcQueryLookupStrategy {
174173

@@ -181,7 +180,7 @@ static class CreateIfNotFoundQueryLookupStrategy extends JdbcQueryLookupStrategy
181180
* @param createStrategy must not be {@literal null}.
182181
* @param lookupStrategy must not be {@literal null}.
183182
*/
184-
public CreateIfNotFoundQueryLookupStrategy(ApplicationEventPublisher publisher, @Nullable EntityCallbacks callbacks,
183+
CreateIfNotFoundQueryLookupStrategy(ApplicationEventPublisher publisher, @Nullable EntityCallbacks callbacks,
185184
RelationalMappingContext context, JdbcConverter converter, Dialect dialect,
186185
QueryMappingConfiguration queryMappingConfiguration, NamedParameterJdbcOperations operations,
187186
@Nullable BeanFactory beanfactory, CreateQueryLookupStrategy createStrategy,
@@ -228,12 +227,12 @@ JdbcQueryMethod getJdbcQueryMethod(Method method, RepositoryMetadata repositoryM
228227
* @param dialect must not be {@literal null}
229228
* @param queryMappingConfiguration must not be {@literal null}
230229
* @param operations must not be {@literal null}
231-
* @param beanfactory may be {@literal null}
230+
* @param beanFactory may be {@literal null}
232231
*/
233232
public static QueryLookupStrategy create(@Nullable Key key, ApplicationEventPublisher publisher,
234233
@Nullable EntityCallbacks callbacks, RelationalMappingContext context, JdbcConverter converter, Dialect dialect,
235234
QueryMappingConfiguration queryMappingConfiguration, NamedParameterJdbcOperations operations,
236-
@Nullable BeanFactory beanfactory) {
235+
@Nullable BeanFactory beanFactory) {
237236

238237
Assert.notNull(publisher, "ApplicationEventPublisher must not be null");
239238
Assert.notNull(context, "RelationalMappingContextPublisher must not be null");
@@ -243,10 +242,10 @@ public static QueryLookupStrategy create(@Nullable Key key, ApplicationEventPubl
243242
Assert.notNull(operations, "NamedParameterJdbcOperations must not be null");
244243

245244
CreateQueryLookupStrategy createQueryLookupStrategy = new CreateQueryLookupStrategy(publisher, callbacks, context,
246-
converter, dialect, queryMappingConfiguration, operations, beanfactory);
245+
converter, dialect, queryMappingConfiguration, operations, beanFactory);
247246

248247
DeclaredQueryLookupStrategy declaredQueryLookupStrategy = new DeclaredQueryLookupStrategy(publisher, callbacks,
249-
context, converter, dialect, queryMappingConfiguration, operations, beanfactory);
248+
context, converter, dialect, queryMappingConfiguration, operations, beanFactory);
250249

251250
Key cleanedKey = key != null ? key : Key.CREATE_IF_NOT_FOUND;
252251

@@ -259,34 +258,30 @@ public static QueryLookupStrategy create(@Nullable Key key, ApplicationEventPubl
259258
return declaredQueryLookupStrategy;
260259
case CREATE_IF_NOT_FOUND:
261260
return new CreateIfNotFoundQueryLookupStrategy(publisher, callbacks, context, converter, dialect,
262-
queryMappingConfiguration, operations, beanfactory, createQueryLookupStrategy, declaredQueryLookupStrategy);
261+
queryMappingConfiguration, operations, beanFactory, createQueryLookupStrategy, declaredQueryLookupStrategy);
263262
default:
264263
throw new IllegalArgumentException(String.format("Unsupported query lookup strategy %s!", key));
265264
}
266265
}
267266

268-
protected ApplicationEventPublisher getPublisher() {
269-
return publisher;
270-
}
271-
272-
protected RelationalMappingContext getContext() {
267+
RelationalMappingContext getContext() {
273268
return context;
274269
}
275270

276-
protected JdbcConverter getConverter() {
271+
JdbcConverter getConverter() {
277272
return converter;
278273
}
279274

280-
protected Dialect getDialect() {
275+
Dialect getDialect() {
281276
return dialect;
282277
}
283278

284-
protected NamedParameterJdbcOperations getOperations() {
279+
NamedParameterJdbcOperations getOperations() {
285280
return operations;
286281
}
287282

288283
@Nullable
289-
protected BeanFactory getBeanfactory() {
284+
BeanFactory getBeanFactory() {
290285
return beanfactory;
291286
}
292287

Original file line numberDiff line numberDiff line change
@@ -29,26 +29,28 @@
2929
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
3030

3131
/**
32-
* Base class to test <code>@EnableJdbcRepositories(queryLookupStrategy = ...)</code> Tests based on logic from
33-
* {@link org.springframework.data.jdbc.repository.support.JdbcQueryLookupStrategy}
32+
* Base class to test <code>@EnableJdbcRepositories(queryLookupStrategy = ...)</code>
3433
*
3534
* @author Diego Krupitza
35+
* @since 2.4
3636
*/
37-
abstract class AbstractJdbcRepositoryLookUpStrategyIntegrationTests {
37+
abstract class AbstractJdbcRepositoryLookUpStrategyTests {
3838

3939
@Autowired protected OnesRepository onesRepository;
4040
@Autowired NamedParameterJdbcTemplate template;
4141
@Autowired RelationalMappingContext context;
4242

43-
protected void insertTestInstances() {
43+
void insertTestInstances() {
44+
4445
AggregateOne firstAggregate = new AggregateOne("Diego");
4546
AggregateOne secondAggregate = new AggregateOne("Franz");
4647
AggregateOne thirdAggregate = new AggregateOne("Daniela");
4748

4849
onesRepository.saveAll(Arrays.asList(firstAggregate, secondAggregate, thirdAggregate));
4950
}
5051

51-
protected void callDeclaredQuery(String name, int expectedSize, String... expectedNames) {
52+
void callDeclaredQuery(String name, int expectedSize, String... expectedNames) {
53+
5254
insertTestInstances();
5355

5456
List<AggregateOne> likeNameD = onesRepository.findAllByName(name);
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,31 @@
2727
import org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory;
2828
import org.springframework.data.jdbc.testing.TestConfiguration;
2929
import org.springframework.data.repository.query.QueryLookupStrategy;
30-
import org.springframework.test.context.ActiveProfiles;
3130
import org.springframework.test.context.ContextConfiguration;
3231
import org.springframework.test.context.junit.jupiter.SpringExtension;
3332
import org.springframework.transaction.annotation.Transactional;
3433

3534
/**
3635
* Test to verify that
3736
* <code>@EnableJdbcRepositories(queryLookupStrategy = QueryLookupStrategy.Key.CREATE_IF_NOT_FOUND)</code> works as
38-
* intended. Tests based on logic from
39-
* {@link org.springframework.data.jdbc.repository.support.JdbcQueryLookupStrategy.CreateIfNotFoundQueryLookupStrategy}
37+
* intended.
4038
*
4139
* @author Diego Krupitza
40+
* @author Jens Schauder
4241
*/
4342
@ContextConfiguration
4443
@Transactional
45-
@ActiveProfiles("hsql")
4644
@ExtendWith(SpringExtension.class)
47-
class JdbcRepositoryCreateIfNotFoundLookUpStrategyIntegrationTests
48-
extends AbstractJdbcRepositoryLookUpStrategyIntegrationTests {
45+
class JdbcRepositoryCreateIfNotFoundLookUpStrategyTests
46+
extends AbstractJdbcRepositoryLookUpStrategyTests {
4947

50-
@Test
48+
@Test // GH-1043
5149
void declaredQueryShouldWork() {
5250
onesRepository.deleteAll();
5351
callDeclaredQuery("D", 2, "Diego", "Daniela");
5452
}
5553

56-
@Test
54+
@Test // GH-1043
5755
void derivedQueryShouldWork() {
5856
onesRepository.deleteAll();
5957
callDerivedQuery();
@@ -64,16 +62,15 @@ void derivedQueryShouldWork() {
6462
@EnableJdbcRepositories(considerNestedRepositories = true,
6563
queryLookupStrategy = QueryLookupStrategy.Key.CREATE_IF_NOT_FOUND,
6664
includeFilters = @ComponentScan.Filter(
67-
value = AbstractJdbcRepositoryLookUpStrategyIntegrationTests.OnesRepository.class,
65+
value = AbstractJdbcRepositoryLookUpStrategyTests.OnesRepository.class,
6866
type = FilterType.ASSIGNABLE_TYPE))
6967
static class Config {
7068

7169
@Autowired JdbcRepositoryFactory factory;
7270

7371
@Bean
7472
Class<?> testClass() {
75-
return AbstractJdbcRepositoryLookUpStrategyIntegrationTests.class;
73+
return AbstractJdbcRepositoryLookUpStrategyTests.class;
7674
}
7775
}
78-
7976
}
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,25 @@
3434

3535
/**
3636
* Test to verify that <code>@EnableJdbcRepositories(queryLookupStrategy = QueryLookupStrategy.Key.CREATE)</code> works
37-
* as intended. Tests based on logic from
38-
* {@link org.springframework.data.jdbc.repository.support.JdbcQueryLookupStrategy.CreateQueryLookupStrategy}
37+
* as intended.
3938
*
4039
* @author Diego Krupitza
40+
* @author Jens Schauder
4141
*/
4242
@ContextConfiguration
4343
@Transactional
44-
@ActiveProfiles("hsql")
4544
@ExtendWith(SpringExtension.class)
46-
class JdbcRepositoryCreateLookUpStrategyIntegrationTests extends AbstractJdbcRepositoryLookUpStrategyIntegrationTests {
45+
class JdbcRepositoryCreateLookUpStrategyTests extends AbstractJdbcRepositoryLookUpStrategyTests {
4746

48-
@Test
47+
@Test // GH-1043
4948
void declaredQueryShouldWork() {
5049
onesRepository.deleteAll();
5150

52-
// here the declared query will use the dervice query which does something totally different
51+
// here the declared query will use the derived query which does something totally different
5352
callDeclaredQuery("D", 0);
5453
}
5554

56-
@Test
55+
@Test // GH-1043
5756
void derivedQueryShouldWork() {
5857
onesRepository.deleteAll();
5958
callDerivedQuery();
@@ -69,7 +68,7 @@ static class Config {
6968

7069
@Bean
7170
Class<?> testClass() {
72-
return AbstractJdbcRepositoryLookUpStrategyIntegrationTests.class;
71+
return AbstractJdbcRepositoryLookUpStrategyTests.class;
7372
}
7473
}
7574

Original file line numberDiff line numberDiff line change
@@ -18,20 +18,19 @@
1818
/**
1919
* Test to verify that
2020
* <code>@EnableJdbcRepositories(queryLookupStrategy = QueryLookupStrategy.Key.USE_DECLARED_QUERY)</code> works as
21-
* intended. Tests based on logic from
22-
* {@link org.springframework.data.jdbc.repository.support.JdbcQueryLookupStrategy.DeclaredQueryLookupStrategy}
21+
* intended.
2322
*
2423
* @author Diego Krupitza
2524
*/
26-
class JdbcRepositoryDeclaredLookUpStrategyIntegrationTests
27-
extends AbstractJdbcRepositoryLookUpStrategyIntegrationTests {
25+
class JdbcRepositoryDeclaredLookUpStrategyTests
26+
extends AbstractJdbcRepositoryLookUpStrategyTests {
2827

29-
@Test
28+
@Test // GH-1043
3029
void contextCannotByCreatedDueToFindByNameNotDeclaredQuery() {
3130

3231
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
3332

34-
context.register(JdbcRepositoryDeclaredLookUpStrategyIntegrationTests.Config.class);
33+
context.register(JdbcRepositoryDeclaredLookUpStrategyTests.Config.class);
3534

3635
assertThatThrownBy(() -> {
3736
context.refresh();
@@ -45,16 +44,15 @@ void contextCannotByCreatedDueToFindByNameNotDeclaredQuery() {
4544
@EnableJdbcRepositories(considerNestedRepositories = true,
4645
queryLookupStrategy = QueryLookupStrategy.Key.USE_DECLARED_QUERY,
4746
includeFilters = @ComponentScan.Filter(
48-
value = AbstractJdbcRepositoryLookUpStrategyIntegrationTests.OnesRepository.class,
47+
value = AbstractJdbcRepositoryLookUpStrategyTests.OnesRepository.class,
4948
type = FilterType.ASSIGNABLE_TYPE))
5049
static class Config {
5150

5251
@Autowired JdbcRepositoryFactory factory;
5352

5453
@Bean
5554
Class<?> testClass() {
56-
return AbstractJdbcRepositoryLookUpStrategyIntegrationTests.class;
55+
return AbstractJdbcRepositoryLookUpStrategyTests.class;
5756
}
5857
}
59-
6058
}

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/support/JdbcQueryLookupStrategyUnitTests.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void prefersDeclaredQuery() {
111111
verify(operations).queryForObject(eq("some SQL"), any(SqlParameterSource.class), any(RowMapper.class));
112112
}
113113

114-
@Test
114+
@Test // GH-1043
115115
void shouldFailOnMissingDeclaredQuery() {
116116

117117
RowMapper<? extends NumberFormat> numberFormatMapper = mock(RowMapper.class);
@@ -139,6 +139,7 @@ void correctLookUpStrategyForKey(QueryLookupStrategy.Key key, Class expectedClas
139139
}
140140

141141
private static Stream<Arguments> correctLookUpStrategyForKeySource() {
142+
142143
return Stream.of( //
143144
Arguments.of(QueryLookupStrategy.Key.CREATE_IF_NOT_FOUND,
144145
JdbcQueryLookupStrategy.CreateIfNotFoundQueryLookupStrategy.class), //

spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/AbstractJdbcRepositoryLookUpStrategyIntegrationTests-db2.sql

-7
This file was deleted.

spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/AbstractJdbcRepositoryLookUpStrategyIntegrationTests-h2.sql

-5
This file was deleted.

spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/AbstractJdbcRepositoryLookUpStrategyIntegrationTests-mariadb.sql

-5
This file was deleted.

spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/AbstractJdbcRepositoryLookUpStrategyIntegrationTests-mssql.sql

-7
This file was deleted.

spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/AbstractJdbcRepositoryLookUpStrategyIntegrationTests-mysql.sql

-5
This file was deleted.

spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/AbstractJdbcRepositoryLookUpStrategyIntegrationTests-oracle.sql

-7
This file was deleted.

spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/AbstractJdbcRepositoryLookUpStrategyIntegrationTests-postgres.sql

-6
This file was deleted.

0 commit comments

Comments
 (0)