Polishing
This commit is contained in:
parent
e57b942b4d
commit
a803206d5f
|
@ -36,6 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*
|
*
|
||||||
* @author Sam Brannen
|
* @author Sam Brannen
|
||||||
* @since 6.1
|
* @since 6.1
|
||||||
|
* @see SimpleJdbcInsertTests
|
||||||
*/
|
*/
|
||||||
class SimpleJdbcInsertIntegrationTests {
|
class SimpleJdbcInsertIntegrationTests {
|
||||||
|
|
||||||
|
@ -81,7 +82,7 @@ class SimpleJdbcInsertIntegrationTests {
|
||||||
insertJaneSmith(insert);
|
insertJaneSmith(insert);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // gh-24013
|
@Test // gh-24013
|
||||||
void usingColumnsAndQuotedIdentifiers() throws Exception {
|
void usingColumnsAndQuotedIdentifiers() throws Exception {
|
||||||
SimpleJdbcInsert insert = new SimpleJdbcInsert(embeddedDatabase)
|
SimpleJdbcInsert insert = new SimpleJdbcInsert(embeddedDatabase)
|
||||||
.withTableName("users")
|
.withTableName("users")
|
||||||
|
@ -90,7 +91,9 @@ class SimpleJdbcInsertIntegrationTests {
|
||||||
|
|
||||||
insert.compile();
|
insert.compile();
|
||||||
// NOTE: quoted identifiers in H2/HSQL will be UPPERCASE!
|
// NOTE: quoted identifiers in H2/HSQL will be UPPERCASE!
|
||||||
assertThat(insert.getInsertString()).isEqualTo("INSERT INTO \"USERS\" (\"FIRST_NAME\", \"LAST_NAME\") VALUES(?, ?)");
|
assertThat(insert.getInsertString()).isEqualToIgnoringNewLines("""
|
||||||
|
INSERT INTO "USERS" ("FIRST_NAME", "LAST_NAME") VALUES(?, ?)
|
||||||
|
""");
|
||||||
|
|
||||||
insertJaneSmith(insert);
|
insertJaneSmith(insert);
|
||||||
}
|
}
|
||||||
|
@ -123,7 +126,7 @@ class SimpleJdbcInsertIntegrationTests {
|
||||||
insertJaneSmith(insert);
|
insertJaneSmith(insert);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // gh-24013
|
@Test // gh-24013
|
||||||
void usingColumnsAndQuotedIdentifiersWithSchemaName() throws Exception {
|
void usingColumnsAndQuotedIdentifiersWithSchemaName() throws Exception {
|
||||||
SimpleJdbcInsert insert = new SimpleJdbcInsert(embeddedDatabase)
|
SimpleJdbcInsert insert = new SimpleJdbcInsert(embeddedDatabase)
|
||||||
.withSchemaName("my_schema")
|
.withSchemaName("my_schema")
|
||||||
|
@ -133,7 +136,9 @@ class SimpleJdbcInsertIntegrationTests {
|
||||||
|
|
||||||
insert.compile();
|
insert.compile();
|
||||||
// NOTE: quoted identifiers in H2/HSQL will be UPPERCASE!
|
// NOTE: quoted identifiers in H2/HSQL will be UPPERCASE!
|
||||||
assertThat(insert.getInsertString()).isEqualTo("INSERT INTO \"MY_SCHEMA\".\"USERS\" (\"FIRST_NAME\", \"LAST_NAME\") VALUES(?, ?)");
|
assertThat(insert.getInsertString()).isEqualToIgnoringNewLines("""
|
||||||
|
INSERT INTO "MY_SCHEMA"."USERS" ("FIRST_NAME", "LAST_NAME") VALUES(?, ?)
|
||||||
|
""");
|
||||||
|
|
||||||
insertJaneSmith(insert);
|
insertJaneSmith(insert);
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,10 +38,11 @@ import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mock object based tests for {@link SimpleJdbcInsert}.
|
* Mock-based tests for {@link SimpleJdbcInsert}.
|
||||||
*
|
*
|
||||||
* @author Thomas Risberg
|
* @author Thomas Risberg
|
||||||
* @author Sam Brannen
|
* @author Sam Brannen
|
||||||
|
* @see SimpleJdbcInsertIntegrationTests
|
||||||
*/
|
*/
|
||||||
class SimpleJdbcInsertTests {
|
class SimpleJdbcInsertTests {
|
||||||
|
|
||||||
|
@ -64,6 +65,18 @@ class SimpleJdbcInsertTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void missingTableName() throws Exception {
|
||||||
|
SimpleJdbcInsert insert = new SimpleJdbcInsert(dataSource);
|
||||||
|
|
||||||
|
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)
|
||||||
|
.isThrownBy(insert::compile)
|
||||||
|
.withMessage("Table name is required");
|
||||||
|
|
||||||
|
// Appease the @AfterEach checks.
|
||||||
|
connection.close();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method does not test any functionality but rather only that
|
* This method does not test any functionality but rather only that
|
||||||
* configuration methods can be chained without compiler errors.
|
* configuration methods can be chained without compiler errors.
|
||||||
|
@ -100,8 +113,8 @@ class SimpleJdbcInsertTests {
|
||||||
SimpleJdbcInsert insert = new SimpleJdbcInsert(dataSource).withTableName("x");
|
SimpleJdbcInsert insert = new SimpleJdbcInsert(dataSource).withTableName("x");
|
||||||
// Shouldn't succeed in inserting into table which doesn't exist
|
// Shouldn't succeed in inserting into table which doesn't exist
|
||||||
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)
|
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)
|
||||||
.isThrownBy(() -> insert.execute(Collections.emptyMap()))
|
.isThrownBy(() -> insert.execute(Collections.emptyMap()))
|
||||||
.withMessageStartingWith("Unable to locate columns for table 'x' so an insert statement can't be generated");
|
.withMessageStartingWith("Unable to locate columns for table 'x' so an insert statement can't be generated");
|
||||||
|
|
||||||
verify(resultSet).close();
|
verify(resultSet).close();
|
||||||
}
|
}
|
||||||
|
@ -152,9 +165,9 @@ class SimpleJdbcInsertTests {
|
||||||
SimpleJdbcInsert insert = new SimpleJdbcInsert(dataSource).withTableName("me");
|
SimpleJdbcInsert insert = new SimpleJdbcInsert(dataSource).withTableName("me");
|
||||||
|
|
||||||
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)
|
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)
|
||||||
.isThrownBy(insert::compile)
|
.isThrownBy(insert::compile)
|
||||||
.withMessage("Unable to locate columns for table 'me' so an insert statement can't be generated. " +
|
.withMessage("Unable to locate columns for table 'me' so an insert statement can't be generated. " +
|
||||||
"Consider specifying explicit column names -- for example, via SimpleJdbcInsert#usingColumns().");
|
"Consider specifying explicit column names -- for example, via SimpleJdbcInsert#usingColumns().");
|
||||||
|
|
||||||
verify(columnResultSet).close();
|
verify(columnResultSet).close();
|
||||||
verify(tableResultSet).close();
|
verify(tableResultSet).close();
|
||||||
|
|
Loading…
Reference in New Issue