Browse Source

Fix test setup for Single Query Loading.

The construction of the DataAccessStrategy happened before the MappingContext was properly setup.
This is now fixed.
A test utilizes Single Query Loading, if it activates the profile singleQueryLoading

Closes #1606
pull/1616/head
Jens Schauder 2 years ago
parent
commit
48b037fb9b
No known key found for this signature in database
GPG Key ID: 9537B67540F0A581
  1. 26
      spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/AbstractJdbcAggregateTemplateIntegrationTests.java
  2. 2
      spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/HsqlDataSourceConfiguration.java
  3. 18
      spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/TestConfiguration.java

26
spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/AbstractJdbcAggregateTemplateIntegrationTests.java

@ -19,6 +19,7 @@ import static java.util.Arrays.*; @@ -19,6 +19,7 @@ import static java.util.Arrays.*;
import static java.util.Collections.*;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.SoftAssertions.*;
import static org.springframework.data.jdbc.testing.TestConfiguration.*;
import static org.springframework.data.jdbc.testing.TestDatabaseFeatures.Feature.*;
import static org.springframework.test.context.TestExecutionListeners.MergeMode.*;
@ -36,7 +37,6 @@ import java.util.function.Function; @@ -36,7 +37,6 @@ import java.util.function.Function;
import java.util.stream.IntStream;
import org.assertj.core.api.SoftAssertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
@ -67,6 +67,7 @@ import org.springframework.data.relational.core.mapping.MappedCollection; @@ -67,6 +67,7 @@ import org.springframework.data.relational.core.mapping.MappedCollection;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.core.mapping.Table;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@ -99,13 +100,6 @@ abstract class AbstractJdbcAggregateTemplateIntegrationTests { @@ -99,13 +100,6 @@ abstract class AbstractJdbcAggregateTemplateIntegrationTests {
LegoSet legoSet = createLegoSet("Star Destroyer");
@BeforeEach
void beforeEach(){
mappingContext.setSingleQueryLoadingEnabled(useSingleQuery());
}
abstract boolean useSingleQuery();
/**
* creates an instance of {@link NoIdListChain4} with the following properties:
* <ul>
@ -1879,16 +1873,10 @@ abstract class AbstractJdbcAggregateTemplateIntegrationTests { @@ -1879,16 +1873,10 @@ abstract class AbstractJdbcAggregateTemplateIntegrationTests {
}
}
static class JdbcAggregateTemplateIntegrationTests extends AbstractJdbcAggregateTemplateIntegrationTests {
@Override
boolean useSingleQuery() {
return false;
}
}
static class JdbcAggregateTemplateSqlIntegrationTests extends AbstractJdbcAggregateTemplateIntegrationTests {
@Override
boolean useSingleQuery() {
return true;
}
static class JdbcAggregateTemplateIntegrationTests extends AbstractJdbcAggregateTemplateIntegrationTests { }
@ActiveProfiles(PROFILE_SINGLE_QUERY_LOADING)
static class JdbcAggregateTemplateSingleQueryLoadingIntegrationTests extends AbstractJdbcAggregateTemplateIntegrationTests {
}
}

2
spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/HsqlDataSourceConfiguration.java

@ -31,7 +31,7 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; @@ -31,7 +31,7 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
* @author Oliver Gierke
*/
@Configuration
@Profile({ "hsql", "default" })
@Profile({ "hsql", "!h2 && !mysql && !mariadb && !postgres && !oracle && !db2 && !mssql" })
class HsqlDataSourceConfiguration {
@Autowired Class<?> context;

18
spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/TestConfiguration.java

@ -31,6 +31,7 @@ import org.springframework.context.annotation.Bean; @@ -31,6 +31,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Profile;
import org.springframework.data.convert.CustomConversions;
import org.springframework.data.jdbc.core.convert.*;
import org.springframework.data.jdbc.core.dialect.JdbcDialect;
@ -67,6 +68,9 @@ import org.springframework.transaction.PlatformTransactionManager; @@ -67,6 +68,9 @@ import org.springframework.transaction.PlatformTransactionManager;
@ComponentScan // To pick up configuration classes (per activated profile)
public class TestConfiguration {
public static final String PROFILE_SINGLE_QUERY_LOADING = "singleQueryLoading";
public static final String PROFILE_NO_SINGLE_QUERY_LOADING = "!" + PROFILE_SINGLE_QUERY_LOADING;
@Autowired DataSource dataSource;
@Autowired BeanFactory beanFactory;
@Autowired ApplicationEventPublisher publisher;
@ -107,11 +111,21 @@ public class TestConfiguration { @@ -107,11 +111,21 @@ public class TestConfiguration {
new InsertStrategyFactory(template, new BatchJdbcOperations(template.getJdbcOperations()), dialect)).create();
}
@Bean
JdbcMappingContext jdbcMappingContext(Optional<NamingStrategy> namingStrategy, CustomConversions conversions) {
@Bean("jdbcMappingContext")
@Profile(PROFILE_NO_SINGLE_QUERY_LOADING)
JdbcMappingContext jdbcMappingContextWithOutSingleQueryLoading(Optional<NamingStrategy> namingStrategy, CustomConversions conversions) {
JdbcMappingContext mappingContext = new JdbcMappingContext(namingStrategy.orElse(DefaultNamingStrategy.INSTANCE));
mappingContext.setSimpleTypeHolder(conversions.getSimpleTypeHolder());
return mappingContext;
}
@Bean("jdbcMappingContext")
@Profile(PROFILE_SINGLE_QUERY_LOADING)
JdbcMappingContext jdbcMappingContextWithSingleQueryLoading(Optional<NamingStrategy> namingStrategy, CustomConversions conversions) {
JdbcMappingContext mappingContext = new JdbcMappingContext(namingStrategy.orElse(DefaultNamingStrategy.INSTANCE));
mappingContext.setSimpleTypeHolder(conversions.getSimpleTypeHolder());
mappingContext.setSingleQueryLoadingEnabled(true);
return mappingContext;
}

Loading…
Cancel
Save