Polishing.
Run tests only for a single database since it is actually not testing anything database related. Formatting. Original pull request #1187 See #1043
This commit is contained in:
@@ -136,6 +136,8 @@ public @interface EnableJdbcRepositories {
|
||||
/**
|
||||
* Returns the key of the {@link QueryLookupStrategy} to be used for lookup queries for query methods. Defaults to
|
||||
* {@link QueryLookupStrategy.Key#CREATE_IF_NOT_FOUND}.
|
||||
*
|
||||
* @since 2.1
|
||||
*/
|
||||
QueryLookupStrategy.Key queryLookupStrategy() default QueryLookupStrategy.Key.CREATE_IF_NOT_FOUND;
|
||||
}
|
||||
|
||||
@@ -99,6 +99,7 @@ abstract class JdbcQueryLookupStrategy implements QueryLookupStrategy {
|
||||
* {@link QueryLookupStrategy} to create a query from the method name.
|
||||
*
|
||||
* @author Diego Krupitza
|
||||
* @since 2.4
|
||||
*/
|
||||
static class CreateQueryLookupStrategy extends JdbcQueryLookupStrategy {
|
||||
|
||||
@@ -125,6 +126,7 @@ abstract class JdbcQueryLookupStrategy implements QueryLookupStrategy {
|
||||
* {@link org.springframework.data.jdbc.repository.query.Query} annotation followed by a JPA named query lookup.
|
||||
*
|
||||
* @author Diego Krupitza
|
||||
* @since 2.4
|
||||
*/
|
||||
static class DeclaredQueryLookupStrategy extends JdbcQueryLookupStrategy {
|
||||
|
||||
@@ -150,7 +152,7 @@ abstract class JdbcQueryLookupStrategy implements QueryLookupStrategy {
|
||||
|
||||
StringBasedJdbcQuery query = new StringBasedJdbcQuery(queryMethod, getOperations(), this::createMapper,
|
||||
getConverter());
|
||||
query.setBeanFactory(getBeanfactory());
|
||||
query.setBeanFactory(getBeanFactory());
|
||||
return query;
|
||||
}
|
||||
|
||||
@@ -163,12 +165,9 @@ abstract class JdbcQueryLookupStrategy implements QueryLookupStrategy {
|
||||
* {@link QueryLookupStrategy} to try to detect a declared query first (
|
||||
* {@link org.springframework.data.jdbc.repository.query.Query}, JDBC named query). In case none is found we fall back
|
||||
* on query creation.
|
||||
* <p>
|
||||
* Modified based on original source: {@link org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy}
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Thomas Darimont
|
||||
* @author Diego Krupitza
|
||||
* @since 2.4
|
||||
*/
|
||||
static class CreateIfNotFoundQueryLookupStrategy extends JdbcQueryLookupStrategy {
|
||||
|
||||
@@ -181,7 +180,7 @@ abstract class JdbcQueryLookupStrategy implements QueryLookupStrategy {
|
||||
* @param createStrategy must not be {@literal null}.
|
||||
* @param lookupStrategy must not be {@literal null}.
|
||||
*/
|
||||
public CreateIfNotFoundQueryLookupStrategy(ApplicationEventPublisher publisher, @Nullable EntityCallbacks callbacks,
|
||||
CreateIfNotFoundQueryLookupStrategy(ApplicationEventPublisher publisher, @Nullable EntityCallbacks callbacks,
|
||||
RelationalMappingContext context, JdbcConverter converter, Dialect dialect,
|
||||
QueryMappingConfiguration queryMappingConfiguration, NamedParameterJdbcOperations operations,
|
||||
@Nullable BeanFactory beanfactory, CreateQueryLookupStrategy createStrategy,
|
||||
@@ -228,12 +227,12 @@ abstract class JdbcQueryLookupStrategy implements QueryLookupStrategy {
|
||||
* @param dialect must not be {@literal null}
|
||||
* @param queryMappingConfiguration must not be {@literal null}
|
||||
* @param operations must not be {@literal null}
|
||||
* @param beanfactory may be {@literal null}
|
||||
* @param beanFactory may be {@literal null}
|
||||
*/
|
||||
public static QueryLookupStrategy create(@Nullable Key key, ApplicationEventPublisher publisher,
|
||||
@Nullable EntityCallbacks callbacks, RelationalMappingContext context, JdbcConverter converter, Dialect dialect,
|
||||
QueryMappingConfiguration queryMappingConfiguration, NamedParameterJdbcOperations operations,
|
||||
@Nullable BeanFactory beanfactory) {
|
||||
@Nullable BeanFactory beanFactory) {
|
||||
|
||||
Assert.notNull(publisher, "ApplicationEventPublisher must not be null");
|
||||
Assert.notNull(context, "RelationalMappingContextPublisher must not be null");
|
||||
@@ -243,10 +242,10 @@ abstract class JdbcQueryLookupStrategy implements QueryLookupStrategy {
|
||||
Assert.notNull(operations, "NamedParameterJdbcOperations must not be null");
|
||||
|
||||
CreateQueryLookupStrategy createQueryLookupStrategy = new CreateQueryLookupStrategy(publisher, callbacks, context,
|
||||
converter, dialect, queryMappingConfiguration, operations, beanfactory);
|
||||
converter, dialect, queryMappingConfiguration, operations, beanFactory);
|
||||
|
||||
DeclaredQueryLookupStrategy declaredQueryLookupStrategy = new DeclaredQueryLookupStrategy(publisher, callbacks,
|
||||
context, converter, dialect, queryMappingConfiguration, operations, beanfactory);
|
||||
context, converter, dialect, queryMappingConfiguration, operations, beanFactory);
|
||||
|
||||
Key cleanedKey = key != null ? key : Key.CREATE_IF_NOT_FOUND;
|
||||
|
||||
@@ -259,34 +258,30 @@ abstract class JdbcQueryLookupStrategy implements QueryLookupStrategy {
|
||||
return declaredQueryLookupStrategy;
|
||||
case CREATE_IF_NOT_FOUND:
|
||||
return new CreateIfNotFoundQueryLookupStrategy(publisher, callbacks, context, converter, dialect,
|
||||
queryMappingConfiguration, operations, beanfactory, createQueryLookupStrategy, declaredQueryLookupStrategy);
|
||||
queryMappingConfiguration, operations, beanFactory, createQueryLookupStrategy, declaredQueryLookupStrategy);
|
||||
default:
|
||||
throw new IllegalArgumentException(String.format("Unsupported query lookup strategy %s!", key));
|
||||
}
|
||||
}
|
||||
|
||||
protected ApplicationEventPublisher getPublisher() {
|
||||
return publisher;
|
||||
}
|
||||
|
||||
protected RelationalMappingContext getContext() {
|
||||
RelationalMappingContext getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
protected JdbcConverter getConverter() {
|
||||
JdbcConverter getConverter() {
|
||||
return converter;
|
||||
}
|
||||
|
||||
protected Dialect getDialect() {
|
||||
Dialect getDialect() {
|
||||
return dialect;
|
||||
}
|
||||
|
||||
protected NamedParameterJdbcOperations getOperations() {
|
||||
NamedParameterJdbcOperations getOperations() {
|
||||
return operations;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected BeanFactory getBeanfactory() {
|
||||
BeanFactory getBeanFactory() {
|
||||
return beanfactory;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,18 +29,19 @@ import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
|
||||
/**
|
||||
* Base class to test <code>@EnableJdbcRepositories(queryLookupStrategy = ...)</code> Tests based on logic from
|
||||
* {@link org.springframework.data.jdbc.repository.support.JdbcQueryLookupStrategy}
|
||||
* Base class to test <code>@EnableJdbcRepositories(queryLookupStrategy = ...)</code>
|
||||
*
|
||||
* @author Diego Krupitza
|
||||
* @since 2.4
|
||||
*/
|
||||
abstract class AbstractJdbcRepositoryLookUpStrategyIntegrationTests {
|
||||
abstract class AbstractJdbcRepositoryLookUpStrategyTests {
|
||||
|
||||
@Autowired protected OnesRepository onesRepository;
|
||||
@Autowired NamedParameterJdbcTemplate template;
|
||||
@Autowired RelationalMappingContext context;
|
||||
|
||||
protected void insertTestInstances() {
|
||||
void insertTestInstances() {
|
||||
|
||||
AggregateOne firstAggregate = new AggregateOne("Diego");
|
||||
AggregateOne secondAggregate = new AggregateOne("Franz");
|
||||
AggregateOne thirdAggregate = new AggregateOne("Daniela");
|
||||
@@ -48,7 +49,8 @@ abstract class AbstractJdbcRepositoryLookUpStrategyIntegrationTests {
|
||||
onesRepository.saveAll(Arrays.asList(firstAggregate, secondAggregate, thirdAggregate));
|
||||
}
|
||||
|
||||
protected void callDeclaredQuery(String name, int expectedSize, String... expectedNames) {
|
||||
void callDeclaredQuery(String name, int expectedSize, String... expectedNames) {
|
||||
|
||||
insertTestInstances();
|
||||
|
||||
List<AggregateOne> likeNameD = onesRepository.findAllByName(name);
|
||||
@@ -27,7 +27,6 @@ import org.springframework.data.jdbc.repository.config.EnableJdbcRepositories;
|
||||
import org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory;
|
||||
import org.springframework.data.jdbc.testing.TestConfiguration;
|
||||
import org.springframework.data.repository.query.QueryLookupStrategy;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -35,25 +34,24 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
/**
|
||||
* Test to verify that
|
||||
* <code>@EnableJdbcRepositories(queryLookupStrategy = QueryLookupStrategy.Key.CREATE_IF_NOT_FOUND)</code> works as
|
||||
* intended. Tests based on logic from
|
||||
* {@link org.springframework.data.jdbc.repository.support.JdbcQueryLookupStrategy.CreateIfNotFoundQueryLookupStrategy}
|
||||
* intended.
|
||||
*
|
||||
* @author Diego Krupitza
|
||||
* @author Jens Schauder
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@Transactional
|
||||
@ActiveProfiles("hsql")
|
||||
@ExtendWith(SpringExtension.class)
|
||||
class JdbcRepositoryCreateIfNotFoundLookUpStrategyIntegrationTests
|
||||
extends AbstractJdbcRepositoryLookUpStrategyIntegrationTests {
|
||||
class JdbcRepositoryCreateIfNotFoundLookUpStrategyTests
|
||||
extends AbstractJdbcRepositoryLookUpStrategyTests {
|
||||
|
||||
@Test
|
||||
@Test // GH-1043
|
||||
void declaredQueryShouldWork() {
|
||||
onesRepository.deleteAll();
|
||||
callDeclaredQuery("D", 2, "Diego", "Daniela");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test // GH-1043
|
||||
void derivedQueryShouldWork() {
|
||||
onesRepository.deleteAll();
|
||||
callDerivedQuery();
|
||||
@@ -64,7 +62,7 @@ class JdbcRepositoryCreateIfNotFoundLookUpStrategyIntegrationTests
|
||||
@EnableJdbcRepositories(considerNestedRepositories = true,
|
||||
queryLookupStrategy = QueryLookupStrategy.Key.CREATE_IF_NOT_FOUND,
|
||||
includeFilters = @ComponentScan.Filter(
|
||||
value = AbstractJdbcRepositoryLookUpStrategyIntegrationTests.OnesRepository.class,
|
||||
value = AbstractJdbcRepositoryLookUpStrategyTests.OnesRepository.class,
|
||||
type = FilterType.ASSIGNABLE_TYPE))
|
||||
static class Config {
|
||||
|
||||
@@ -72,8 +70,7 @@ class JdbcRepositoryCreateIfNotFoundLookUpStrategyIntegrationTests
|
||||
|
||||
@Bean
|
||||
Class<?> testClass() {
|
||||
return AbstractJdbcRepositoryLookUpStrategyIntegrationTests.class;
|
||||
return AbstractJdbcRepositoryLookUpStrategyTests.class;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -34,26 +34,25 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* Test to verify that <code>@EnableJdbcRepositories(queryLookupStrategy = QueryLookupStrategy.Key.CREATE)</code> works
|
||||
* as intended. Tests based on logic from
|
||||
* {@link org.springframework.data.jdbc.repository.support.JdbcQueryLookupStrategy.CreateQueryLookupStrategy}
|
||||
* as intended.
|
||||
*
|
||||
* @author Diego Krupitza
|
||||
* @author Jens Schauder
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@Transactional
|
||||
@ActiveProfiles("hsql")
|
||||
@ExtendWith(SpringExtension.class)
|
||||
class JdbcRepositoryCreateLookUpStrategyIntegrationTests extends AbstractJdbcRepositoryLookUpStrategyIntegrationTests {
|
||||
class JdbcRepositoryCreateLookUpStrategyTests extends AbstractJdbcRepositoryLookUpStrategyTests {
|
||||
|
||||
@Test
|
||||
@Test // GH-1043
|
||||
void declaredQueryShouldWork() {
|
||||
onesRepository.deleteAll();
|
||||
|
||||
// here the declared query will use the dervice query which does something totally different
|
||||
// here the declared query will use the derived query which does something totally different
|
||||
callDeclaredQuery("D", 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test // GH-1043
|
||||
void derivedQueryShouldWork() {
|
||||
onesRepository.deleteAll();
|
||||
callDerivedQuery();
|
||||
@@ -69,7 +68,7 @@ class JdbcRepositoryCreateLookUpStrategyIntegrationTests extends AbstractJdbcRep
|
||||
|
||||
@Bean
|
||||
Class<?> testClass() {
|
||||
return AbstractJdbcRepositoryLookUpStrategyIntegrationTests.class;
|
||||
return AbstractJdbcRepositoryLookUpStrategyTests.class;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,20 +18,19 @@ import org.springframework.data.repository.query.QueryLookupStrategy;
|
||||
/**
|
||||
* Test to verify that
|
||||
* <code>@EnableJdbcRepositories(queryLookupStrategy = QueryLookupStrategy.Key.USE_DECLARED_QUERY)</code> works as
|
||||
* intended. Tests based on logic from
|
||||
* {@link org.springframework.data.jdbc.repository.support.JdbcQueryLookupStrategy.DeclaredQueryLookupStrategy}
|
||||
* intended.
|
||||
*
|
||||
* @author Diego Krupitza
|
||||
*/
|
||||
class JdbcRepositoryDeclaredLookUpStrategyIntegrationTests
|
||||
extends AbstractJdbcRepositoryLookUpStrategyIntegrationTests {
|
||||
class JdbcRepositoryDeclaredLookUpStrategyTests
|
||||
extends AbstractJdbcRepositoryLookUpStrategyTests {
|
||||
|
||||
@Test
|
||||
@Test // GH-1043
|
||||
void contextCannotByCreatedDueToFindByNameNotDeclaredQuery() {
|
||||
|
||||
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
|
||||
|
||||
context.register(JdbcRepositoryDeclaredLookUpStrategyIntegrationTests.Config.class);
|
||||
context.register(JdbcRepositoryDeclaredLookUpStrategyTests.Config.class);
|
||||
|
||||
assertThatThrownBy(() -> {
|
||||
context.refresh();
|
||||
@@ -45,7 +44,7 @@ class JdbcRepositoryDeclaredLookUpStrategyIntegrationTests
|
||||
@EnableJdbcRepositories(considerNestedRepositories = true,
|
||||
queryLookupStrategy = QueryLookupStrategy.Key.USE_DECLARED_QUERY,
|
||||
includeFilters = @ComponentScan.Filter(
|
||||
value = AbstractJdbcRepositoryLookUpStrategyIntegrationTests.OnesRepository.class,
|
||||
value = AbstractJdbcRepositoryLookUpStrategyTests.OnesRepository.class,
|
||||
type = FilterType.ASSIGNABLE_TYPE))
|
||||
static class Config {
|
||||
|
||||
@@ -53,8 +52,7 @@ class JdbcRepositoryDeclaredLookUpStrategyIntegrationTests
|
||||
|
||||
@Bean
|
||||
Class<?> testClass() {
|
||||
return AbstractJdbcRepositoryLookUpStrategyIntegrationTests.class;
|
||||
return AbstractJdbcRepositoryLookUpStrategyTests.class;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -111,7 +111,7 @@ class JdbcQueryLookupStrategyUnitTests {
|
||||
verify(operations).queryForObject(eq("some SQL"), any(SqlParameterSource.class), any(RowMapper.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test // GH-1043
|
||||
void shouldFailOnMissingDeclaredQuery() {
|
||||
|
||||
RowMapper<? extends NumberFormat> numberFormatMapper = mock(RowMapper.class);
|
||||
@@ -139,6 +139,7 @@ class JdbcQueryLookupStrategyUnitTests {
|
||||
}
|
||||
|
||||
private static Stream<Arguments> correctLookUpStrategyForKeySource() {
|
||||
|
||||
return Stream.of( //
|
||||
Arguments.of(QueryLookupStrategy.Key.CREATE_IF_NOT_FOUND,
|
||||
JdbcQueryLookupStrategy.CreateIfNotFoundQueryLookupStrategy.class), //
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
DROP TABLE aggregate_one;
|
||||
|
||||
CREATE TABLE aggregate_one
|
||||
(
|
||||
id BIGINT GENERATED BY DEFAULT AS IDENTITY ( START WITH 1 ) PRIMARY KEY,
|
||||
NAME VARCHAR(100)
|
||||
);
|
||||
@@ -1,5 +0,0 @@
|
||||
CREATE TABLE aggregate_one
|
||||
(
|
||||
id BIGINT GENERATED BY DEFAULT AS IDENTITY ( START WITH 1 ) PRIMARY KEY,
|
||||
NAME VARCHAR(100)
|
||||
);
|
||||
@@ -1,5 +0,0 @@
|
||||
CREATE TABLE aggregate_one
|
||||
(
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
NAME VARCHAR(100)
|
||||
);
|
||||
@@ -1,7 +0,0 @@
|
||||
DROP TABLE IF EXISTS aggregate_one;
|
||||
|
||||
CREATE TABLE aggregate_one
|
||||
(
|
||||
id BIGINT IDENTITY PRIMARY KEY,
|
||||
NAME VARCHAR(100)
|
||||
);
|
||||
@@ -1,5 +0,0 @@
|
||||
CREATE TABLE aggregate_one
|
||||
(
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
NAME VARCHAR(100)
|
||||
);
|
||||
@@ -1,7 +0,0 @@
|
||||
DROP TABLE aggregate_one CASCADE CONSTRAINTS PURGE;
|
||||
|
||||
CREATE TABLE aggregate_one
|
||||
(
|
||||
id NUMBER GENERATED BY DEFAULT ON NULL AS IDENTITY PRIMARY KEY,
|
||||
NAME VARCHAR2(100)
|
||||
);
|
||||
@@ -1,6 +0,0 @@
|
||||
DROP TABLE aggregate_one;
|
||||
CREATE TABLE aggregate_one
|
||||
(
|
||||
id SERIAL PRIMARY KEY,
|
||||
NAME VARCHAR(100)
|
||||
);
|
||||
Reference in New Issue
Block a user