Skip to content

Commit

Permalink
Add more unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
yanick.xia committed Sep 18, 2020
1 parent c7fe44e commit b4c53b1
Showing 1 changed file with 14 additions and 0 deletions.
Expand Up @@ -51,6 +51,8 @@ public final class ShadowPreparedStatementTest extends AbstractShardingSphereDat

private static final String SHADOW_UPDATE_SQL = "UPDATE t_encrypt SET cipher_pwd = ? WHERE id = ? AND shadow = ?";

private static final String SHADOW_UPDATE_SQL_WITH_CONDITION = "UPDATE t_encrypt SET cipher_pwd = ? WHERE id = ? AND shadow = true";

@Test
public void assertInsertWithExecute() throws SQLException {
try (PreparedStatement statement = getShadowDataSource().getConnection().prepareStatement(INSERT_SQL)) {
Expand Down Expand Up @@ -121,6 +123,18 @@ public void assertShadowUpdateWithExecuteUpdate() throws SQLException {
assertResultSet(true, 99, 1, "cipher_pwd");
}

@Test
public void assertShadowUpdateConditionWithExecuteUpdate() throws SQLException {
int result;
try (PreparedStatement statement = getShadowDataSource().getConnection().prepareStatement(SHADOW_UPDATE_SQL_WITH_CONDITION)) {
statement.setString(1, "cipher_pwd");
statement.setInt(2, 99);
result = statement.executeUpdate();
}
assertThat(result, is(1));
assertResultSet(true, 99, 1, "cipher_pwd");
}

private void assertResultSet(final boolean isShadow, final int resultSetCount, final Object cipherPwd) throws SQLException {
Map<String, DataSource> dataMaps = getDATABASE_TYPE_MAP().get(DatabaseTypes.getActualDatabaseType("H2"));
DataSource dataSource = isShadow ? dataMaps.get("jdbc_1") : dataMaps.get("jdbc_0");
Expand Down

0 comments on commit b4c53b1

Please sign in to comment.