Browse Source

Fix integration tests.

See #2003
Original pull request: #2005
pull/2034/head
Mark Paluch 8 months ago
parent
commit
1f2e69452b
No known key found for this signature in database
GPG Key ID: 55BC6374BAA9D973
  1. 14
      spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryIdGenerationIntegrationTests.java
  2. 2
      spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIdGenerationIntegrationTests-db2.sql
  3. 6
      spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIdGenerationIntegrationTests-mysql.sql
  4. 2
      spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIdGenerationIntegrationTests-oracle.sql

14
spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryIdGenerationIntegrationTests.java

@ -38,15 +38,17 @@ import org.springframework.data.domain.Persistable; @@ -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; @@ -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 { @@ -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 { @@ -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 { @@ -153,6 +158,7 @@ class JdbcRepositoryIdGenerationIntegrationTests {
}
@Test // DATAJDBC-2003
@EnabledOnFeature(TestDatabaseFeatures.Feature.SUPPORTS_SEQUENCES)
void testInsertAggregateWithSequenceAndUnsetPrimitiveId() {
PrimitiveIdSeq entity = new PrimitiveIdSeq();

2
spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIdGenerationIntegrationTests-db2.sql

@ -12,4 +12,4 @@ CREATE SEQUENCE simple_seq_seq START WITH 1; @@ -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;

6
spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIdGenerationIntegrationTests-mysql.sql

@ -1,9 +1,3 @@ @@ -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;

2
spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIdGenerationIntegrationTests-oracle.sql

@ -36,4 +36,4 @@ CREATE TABLE PrimitiveIdSeq ( @@ -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;

Loading…
Cancel
Save