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

Junit testing #404

Merged
merged 7 commits into from
Jul 25, 2017
Merged

Junit testing #404

merged 7 commits into from
Jul 25, 2017

Conversation

peterbae
Copy link
Contributor

Moved JDBCEncryptionDecryption AE tests into Junit. Ran Appveyor and Travis tests against my local dev branch to ensure that the tests passed.

@msftclas
Copy link

@peterbae,
Thanks for your contribution as a Microsoft full-time employee or intern. You do not need to sign a CLA.
Thanks,
Microsoft Pull Request Bot

@codecov-io
Copy link

codecov-io commented Jul 21, 2017

Codecov Report

Merging #404 into dev will increase coverage by 4.93%.
The diff coverage is 50%.

Impacted file tree graph

@@             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
Flag Coverage Δ Complexity Δ
#JDBC41 44.8% <50%> (+4.83%) 2118 <0> (+237) ⬆️
#JDBC42 44.85% <50%> (+4.93%) 2128 <0> (+250) ⬆️
Impacted Files Coverage Δ Complexity Δ
...c/main/java/com/microsoft/sqlserver/jdbc/Util.java 59.61% <50%> (+12.09%) 90 <0> (+27) ⬆️
...oft/sqlserver/jdbc/SQLServerParameterMetaData.java 23.81% <0%> (-1.71%) 30% <0%> (ø)
...m/microsoft/sqlserver/jdbc/KeyVaultCredential.java 0% <0%> (ø) 0% <0%> (ø) ⬇️
...QLServerColumnEncryptionAzureKeyVaultProvider.java 0% <0%> (ø) 0% <0%> (ø) ⬇️
...om/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java 49.85% <0%> (+0.42%) 214% <0%> (+3%) ⬆️
...soft/sqlserver/jdbc/SQLServerDatabaseMetaData.java 29.47% <0%> (+0.45%) 48% <0%> (+2%) ⬆️
...n/java/com/microsoft/sqlserver/jdbc/DataTypes.java 77.4% <0%> (+0.5%) 5% <0%> (ø) ⬇️
...m/microsoft/sqlserver/jdbc/SQLServerStatement.java 59.57% <0%> (+0.5%) 138% <0%> (+9%) ⬆️
...oft/sqlserver/jdbc/SQLServerResultSetMetaData.java 40.84% <0%> (+0.7%) 23% <0%> (+1%) ⬆️
.../microsoft/sqlserver/jdbc/SQLServerConnection.java 45.78% <0%> (+0.71%) 286% <0%> (+19%) ⬆️
... and 22 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f46f622...6b905af. Read the comment docs.

static final String cmkName = "JDBC_CMK";
static final String cekName = "JDBC_CEK";
static final String secretstrJks = "password";
static final String numericTable = "JDBCEncrpytedNumericTable";
Copy link
Contributor

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?

Copy link
Contributor Author

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);
Copy link
Contributor

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

Copy link
Contributor Author

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
Copy link
Contributor

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

Copy link
Contributor Author

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

}
}

pstmt.execute();
Copy link
Contributor

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

Copy link
Contributor Author

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;
Copy link
Contributor

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?

Copy link
Contributor Author

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--------------------------------------------
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this // to javaDocs

Copy link
Contributor Author

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);
}
}
/*
Copy link
Contributor

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

Copy link
Contributor Author

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")
Copy link
Contributor

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

Copy link
Contributor Author

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is uid2 used anywhere?

Copy link
Contributor Author

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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() {
Copy link
Contributor

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?

Copy link
Contributor Author

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
@peterbae peterbae merged commit c28b271 into microsoft:dev Jul 25, 2017
@peterbae peterbae deleted the JunitTesting branch July 25, 2017 17:57
@peterbae peterbae restored the JunitTesting branch July 25, 2017 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants