diff --git a/build.gradle b/build.gradle index 6d02ba3f66..ec5adec010 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,7 @@ configure(allprojects) { project -> ext.aspectjVersion = "1.8.0.M1" ext.groovyVersion = "1.8.9" - ext.hsqldbVersion = "1.8.0.10" + ext.hsqldbVersion = "2.3.1" ext.junitVersion = "4.11" ext.slf4jVersion = "1.6.1" ext.jettyVersion = "9.1.0.v20131115" @@ -495,7 +495,7 @@ project("spring-jdbc") { optional(project(":spring-context")) // for JndiDataSourceLookup compile(project(":spring-tx")) optional("c3p0:c3p0:0.9.1.2") - optional("hsqldb:hsqldb:${hsqldbVersion}") + optional("org.hsqldb:hsqldb:${hsqldbVersion}") optional("com.h2database:h2:1.0.71") optional("org.apache.derby:derby:10.5.3.0_1") optional("org.apache.derby:derbyclient:10.5.3.0_1") @@ -528,7 +528,7 @@ project("spring-context-support") { testCompile("org.apache.poi:poi:3.9") testCompile("commons-beanutils:commons-beanutils:1.8.0") // for Velocity/JasperReports testCompile("commons-digester:commons-digester:1.8.1") // for Velocity/JasperReports - testCompile("hsqldb:hsqldb:${hsqldbVersion}") + testCompile("org.hsqldb:hsqldb:${hsqldbVersion}") } // pick up **/*.types files in src/main @@ -622,7 +622,7 @@ project("spring-orm") { provided("javax.servlet:javax.servlet-api:3.0.1") testCompile("org.slf4j:slf4j-jcl:${slf4jVersion}") testCompile("commons-dbcp:commons-dbcp:1.2.2") - testCompile("hsqldb:hsqldb:${hsqldbVersion}") + testCompile("org.hsqldb:hsqldb:${hsqldbVersion}") compile(project(":spring-core")) compile(project(":spring-beans")) optional(project(":spring-aop")) @@ -790,7 +790,7 @@ project("spring-test") { testCompile(project(":spring-webmvc-tiles3")) testCompile("org.hibernate:hibernate-core:3.6.9.Final") testCompile "org.slf4j:slf4j-jcl:${slf4jVersion}" - testCompile("hsqldb:hsqldb:${hsqldbVersion}") + testCompile("org.hsqldb:hsqldb:${hsqldbVersion}") testCompile("org.hibernate:hibernate-validator:4.3.0.Final") testCompile("org.codehaus.jackson:jackson-mapper-asl:1.9.12") testCompile("com.fasterxml.jackson.core:jackson-databind:2.2.2") @@ -918,7 +918,7 @@ configure(rootProject) { testCompile("javax.inject:javax.inject:1") testCompile("javax.resource:connector-api:1.5") testCompile("org.aspectj:aspectjweaver:${aspectjVersion}") - testCompile("hsqldb:hsqldb:${hsqldbVersion}") + testCompile("org.hsqldb:hsqldb:${hsqldbVersion}") } task api(type: Javadoc) { diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/DatabasePopulatorTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/DatabasePopulatorTests.java index 64f09cc77c..68f33bcf82 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/DatabasePopulatorTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/DatabasePopulatorTests.java @@ -28,6 +28,8 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.transaction.support.TransactionSynchronizationManager; +import static org.hamcrest.Matchers.*; + import static org.junit.Assert.*; import static org.mockito.BDDMockito.*; @@ -59,8 +61,9 @@ public class DatabasePopulatorTests { private void assertUsersDatabaseCreated(String... lastNames) { for (String lastName : lastNames) { - assertEquals("Did not find user with last name [" + lastName + "].", 1, - jdbcTemplate.queryForInt("select count(0) from users where last_name = ?", lastName)); + assertThat("Did not find user with last name [" + lastName + "].", + jdbcTemplate.queryForObject("select count(0) from users where last_name = ?", Integer.class, lastName), + equalTo(1)); } } @@ -131,8 +134,8 @@ public class DatabasePopulatorTests { connection.close(); } - assertEquals(1, jdbcTemplate.queryForInt("select COUNT(NAME) from T_TEST where NAME='Keith'")); - assertEquals(1, jdbcTemplate.queryForInt("select COUNT(NAME) from T_TEST where NAME='Dave'")); + assertThat(jdbcTemplate.queryForObject("select COUNT(NAME) from T_TEST where NAME='Keith'", Integer.class), equalTo(1)); + assertThat(jdbcTemplate.queryForObject("select COUNT(NAME) from T_TEST where NAME='Dave'", Integer.class), equalTo(1)); } @Test @@ -148,8 +151,8 @@ public class DatabasePopulatorTests { connection.close(); } - assertEquals(1, jdbcTemplate.queryForInt("select COUNT(NAME) from T_TEST where NAME='Keith'")); - assertEquals(1, jdbcTemplate.queryForInt("select COUNT(NAME) from T_TEST where NAME='Dave'")); + assertThat(jdbcTemplate.queryForObject("select COUNT(NAME) from T_TEST where NAME='Keith'", Integer.class), equalTo(1)); + assertThat(jdbcTemplate.queryForObject("select COUNT(NAME) from T_TEST where NAME='Dave'", Integer.class), equalTo(1)); } @Test @@ -165,8 +168,8 @@ public class DatabasePopulatorTests { connection.close(); } - assertEquals(1, jdbcTemplate.queryForInt("select COUNT(NAME) from T_TEST where NAME='Keith'")); - assertEquals(1, jdbcTemplate.queryForInt("select COUNT(NAME) from T_TEST where NAME='Dave'")); + assertThat(jdbcTemplate.queryForObject("select COUNT(NAME) from T_TEST where NAME='Keith'", Integer.class), equalTo(1)); + assertThat(jdbcTemplate.queryForObject("select COUNT(NAME) from T_TEST where NAME='Dave'", Integer.class), equalTo(1)); } @Test @@ -181,8 +184,8 @@ public class DatabasePopulatorTests { connection.close(); } - assertEquals(1, jdbcTemplate.queryForInt("select COUNT(NAME) from T_TEST where NAME='Keith'")); - assertEquals(1, jdbcTemplate.queryForInt("select COUNT(NAME) from T_TEST where NAME='Dave'")); + assertThat(jdbcTemplate.queryForObject("select COUNT(NAME) from T_TEST where NAME='Keith'", Integer.class), equalTo(1)); + assertThat(jdbcTemplate.queryForObject("select COUNT(NAME) from T_TEST where NAME='Dave'", Integer.class), equalTo(1)); } @Test @@ -198,8 +201,8 @@ public class DatabasePopulatorTests { connection.close(); } - assertEquals(1, jdbcTemplate.queryForInt("select COUNT(NAME) from T_TEST where NAME='Keith'")); - assertEquals(1, jdbcTemplate.queryForInt("select COUNT(NAME) from T_TEST where NAME='Dave'")); + assertThat(jdbcTemplate.queryForObject("select COUNT(NAME) from T_TEST where NAME='Keith'", Integer.class), equalTo(1)); + assertThat(jdbcTemplate.queryForObject("select COUNT(NAME) from T_TEST where NAME='Dave'", Integer.class), equalTo(1)); } @Test @@ -244,8 +247,8 @@ public class DatabasePopulatorTests { connection.close(); } - assertEquals(1, jdbcTemplate.queryForInt("select COUNT(NAME) from T_TEST where NAME='Keith'")); - assertEquals(1, jdbcTemplate.queryForInt("select COUNT(NAME) from T_TEST where NAME='Dave'")); + assertThat(jdbcTemplate.queryForObject("select COUNT(NAME) from T_TEST where NAME='Keith'", Integer.class), equalTo(1)); + assertThat(jdbcTemplate.queryForObject("select COUNT(NAME) from T_TEST where NAME='Dave'", Integer.class), equalTo(1)); } /** diff --git a/spring-jdbc/src/test/resources/org/springframework/jdbc/datasource/init/users-schema.sql b/spring-jdbc/src/test/resources/org/springframework/jdbc/datasource/init/users-schema.sql index 73975e9245..80ffe23da9 100644 --- a/spring-jdbc/src/test/resources/org/springframework/jdbc/datasource/init/users-schema.sql +++ b/spring-jdbc/src/test/resources/org/springframework/jdbc/datasource/init/users-schema.sql @@ -1,7 +1,7 @@ DROP TABLE users IF EXISTS; CREATE TABLE users ( - id INTEGER NOT NULL IDENTITY PRIMARY KEY, + id INTEGER NOT NULL IDENTITY, first_name VARCHAR(50) NOT NULL, last_name VARCHAR(50) NOT NULL ); diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryIntegrationTests.java b/spring-orm/src/test/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryIntegrationTests.java index 66c93e0a41..84ac09fd5f 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryIntegrationTests.java +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryIntegrationTests.java @@ -16,6 +16,9 @@ package org.springframework.orm.jpa; +import javax.persistence.EntityManager; +import javax.persistence.Query; + import org.springframework.test.jpa.AbstractJpaTests; import org.springframework.transaction.support.TransactionSynchronizationManager; @@ -81,6 +84,10 @@ public abstract class AbstractEntityManagerFactoryIntegrationTests extends Abstr assertFalse(TransactionSynchronizationManager.isActualTransactionActive()); } + protected int countRowsInTable(EntityManager em, String tableName) { + Query query = em.createNativeQuery("SELECT COUNT(0) FROM " + tableName); + return ((Number) query.getSingleResult()).intValue(); + }; public enum Provider { ECLIPSELINK, HIBERNATE, OPENJPA diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/ApplicationManagedEntityManagerIntegrationTests.java b/spring-orm/src/test/java/org/springframework/orm/jpa/ApplicationManagedEntityManagerIntegrationTests.java index 920099caf9..d98197ff67 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/ApplicationManagedEntityManagerIntegrationTests.java +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/ApplicationManagedEntityManagerIntegrationTests.java @@ -93,7 +93,7 @@ public class ApplicationManagedEntityManagerIntegrationTests extends AbstractEnt em.persist(p); em.flush(); - assertEquals("1 row must have been inserted", 1, countRowsInTable("person")); + assertEquals("1 row must have been inserted", 1, countRowsInTable(em, "person")); } public void testStateClean() { @@ -122,14 +122,14 @@ public class ApplicationManagedEntityManagerIntegrationTests extends AbstractEnt setComplete(); endTransaction(); // Should rollback assertEquals("Tx must have committed back", - 1, countRowsInTable("person")); + 1, countRowsInTable(em, "person")); // Now clean up the database startNewTransaction(); em.joinTransaction(); deleteAllPeopleUsingEntityManager(em); assertEquals("People have been killed", - 0, countRowsInTable("person")); + 0, countRowsInTable(em, "person")); setComplete(); } @@ -143,7 +143,7 @@ public class ApplicationManagedEntityManagerIntegrationTests extends AbstractEnt doInstantiateAndSave(em); endTransaction(); // Should rollback assertEquals("Tx must have been rolled back", - 0, countRowsInTable("person")); + 0, countRowsInTable(em, "person")); } public void testCommitOccurs() { @@ -154,7 +154,7 @@ public class ApplicationManagedEntityManagerIntegrationTests extends AbstractEnt setComplete(); endTransaction(); // Should rollback assertEquals("Tx must have committed back", - 1, countRowsInTable("person")); + 1, countRowsInTable(em, "person")); // Now clean up the database deleteFromTables(new String[] { "person" }); diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/ContainerManagedEntityManagerIntegrationTests.java b/spring-orm/src/test/java/org/springframework/orm/jpa/ContainerManagedEntityManagerIntegrationTests.java index 04a4058711..844f41bdbc 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/ContainerManagedEntityManagerIntegrationTests.java +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/ContainerManagedEntityManagerIntegrationTests.java @@ -105,7 +105,7 @@ public class ContainerManagedEntityManagerIntegrationTests extends AbstractEntit public void doInstantiateAndSave(EntityManager em) { assertEquals("Should be no people from previous transactions", - 0, countRowsInTable("person")); + 0, countRowsInTable(em, "person")); Person p = new Person(); p.setFirstName("Tony"); @@ -113,7 +113,7 @@ public class ContainerManagedEntityManagerIntegrationTests extends AbstractEntit em.persist(p); em.flush(); - assertEquals("1 row must have been inserted", 1, countRowsInTable("person")); + assertEquals("1 row must have been inserted", 1, countRowsInTable(em, "person")); } public void testReuseInNewTransaction() { @@ -132,7 +132,7 @@ public class ContainerManagedEntityManagerIntegrationTests extends AbstractEntit setComplete(); endTransaction(); // Should rollback assertEquals("Tx must have committed back", - 1, countRowsInTable("person")); + 1, countRowsInTable(em, "person")); // Now clean up the database deleteFromTables(new String[] { "person" }); @@ -143,7 +143,7 @@ public class ContainerManagedEntityManagerIntegrationTests extends AbstractEntit doInstantiateAndSave(em); endTransaction(); // Should rollback assertEquals("Tx must have been rolled back", - 0, countRowsInTable("person")); + 0, countRowsInTable(em, "person")); } public void testCommitOccurs() { @@ -152,7 +152,7 @@ public class ContainerManagedEntityManagerIntegrationTests extends AbstractEntit setComplete(); endTransaction(); // Should rollback assertEquals("Tx must have committed back", - 1, countRowsInTable("person")); + 1, countRowsInTable(em, "person")); // Now clean up the database deleteFromTables(new String[] { "person" }); diff --git a/spring-orm/src/test/java/org/springframework/test/AbstractTransactionalDataSourceSpringContextTests.java b/spring-orm/src/test/java/org/springframework/test/AbstractTransactionalDataSourceSpringContextTests.java index a3aa264cec..dcd60ae78c 100644 --- a/spring-orm/src/test/java/org/springframework/test/AbstractTransactionalDataSourceSpringContextTests.java +++ b/spring-orm/src/test/java/org/springframework/test/AbstractTransactionalDataSourceSpringContextTests.java @@ -134,7 +134,7 @@ public abstract class AbstractTransactionalDataSourceSpringContextTests * @return the number of rows in the table */ protected int countRowsInTable(String tableName) { - return this.jdbcTemplate.queryForInt("SELECT COUNT(0) FROM " + tableName); + return this.jdbcTemplate.queryForObject("SELECT COUNT(0) FROM " + tableName, Integer.class); } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/orm/HibernateSessionFlushingTests.java b/spring-test/src/test/java/org/springframework/test/context/junit4/orm/HibernateSessionFlushingTests.java index 69aecb723b..7485bb817a 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/orm/HibernateSessionFlushingTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/junit4/orm/HibernateSessionFlushingTests.java @@ -109,7 +109,7 @@ public class HibernateSessionFlushingTests extends AbstractTransactionalJUnit4Sp // finally flushed (i.e., in production code) } - @Test(expected = GenericJDBCException.class) + @Test(expected = ConstraintViolationException.class) public void updateSamWithNullDriversLicenseWithSessionFlush() { updateSamWithNullDriversLicense(); // Manual flush is required to avoid false positive in test diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/orm/db-schema.sql b/spring-test/src/test/java/org/springframework/test/context/junit4/orm/db-schema.sql index 960b101e7f..3dee075af5 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/orm/db-schema.sql +++ b/spring-test/src/test/java/org/springframework/test/context/junit4/orm/db-schema.sql @@ -2,7 +2,7 @@ DROP TABLE drivers_license IF EXISTS; DROP TABLE person IF EXISTS; CREATE TABLE person ( - id INTEGER NOT NULL IDENTITY PRIMARY KEY, + id INTEGER NOT NULL IDENTITY, name VARCHAR(50) NOT NULL, drivers_license_id INTEGER NOT NULL ); @@ -10,7 +10,7 @@ CREATE UNIQUE INDEX person_name ON person(name); CREATE UNIQUE INDEX person_drivers_license_id ON person(drivers_license_id); CREATE TABLE drivers_license ( - id INTEGER NOT NULL IDENTITY PRIMARY KEY, + id INTEGER NOT NULL IDENTITY, license_number INTEGER NOT NULL ); CREATE UNIQUE INDEX drivers_license_license_number ON drivers_license(license_number); diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/spr8849/spr8849-schema.sql b/spring-test/src/test/java/org/springframework/test/context/junit4/spr8849/spr8849-schema.sql index a17d13a9d9..da1ce4b8c9 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/spr8849/spr8849-schema.sql +++ b/spring-test/src/test/java/org/springframework/test/context/junit4/spr8849/spr8849-schema.sql @@ -1,3 +1,3 @@ CREATE TABLE enigma ( - id INTEGER NOT NULL IDENTITY PRIMARY KEY + id INTEGER NOT NULL IDENTITY );