Skip to content

Commit 571fd96

Browse files
committed
Fix integration tests.
See #2003 Original pull request: #2005
1 parent e27a058 commit 571fd96

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

Diff for: spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryIdGenerationIntegrationTests.java

+10-4
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,17 @@
3838
import org.springframework.data.jdbc.core.convert.IdGeneratingEntityCallback;
3939
import org.springframework.data.jdbc.repository.config.EnableJdbcRepositories;
4040
import org.springframework.data.jdbc.repository.support.SimpleJdbcRepository;
41+
import org.springframework.data.jdbc.testing.EnabledOnFeature;
4142
import org.springframework.data.jdbc.testing.IntegrationTest;
4243
import org.springframework.data.jdbc.testing.TestConfiguration;
44+
import org.springframework.data.jdbc.testing.TestDatabaseFeatures;
4345
import org.springframework.data.relational.core.conversion.MutableAggregateChange;
4446
import org.springframework.data.relational.core.mapping.NamingStrategy;
4547
import org.springframework.data.relational.core.mapping.Sequence;
4648
import org.springframework.data.relational.core.mapping.event.BeforeConvertCallback;
4749
import org.springframework.data.repository.CrudRepository;
4850
import org.springframework.data.repository.ListCrudRepository;
49-
import org.springframework.test.context.jdbc.Sql;
51+
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
5052

5153
/**
5254
* Testing special cases for id generation with {@link SimpleJdbcRepository}.
@@ -59,6 +61,7 @@
5961
@IntegrationTest
6062
class JdbcRepositoryIdGenerationIntegrationTests {
6163

64+
@Autowired NamedParameterJdbcOperations operations;
6265
@Autowired ReadOnlyIdEntityRepository readOnlyIdRepository;
6366
@Autowired PrimitiveIdEntityRepository primitiveIdRepository;
6467
@Autowired ImmutableWithManualIdEntityRepository immutableWithManualIdEntityRepository;
@@ -123,9 +126,11 @@ void manuallyGeneratedIdForSaveAll() {
123126
}
124127

125128
@Test // DATAJDBC-2003
126-
@Sql(statements = "INSERT INTO SimpleSeq(id, name) VALUES(1, 'initial value');")
129+
@EnabledOnFeature(TestDatabaseFeatures.Feature.SUPPORTS_SEQUENCES)
127130
void testUpdateAggregateWithSequence() {
128131

132+
operations.getJdbcOperations().update("INSERT INTO SimpleSeq(id, name) VALUES(1, 'initial value')");
133+
129134
SimpleSeq entity = new SimpleSeq();
130135
entity.id = 1L;
131136
entity.name = "New name";
@@ -137,8 +142,8 @@ void testUpdateAggregateWithSequence() {
137142
assertThat(afterCallback.join().id).isEqualTo(1L);
138143
}
139144

140-
@Test
141-
// DATAJDBC-2003
145+
@Test // DATAJDBC-2003
146+
@EnabledOnFeature(TestDatabaseFeatures.Feature.SUPPORTS_SEQUENCES)
142147
void testInsertPersistableAggregateWithSequenceClientIdIsFavored() {
143148

144149
long initialId = 1L;
@@ -153,6 +158,7 @@ void testInsertPersistableAggregateWithSequenceClientIdIsFavored() {
153158
}
154159

155160
@Test // DATAJDBC-2003
161+
@EnabledOnFeature(TestDatabaseFeatures.Feature.SUPPORTS_SEQUENCES)
156162
void testInsertAggregateWithSequenceAndUnsetPrimitiveId() {
157163

158164
PrimitiveIdSeq entity = new PrimitiveIdSeq();

Diff for: spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIdGenerationIntegrationTests-db2.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ CREATE SEQUENCE simple_seq_seq START WITH 1;
1212
CREATE TABLE PersistableSeq (ID BIGINT NOT NULL PRIMARY KEY, NAME VARCHAR(100));
1313
CREATE SEQUENCE persistable_seq_seq START WITH 1;
1414
CREATE TABLE PrimitiveIdSeq (ID BIGINT NOT NULL PRIMARY KEY, NAME VARCHAR(100));
15-
CREATE SEQUENCE primitive_seq_seq START WITH 1;
15+
CREATE SEQUENCE "primitive_seq_seq" START WITH 1;
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
11
CREATE TABLE ReadOnlyIdEntity (ID BIGINT AUTO_INCREMENT PRIMARY KEY, NAME VARCHAR(100));
22
CREATE TABLE PrimitiveIdEntity (ID BIGINT AUTO_INCREMENT PRIMARY KEY, NAME VARCHAR(100));
33
CREATE TABLE ImmutableWithManualIdentity (ID BIGINT PRIMARY KEY, NAME VARCHAR(100));
4-
CREATE TABLE SimpleSeq (ID BIGINT NOT NULL PRIMARY KEY, NAME VARCHAR(100));
5-
CREATE SEQUENCE simple_seq_seq START WITH 1;
6-
CREATE TABLE PersistableSeq (ID BIGINT NOT NULL PRIMARY KEY, NAME VARCHAR(100));
7-
CREATE SEQUENCE persistable_seq_seq START WITH 1;
8-
CREATE TABLE PrimitiveIdSeq (ID BIGINT NOT NULL PRIMARY KEY, NAME VARCHAR(100));
9-
CREATE SEQUENCE primitive_seq_seq START WITH 1;

0 commit comments

Comments
 (0)