From 48b037fb9b3a9c65dd0ceb2469ea41d30c0a401c Mon Sep 17 00:00:00 2001 From: Jens Schauder Date: Fri, 8 Sep 2023 12:08:24 +0200 Subject: [PATCH] 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 --- ...JdbcAggregateTemplateIntegrationTests.java | 26 +++++-------------- .../testing/HsqlDataSourceConfiguration.java | 2 +- .../data/jdbc/testing/TestConfiguration.java | 18 +++++++++++-- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/AbstractJdbcAggregateTemplateIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/AbstractJdbcAggregateTemplateIntegrationTests.java index 39e9fabec..8c2e2324c 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/AbstractJdbcAggregateTemplateIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/AbstractJdbcAggregateTemplateIntegrationTests.java @@ -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; 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; 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 { LegoSet legoSet = createLegoSet("Star Destroyer"); - @BeforeEach - void beforeEach(){ - mappingContext.setSingleQueryLoadingEnabled(useSingleQuery()); - } - - abstract boolean useSingleQuery(); - /** * creates an instance of {@link NoIdListChain4} with the following properties: *