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

Tests | Junit improvements + Organize constants #982

Merged
merged 15 commits into from
Mar 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.sql.SQLException;


abstract class SQLServerLob implements Serializable{
abstract class SQLServerLob implements Serializable {

/**
* Always update serialVersionUID when prompted.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public SQLServerMetaData(String columnName, int sqlType, int precision, int scal
}

/**
* Constructs a SQLServerMetaData with the column name, SQL type, and length (for String data).
* The length is used to differentiate large strings from strings with length less than 4000 characters.
* Constructs a SQLServerMetaData with the column name, SQL type, and length (for String data). The length is used
* to differentiate large strings from strings with length less than 4000 characters.
*
* @param columnName
* the name of the column
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public final class SQLServerResultSetMetaData implements ISQLServerResultSetMeta
* Always update serialVersionUID when prompted.
*/
private static final long serialVersionUID = -5747558730471411712L;

private SQLServerConnection con;
private final SQLServerResultSet rs;
static final private java.util.logging.Logger logger = java.util.logging.Logger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public final class SQLServerSavepoint implements ISQLServerSavepoint {
* Always update serialVersionUID when prompted.
*/
private static final long serialVersionUID = 1857415943191289598L;

private final String sName;
private final int nId;
private final SQLServerConnection con;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class SQLServerStatement implements ISQLServerStatement {
* Always update serialVersionUID when prompted.
*/
private static final long serialVersionUID = -4421134713913331507L;

final static char LEFT_CURLY_BRACKET = 123;
final static char RIGHT_CURLY_BRACKET = 125;

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/microsoft/sqlserver/jdbc/tdsparser.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ boolean onTabName(TDSReader tdsReader) throws SQLServerException {

void onEOF(TDSReader tdsReader) throws SQLServerException {
if (null != getDatabaseError()) {
SQLServerException.makeFromDatabaseError(tdsReader.getConnection(), null, getDatabaseError().getErrorMessage(),
getDatabaseError(), false);
SQLServerException.makeFromDatabaseError(tdsReader.getConnection(), null,
getDatabaseError().getErrorMessage(), getDatabaseError(), false);
}
}

Expand Down
487 changes: 228 additions & 259 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.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.math.BigDecimal;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Time;
Expand All @@ -28,6 +27,8 @@
import com.microsoft.sqlserver.jdbc.TestResource;
import com.microsoft.sqlserver.jdbc.TestUtils;
import com.microsoft.sqlserver.testframework.AbstractSQLGenerator;
import com.microsoft.sqlserver.testframework.Constants;
import com.microsoft.sqlserver.testframework.PrepUtil;


/**
Expand Down Expand Up @@ -65,8 +66,8 @@ public class PrecisionScaleTest extends AESetup {

@Test
public void testNumericPrecision8Scale2() throws Exception {
try (SQLServerConnection con = (SQLServerConnection) DriverManager.getConnection(AETestConnectionString,
AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) {
try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo);
SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) {
dropTables(stmt);

String[] numeric = {"1.12345", "12345.12", "567.70"};
Expand All @@ -81,8 +82,8 @@ public void testNumericPrecision8Scale2() throws Exception {

@Test
public void testDateScale2() throws Exception {
try (SQLServerConnection con = (SQLServerConnection) DriverManager.getConnection(AETestConnectionString,
AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) {
try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo);
SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) {
dropTables(stmt);

String[] dateNormalCase = {GMTDate + ".18", GMTDate + ".1770000",
Expand All @@ -101,8 +102,8 @@ public void testDateScale2() throws Exception {

@Test
public void testNumericPrecision8Scale0() throws Exception {
try (SQLServerConnection con = (SQLServerConnection) DriverManager.getConnection(AETestConnectionString,
AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) {
try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo);
SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) {
dropTables(stmt);

String[] numeric2 = {"1.12345", "12345", "567"};
Expand All @@ -117,8 +118,8 @@ public void testNumericPrecision8Scale0() throws Exception {

@Test
public void testDateScale0() throws Exception {
try (SQLServerConnection con = (SQLServerConnection) DriverManager.getConnection(AETestConnectionString,
AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) {
try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo);
SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) {
dropTables(stmt);

String[] dateNormalCase2 = {GMTDate, GMTDate + ".1770000", dateTimeOffsetExpectedValue + ".1770000 +00:01",
Expand All @@ -136,8 +137,8 @@ public void testDateScale0() throws Exception {

@Test
public void testNumericPrecision8Scale2Null() throws Exception {
try (SQLServerConnection con = (SQLServerConnection) DriverManager.getConnection(AETestConnectionString,
AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) {
try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo);
SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) {
dropTables(stmt);

String[] numericNull = {"null", "null", "null"};
Expand All @@ -151,8 +152,8 @@ public void testNumericPrecision8Scale2Null() throws Exception {

@Test
public void testDateScale2Null() throws Exception {
try (SQLServerConnection con = (SQLServerConnection) DriverManager.getConnection(AETestConnectionString,
AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) {
try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo);
SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) {
dropTables(stmt);

String[] dateSetObjectNull = {"null", "null", "null", "null", "null", "null"};
Expand All @@ -166,8 +167,8 @@ public void testDateScale2Null() throws Exception {

@Test
public void testDateScale5Null() throws Exception {
try (SQLServerConnection con = (SQLServerConnection) DriverManager.getConnection(AETestConnectionString,
AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) {
try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo);
SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) {
dropTables(stmt);

String[] dateSetObjectNull = {"null", "null", "null", "null", "null", "null"};
Expand All @@ -180,10 +181,9 @@ public void testDateScale5Null() throws Exception {

private void testNumeric(String[] numeric) throws SQLException {

try (SQLServerConnection con = (SQLServerConnection) DriverManager.getConnection(AETestConnectionString,
AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement();
ResultSet rs = stmt
.executeQuery("select * from " + AbstractSQLGenerator.escapeIdentifier(numericTable))) {
try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo);
SQLServerStatement stmt = (SQLServerStatement) con.createStatement(); ResultSet rs = stmt.executeQuery(
"select * from " + AbstractSQLGenerator.escapeIdentifier(Constants.NUMERIC_TABLE_AE))) {
int numberOfColumns = rs.getMetaData().getColumnCount();

ArrayList<Integer> skipMax = new ArrayList<>();
Expand All @@ -198,9 +198,9 @@ private void testNumeric(String[] numeric) throws SQLException {

private void testDate(String[] dateNormalCase, String[] dateSetObject) throws Exception {

try (SQLServerConnection con = (SQLServerConnection) DriverManager.getConnection(AETestConnectionString,
AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement();
ResultSet rs = stmt.executeQuery("select * from " + AbstractSQLGenerator.escapeIdentifier(dateTable))) {
try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo);
SQLServerStatement stmt = (SQLServerStatement) con.createStatement(); ResultSet rs = stmt.executeQuery(
"select * from " + AbstractSQLGenerator.escapeIdentifier(Constants.DATE_TABLE_AE))) {
int numberOfColumns = rs.getMetaData().getColumnCount();

ArrayList<Integer> skipMax = new ArrayList<>();
Expand Down Expand Up @@ -365,11 +365,10 @@ private void testGetDate(ResultSet rs, int numberOfColumns, String[] dates) thro
}

private void populateDateNormalCase(int scale) throws SQLException {
String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(dateTable) + " values( " + "?,?,?,"
+ "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")";
String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.DATE_TABLE_AE) + " values( "
+ "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")";

try (SQLServerConnection con = (SQLServerConnection) DriverManager.getConnection(AETestConnectionString,
AEInfo);
try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo);
SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql,
stmtColEncSetting)) {

Expand Down Expand Up @@ -409,11 +408,10 @@ private void populateDateNormalCase(int scale) throws SQLException {
}

private void populateDateNormalCaseNull(int scale) throws SQLException {
String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(dateTable) + " values( " + "?,?,?,"
+ "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")";
String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.DATE_TABLE_AE) + " values( "
+ "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")";

try (SQLServerConnection con = (SQLServerConnection) DriverManager.getConnection(AETestConnectionString,
AEInfo);
try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo);
SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql,
stmtColEncSetting)) {

Expand Down Expand Up @@ -452,11 +450,10 @@ private void populateDateNormalCaseNull(int scale) throws SQLException {
}

private void populateNumericNormalCase(String[] numeric, int precision, int scale) throws SQLException {
String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(numericTable) + " values( " + "?,?,?,"
+ "?,?,?," + "?,?,?" + ")";
String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.NUMERIC_TABLE_AE) + " values( "
+ "?,?,?," + "?,?,?," + "?,?,?" + ")";

try (SQLServerConnection con = (SQLServerConnection) DriverManager.getConnection(AETestConnectionString,
AEInfo);
try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo);
SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql,
stmtColEncSetting)) {

Expand All @@ -480,11 +477,10 @@ private void populateNumericNormalCase(String[] numeric, int precision, int scal
}

private void populateNumericSetObject(String[] numeric, int precision, int scale) throws SQLException {
String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(numericTable) + " values( " + "?,?,?,"
+ "?,?,?," + "?,?,?" + ")";
String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.NUMERIC_TABLE_AE) + " values( "
+ "?,?,?," + "?,?,?," + "?,?,?" + ")";

try (SQLServerConnection con = (SQLServerConnection) DriverManager.getConnection(AETestConnectionString,
AEInfo);
try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo);
SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql,
stmtColEncSetting)) {

Expand All @@ -509,11 +505,10 @@ private void populateNumericSetObject(String[] numeric, int precision, int scale
}

private void populateNumericSetObjectNull(int precision, int scale) throws SQLException {
String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(numericTable) + " values( " + "?,?,?,"
+ "?,?,?," + "?,?,?" + ")";
String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.NUMERIC_TABLE_AE) + " values( "
+ "?,?,?," + "?,?,?," + "?,?,?" + ")";

try (SQLServerConnection con = (SQLServerConnection) DriverManager.getConnection(AETestConnectionString,
AEInfo);
try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo);
SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql,
stmtColEncSetting)) {

Expand All @@ -538,11 +533,10 @@ private void populateNumericSetObjectNull(int precision, int scale) throws SQLEx
}

private void populateDateSetObject(int scale) throws SQLException {
String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(dateTable) + " values( " + "?,?,?,"
+ "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")";
String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.DATE_TABLE_AE) + " values( "
+ "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")";

try (SQLServerConnection con = (SQLServerConnection) DriverManager.getConnection(AETestConnectionString,
AEInfo);
try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo);
SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql,
stmtColEncSetting)) {

Expand Down Expand Up @@ -583,11 +577,10 @@ private void populateDateSetObject(int scale) throws SQLException {
}

private void populateDateSetObjectNull(int scale) throws SQLException {
String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(dateTable) + " values( " + "?,?,?,"
+ "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")";
String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.DATE_TABLE_AE) + " values( "
+ "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")";

try (SQLServerConnection con = (SQLServerConnection) DriverManager.getConnection(AETestConnectionString,
AEInfo);
try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo);
SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql,
stmtColEncSetting)) {

Expand Down
Loading