-
Notifications
You must be signed in to change notification settings - Fork 426
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
Junit testing #404
Junit testing #404
Conversation
@peterbae, |
Codecov Report
@@ Coverage Diff @@
## dev #404 +/- ##
============================================
+ Coverage 40.07% 45.01% +4.93%
- Complexity 1887 2132 +245
============================================
Files 107 107
Lines 24482 24661 +179
Branches 4038 4102 +64
============================================
+ Hits 9812 11101 +1289
+ Misses 12831 11693 -1138
- Partials 1839 1867 +28
Continue to review full report at Codecov.
|
static final String cmkName = "JDBC_CMK"; | ||
static final String cekName = "JDBC_CEK"; | ||
static final String secretstrJks = "password"; | ||
static final String numericTable = "JDBCEncrpytedNumericTable"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you run format on all of the file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
* @throws SQLException | ||
*/ | ||
static void dropTables() throws SQLException { | ||
stmt.executeUpdate("if object_id('" + numericTable + "','U') is not null" + " drop table " + numericTable); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's use Utils.dropTableIfExists
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
* | ||
* @throws Exception | ||
* @throws TestAbortedException | ||
* Junit test case for char set string for string values |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same for this file. let's run format
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
* @throws SQLException | ||
*/ | ||
@Test | ||
public void testChar_SpecificSetter() throws SQLException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's use camelCase convention, I noticed you used the right convention in the methods you introduced.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
} | ||
} | ||
|
||
pstmt.execute(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing pstmt.close in some places
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created Util.close(ResultSet, Statement, Connection) that employs good practice for closing those 3 objects, and applied it to the test cases.
@@ -0,0 +1,655 @@ | |||
package com.microsoft.sqlserver.jdbc.AlwaysEncrypted; | |||
import java.math.BigDecimal; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest moving this randomData class somewhere in test framework so we can use it in other tests as well. also, could you run form format?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep. randomData and Util were originally for AE only, but I think they can be used elsewhere as well - i moved both of them to util package.
private static String numberCharSet = "1234567890"; | ||
private static String numberCharSet2 = "123456789"; | ||
|
||
//-------------------numeric types-------------------------------------------- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change this // to javaDocs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
return ((SQLServerConnection) connection).prepareCall(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, connection.getHoldability(), stmtColEncSetting); | ||
} | ||
} | ||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can remove these sections if they are not needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
@@ -67,7 +67,8 @@ public static void setup() throws Exception { | |||
applicationKey = getConfiguredProperty("applicationKey"); | |||
keyIDs = getConfiguredProperty("keyID", "").split(";"); | |||
|
|||
connectionString = getConfiguredProperty("mssql_jdbc_test_connection_properties"); | |||
connectionString = getConfiguredProperty("mssql_jdbc_test_connection_properties") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add the + ";sendTimeAsDateTime=false"; inside the jdbcEncryptionDecryption test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done. I moved it to AESetup.java.
@@ -70,23 +78,24 @@ static void setUpConnection() throws TestAbortedException, Exception { | |||
|
|||
readFromFile(javaKeyStoreInputFile, "Alias name"); | |||
con = (SQLServerConnection) DriverManager.getConnection(connectionString); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add the + ";sendTimeAsDateTime=false"; here. We don't want other tests to create connection with having this connection property.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
static final String binaryTable = "JDBCEncrpytedBinaryTable"; | ||
static final String dateTable = "JDBCEncrpytedDateTable"; | ||
static final String uid = "171fbe25-4331-4765-a838-b2e3eea3e7ea"; | ||
static final String uid2 = "171fbe25-4331-4765-a838-b2e3eea3e7eb"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is uid2 used anywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, I removed it.
@@ -70,23 +78,24 @@ static void setUpConnection() throws TestAbortedException, Exception { | |||
|
|||
readFromFile(javaKeyStoreInputFile, "Alias name"); | |||
con = (SQLServerConnection) DriverManager.getConnection(connectionString); | |||
stmt = con.createStatement(); | |||
stmt = (SQLServerStatement) con.createStatement(); | |||
Utils.dropTableIfExists(numericTable, stmt); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since dropTables() method in afterAll() is cleaning up, let's remove this, or add all dropping tables here too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
@@ -970,7 +970,7 @@ static synchronized boolean checkIfNeedNewAccessToken(SQLServerConnection connec | |||
|
|||
// if driver is for JDBC 42 and jvm version is 8 or higher, then always return as SQLServerPreparedStatement42, | |||
// otherwise return SQLServerPreparedStatement | |||
static boolean use42Wrapper() { | |||
public static boolean use42Wrapper() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you check using System.getProperty("java.specification.version"); and skipping the test if java 7 would solve the issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking for java 7 only doesn't solve the issue - the tests being done on github uses java 8, but does not support jdbc 4.2 - we need to check for both.
…cking and moved/added functionalities to utility classes.
…ality to the Util class within the testing package
Moved JDBCEncryptionDecryption AE tests into Junit. Ran Appveyor and Travis tests against my local dev branch to ensure that the tests passed.