connell-class / revassess

this is a trial repo for making a template for the revature assessment
2 stars 11 forks source link

tier3/test4: Fails with Oracle DB 12.1 #21

Closed flacks closed 4 years ago

flacks commented 4 years ago

Describe the bug

To reproduce

  1. Create required stored procedure in database
  2. Set TIER_3_PROCEDURE_NAME in com.rev.config.ConnectionConfig` as well as database details.
  3. Run Answer4Test.java

Workaround This is a rework of the test that has worked for me.

try (Connection conn = DriverManager.getConnection(ConnectionConfig.URL, ConnectionConfig.USERNAME, ConnectionConfig.PASSWORD)) {
    String sql = "{ call " + ConnectionConfig.TIER_3_PROCEDURE_NAME + "(?, ?) }";
    CallableStatement cs = conn.prepareCall(sql);
    // First parameter is set to user_id 4, since this user owns study sets
    int userId = 4;
    cs.setInt(1, userId);
    // Second parameter is the cursor
    cs.registerOutParameter(2, Types.REF_CURSOR);
    // Manually execute callable statement
    cs.execute();
    // Select OUT parameter
    ResultSet rs = (ResultSet) cs.getObject(2);
    while (rs.next()) {
        // Assert that user_id is the owner of every study set
        // Expects user_id 4 from every third column (OWNER_ID)
        assertEquals(userId, rs.getInt(3));
    }