(String[] args)
| 56 | }; |
| 57 | |
| 58 | public static void main(String[] args) { |
| 59 | Connection conn = null; |
| 60 | |
| 61 | String user = args[0]; |
| 62 | String port = args[1]; |
| 63 | |
| 64 | try { |
| 65 | String url = "jdbc:postgresql://127.0.0.1:" + port + "/postgres"; |
| 66 | String password = "password"; |
| 67 | |
| 68 | conn = DriverManager.getConnection(url, user, password); |
| 69 | Statement st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); |
| 70 | |
| 71 | for (int i = 0; i < tests.length; i++) { |
| 72 | PostgresTest t = tests[i]; |
| 73 | String query = t.getQuery(); |
| 74 | if ( st.execute(query) ) { |
| 75 | String[] expectedResults = t.getExpectedResults(); |
| 76 | Object fieldAccessor = t.getFieldAccessor(); |
| 77 | ResultSet rs = st.getResultSet(); |
| 78 | int rowCount = getRowCount(rs); |
| 79 | // Compare the row count to the length of the array |
| 80 | if (rowCount != expectedResults.length) { |
| 81 | System.out.println("Row count in ResultSet: " + rowCount + " does not match length of the expected results: " + expectedResults.length); |
| 82 | System.exit(1); |
| 83 | } |
| 84 | |
| 85 | Integer j = 0; |
| 86 | if (rs.next()) { |
| 87 | String expected = expectedResults[j]; |
| 88 | String result = ""; |
| 89 | if (fieldAccessor instanceof String) { |
| 90 | result = rs.getString((String)fieldAccessor); |
| 91 | } else if (fieldAccessor instanceof Integer) { |
| 92 | result = rs.getString((Integer)fieldAccessor); |
| 93 | } else { |
| 94 | System.out.println("Unsupported field accessor value: " + fieldAccessor); |
| 95 | System.exit(1); |
| 96 | } |
| 97 | |
| 98 | if (!expected.equals(result) && !(query.contains("dolt_commit")) && !(query.contains("dolt_merge"))) { |
| 99 | System.out.println("Query: \n" + query); |
| 100 | System.out.println("Expected:\n'" + expected + "'"); |
| 101 | System.out.println("Result:\n'" + result + "'"); |
| 102 | System.exit(1); |
| 103 | } |
| 104 | j++; |
| 105 | } |
| 106 | } else { |
| 107 | Integer expectedUpdateCount = t.getExpectedUpdateCount(); |
| 108 | Integer result = st.getUpdateCount(); |
| 109 | if ( !expectedUpdateCount.equals(result) ) { |
| 110 | System.out.println("Query: \n" + query); |
| 111 | System.out.println("Expected:\n" + expectedUpdateCount); |
| 112 | System.out.println("Rows Updated:\n" + result); |
| 113 | System.exit(1); |
| 114 | } |
| 115 | } |
nothing calls this directly
no test coverage detected