Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try with resources implementation in JUnit FW - Part 1 #520

Merged
merged 8 commits into from
Oct 10, 2017
2,227 changes: 1,110 additions & 1,117 deletions src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -512,68 +512,46 @@ public void testNumericNormalization() throws SQLException {
private void testChar(SQLServerStatement stmt,
String[] values) throws SQLException {
String sql = "select * from " + charTable;
SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting);
ResultSet rs = null;
if (stmt == null) {
rs = pstmt.executeQuery();
try(SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting)) {
try(ResultSet rs = (stmt == null) ? pstmt.executeQuery() : stmt.executeQuery(sql)) {
int numberOfColumns = rs.getMetaData().getColumnCount();
while (rs.next()) {
testGetString(rs, numberOfColumns, values);
testGetObject(rs, numberOfColumns, values);
}
}
}
else {
rs = stmt.executeQuery(sql);
}
int numberOfColumns = rs.getMetaData().getColumnCount();

while (rs.next()) {
testGetString(rs, numberOfColumns, values);
testGetObject(rs, numberOfColumns, values);
}

Util.close(rs, pstmt, null);
}

private void testBinary(SQLServerStatement stmt,
LinkedList<byte[]> values) throws SQLException {
String sql = "select * from " + binaryTable;
SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting);
ResultSet rs = null;
if (stmt == null) {
rs = pstmt.executeQuery();
}
else {
rs = stmt.executeQuery(sql);
try(SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting)) {
try(ResultSet rs = (stmt == null) ? pstmt.executeQuery() : stmt.executeQuery(sql)) {
int numberOfColumns = rs.getMetaData().getColumnCount();
while (rs.next()) {
testGetStringForBinary(rs, numberOfColumns, values);
testGetBytes(rs, numberOfColumns, values);
testGetObjectForBinary(rs, numberOfColumns, values);
}
}
}
int numberOfColumns = rs.getMetaData().getColumnCount();

while (rs.next()) {
testGetStringForBinary(rs, numberOfColumns, values);
testGetBytes(rs, numberOfColumns, values);
testGetObjectForBinary(rs, numberOfColumns, values);
}

Util.close(rs, pstmt, null);
}

private void testDate(SQLServerStatement stmt,
LinkedList<Object> values1) throws SQLException {

String sql = "select * from " + dateTable;
SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting);
ResultSet rs = null;
if (stmt == null) {
rs = pstmt.executeQuery();
try(SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting)) {
try(ResultSet rs = (stmt == null) ? pstmt.executeQuery() : stmt.executeQuery(sql)) {
int numberOfColumns = rs.getMetaData().getColumnCount();
while (rs.next()) {
// testGetStringForDate(rs, numberOfColumns, values1); //TODO: Disabling, since getString throws verification error for zero temporal
// types
testGetObjectForTemporal(rs, numberOfColumns, values1);
testGetDate(rs, numberOfColumns, values1);
}
}
}
else {
rs = stmt.executeQuery(sql);
}
int numberOfColumns = rs.getMetaData().getColumnCount();

while (rs.next()) {
// testGetStringForDate(rs, numberOfColumns, values1); //TODO: Disabling, since getString throws verification error for zero temporal
// types
testGetObjectForTemporal(rs, numberOfColumns, values1);
testGetDate(rs, numberOfColumns, values1);
}

Util.close(rs, pstmt, null);
}

private void testGetObject(ResultSet rs,
Expand Down Expand Up @@ -948,29 +926,22 @@ private void testNumeric(Statement stmt,
String[] numericValues,
boolean isNull) throws SQLException {
String sql = "select * from " + numericTable;
SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting);
SQLServerResultSet rs = null;
if (stmt == null) {
rs = (SQLServerResultSet) pstmt.executeQuery();
}
else {
rs = (SQLServerResultSet) stmt.executeQuery(sql);
try(SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting)) {
try(SQLServerResultSet rs = (stmt == null) ? (SQLServerResultSet) pstmt.executeQuery() : (SQLServerResultSet) stmt.executeQuery(sql)) {
int numberOfColumns = rs.getMetaData().getColumnCount();
while (rs.next()) {
testGetString(rs, numberOfColumns, numericValues);
testGetObject(rs, numberOfColumns, numericValues);
testGetBigDecimal(rs, numberOfColumns, numericValues);
if (!isNull)
testWithSpecifiedtype(rs, numberOfColumns, numericValues);
else {
String[] nullNumericValues = {"false", "0", "0", "0", "0", "0.0", "0.0", "0.0", null, null, null, null, null, null, null, null};
testWithSpecifiedtype(rs, numberOfColumns, nullNumericValues);
}
}
}
}
int numberOfColumns = rs.getMetaData().getColumnCount();

while (rs.next()) {
testGetString(rs, numberOfColumns, numericValues);
testGetObject(rs, numberOfColumns, numericValues);
testGetBigDecimal(rs, numberOfColumns, numericValues);
if (!isNull)
testWithSpecifiedtype(rs, numberOfColumns, numericValues);
else {
String[] nullNumericValues = {"false", "0", "0", "0", "0", "0.0", "0.0", "0.0", null, null, null, null, null, null, null, null};
testWithSpecifiedtype(rs, numberOfColumns, nullNumericValues);
}
}

Util.close(rs, pstmt, null);
}

private void testWithSpecifiedtype(SQLServerResultSet rs,
Expand Down
Loading