Browse Source

nice reproducable test with jdbc template

issue/1929-upgrade-hsql
Jens Schauder 1 year ago
parent
commit
c9ea1d3c08
No known key found for this signature in database
GPG Key ID: 74F6C554AE971567
  1. 28
      spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedWithReferenceIntegrationTests.java

28
spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedWithReferenceIntegrationTests.java

@ -20,7 +20,10 @@ import java.util.Map;
import javax.sql.DataSource; import javax.sql.DataSource;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -47,6 +50,7 @@ import org.springframework.jdbc.support.KeyHolder;
* @author Jens Schauder * @author Jens Schauder
*/ */
@IntegrationTest @IntegrationTest
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class JdbcRepositoryEmbeddedWithReferenceIntegrationTests { public class JdbcRepositoryEmbeddedWithReferenceIntegrationTests {
@Autowired NamedParameterJdbcTemplate template; @Autowired NamedParameterJdbcTemplate template;
@ -74,20 +78,26 @@ public class JdbcRepositoryEmbeddedWithReferenceIntegrationTests {
} }
@Test @Test
void batchInsertJdbcTemplate() { @Order(1)
Map<String, ?> params = Map.of("id", 4711, "test", "text1"); void jdbcTemplateOne() {
KeyHolder keyHolder = new GeneratedKeyHolder(); System.out.println("insertJdbcTemplate");
SqlParameterSource[] sqlParameterSource = new SqlParameterSource[] { new MapSqlParameterSource(params) }; insert();
template.batchUpdate("INSERT INTO \"DUMMY_ENTITY2\" (\"ID\", \"TEST\") VALUES (:id, :test)", sqlParameterSource,
keyHolder);
} }
@Test @Test
void batchInsertJdbcTemplate2() { @Order(2)
void jdbcTemplateTwo() {
System.out.println("rerunJdbcTemplate");
insert();
}
private void insert() {
Map<String, ?> params = Map.of("id", 4711, "test", "text1"); Map<String, ?> params = Map.of("id", 4711, "test", "text1");
MapSqlParameterSource sqlParameterSource = new MapSqlParameterSource(params);
SqlParameterSource[] sqlParameterSources = new SqlParameterSource[] {sqlParameterSource};
KeyHolder keyHolder = new GeneratedKeyHolder(); KeyHolder keyHolder = new GeneratedKeyHolder();
SqlParameterSource[] sqlParameterSources = new SqlParameterSource[] { new MapSqlParameterSource(params) }; template.update("INSERT INTO \"DUMMY_ENTITY2\" (\"ID\", \"TEST\") VALUES (:id, :test)", sqlParameterSource,
template.batchUpdate("INSERT INTO \"DUMMY_ENTITY2\" (\"ID\", \"TEST\") VALUES (:id, :test)", sqlParameterSources,
keyHolder); keyHolder);
} }

Loading…
Cancel
Save