Fix integration tests.

See #2003
Original pull request: #2005
This commit is contained in:
Mark Paluch
2025-04-09 12:25:54 +02:00
parent e27a05880f
commit 1f2e69452b
4 changed files with 12 additions and 12 deletions

View File

@@ -38,15 +38,17 @@ import org.springframework.data.domain.Persistable;
import org.springframework.data.jdbc.core.convert.IdGeneratingEntityCallback;
import org.springframework.data.jdbc.repository.config.EnableJdbcRepositories;
import org.springframework.data.jdbc.repository.support.SimpleJdbcRepository;
import org.springframework.data.jdbc.testing.EnabledOnFeature;
import org.springframework.data.jdbc.testing.IntegrationTest;
import org.springframework.data.jdbc.testing.TestConfiguration;
import org.springframework.data.jdbc.testing.TestDatabaseFeatures;
import org.springframework.data.relational.core.conversion.MutableAggregateChange;
import org.springframework.data.relational.core.mapping.NamingStrategy;
import org.springframework.data.relational.core.mapping.Sequence;
import org.springframework.data.relational.core.mapping.event.BeforeConvertCallback;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.ListCrudRepository;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
/**
* Testing special cases for id generation with {@link SimpleJdbcRepository}.
@@ -59,6 +61,7 @@ import org.springframework.test.context.jdbc.Sql;
@IntegrationTest
class JdbcRepositoryIdGenerationIntegrationTests {
@Autowired NamedParameterJdbcOperations operations;
@Autowired ReadOnlyIdEntityRepository readOnlyIdRepository;
@Autowired PrimitiveIdEntityRepository primitiveIdRepository;
@Autowired ImmutableWithManualIdEntityRepository immutableWithManualIdEntityRepository;
@@ -123,9 +126,11 @@ class JdbcRepositoryIdGenerationIntegrationTests {
}
@Test // DATAJDBC-2003
@Sql(statements = "INSERT INTO SimpleSeq(id, name) VALUES(1, 'initial value');")
@EnabledOnFeature(TestDatabaseFeatures.Feature.SUPPORTS_SEQUENCES)
void testUpdateAggregateWithSequence() {
operations.getJdbcOperations().update("INSERT INTO SimpleSeq(id, name) VALUES(1, 'initial value')");
SimpleSeq entity = new SimpleSeq();
entity.id = 1L;
entity.name = "New name";
@@ -137,8 +142,8 @@ class JdbcRepositoryIdGenerationIntegrationTests {
assertThat(afterCallback.join().id).isEqualTo(1L);
}
@Test
// DATAJDBC-2003
@Test // DATAJDBC-2003
@EnabledOnFeature(TestDatabaseFeatures.Feature.SUPPORTS_SEQUENCES)
void testInsertPersistableAggregateWithSequenceClientIdIsFavored() {
long initialId = 1L;
@@ -153,6 +158,7 @@ class JdbcRepositoryIdGenerationIntegrationTests {
}
@Test // DATAJDBC-2003
@EnabledOnFeature(TestDatabaseFeatures.Feature.SUPPORTS_SEQUENCES)
void testInsertAggregateWithSequenceAndUnsetPrimitiveId() {
PrimitiveIdSeq entity = new PrimitiveIdSeq();

View File

@@ -12,4 +12,4 @@ CREATE SEQUENCE simple_seq_seq START WITH 1;
CREATE TABLE PersistableSeq (ID BIGINT NOT NULL PRIMARY KEY, NAME VARCHAR(100));
CREATE SEQUENCE persistable_seq_seq START WITH 1;
CREATE TABLE PrimitiveIdSeq (ID BIGINT NOT NULL PRIMARY KEY, NAME VARCHAR(100));
CREATE SEQUENCE primitive_seq_seq START WITH 1;
CREATE SEQUENCE "primitive_seq_seq" START WITH 1;

View File

@@ -1,9 +1,3 @@
CREATE TABLE ReadOnlyIdEntity (ID BIGINT AUTO_INCREMENT PRIMARY KEY, NAME VARCHAR(100));
CREATE TABLE PrimitiveIdEntity (ID BIGINT AUTO_INCREMENT PRIMARY KEY, NAME VARCHAR(100));
CREATE TABLE ImmutableWithManualIdentity (ID BIGINT PRIMARY KEY, NAME VARCHAR(100));
CREATE TABLE SimpleSeq (ID BIGINT NOT NULL PRIMARY KEY, NAME VARCHAR(100));
CREATE SEQUENCE simple_seq_seq START WITH 1;
CREATE TABLE PersistableSeq (ID BIGINT NOT NULL PRIMARY KEY, NAME VARCHAR(100));
CREATE SEQUENCE persistable_seq_seq START WITH 1;
CREATE TABLE PrimitiveIdSeq (ID BIGINT NOT NULL PRIMARY KEY, NAME VARCHAR(100));
CREATE SEQUENCE primitive_seq_seq START WITH 1;

View File

@@ -36,4 +36,4 @@ CREATE TABLE PrimitiveIdSeq (
NAME VARCHAR2(100)
);
CREATE SEQUENCE primitive_seq_seq START WITH 1;
CREATE SEQUENCE "primitive_seq_seq" START WITH 1;