Skip to content

Commit 7588640

Browse files
gopalldbclaude
andauthored
Add metadata, connection, statement and PreparedStatement integration tests (#1213)
## Summary - Add 26 new fake service integration tests across 4 existing test classes - Tests cover metadata retrieval, connection management, statement lifecycle, and PreparedStatement enhancements - All tests use the existing WireMock-based record-replay infrastructure in SEA mode - Recorded against production and verified in replay mode (no token needed for CI) ## Changes by test class | Test Class | New Tests | Coverage Area | |-----------|-----------|--------------| | MetadataIntegrationTests | +10 | ResultSetMetaData (columnLabel, typeName, precision, scale, displaySize, className, boolean properties, signed, multiple data types), DatabaseMetaData.getTypeInfo(), ParameterMetaData.getParameterCount() | | ConnectionIntegrationTests | +7 | isClosed(), isValid(), getCatalog(), getSchema(), getMetaData(), getWarnings()/clearWarnings(), getClientInfo() | | ExecutionIntegrationTests | +5 | Statement lifecycle: close()/isClosed(), getConnection(), getMaxRows()/setMaxRows(), getQueryTimeout()/setQueryTimeout(), getWarnings()/clearWarnings() | | PreparedStatementIntegrationTests | +4 | clearParameters(), setNull() with INT type, setObject() without SQL type, getMetaData() for SELECT | ## New JDBC methods covered ### ResultSetMetaData - getColumnLabel(), getColumnTypeName(), getPrecision(), getScale() - getColumnDisplaySize(), getColumnClassName() - isAutoIncrement(), isSearchable(), isCurrency(), isReadOnly(), isSigned() ### DatabaseMetaData - getTypeInfo() - full type catalog ### ParameterMetaData - getParameterCount() ### Connection - isClosed(), isValid(int), getCatalog(), getSchema() - getMetaData(), getWarnings(), clearWarnings(), getClientInfo() ### Statement - close(), isClosed(), getConnection() - getMaxRows(), setMaxRows(), getQueryTimeout(), setQueryTimeout() - getWarnings(), clearWarnings() ### PreparedStatement - clearParameters(), setNull() with INT, setObject() without type - getMetaData() before execution ## Test plan - [x] All 56 tests pass in REPLAY mode (no production access needed) - [x] All tests compile successfully - [x] WireMock recordings committed under src/test/resources/sqlexecapi/ and cloudfetchapi/ - [ ] Verify CI passes ## Updated Coverage Including PR #1212 ┌─────────────────────────────────────┬───────────────────┬──────────────────┐ │ │ Before (both PRs) │ After (both PRs) │ ├─────────────────────────────────────┼───────────────────┼──────────────────┤ │ JDBC methods with integration tests │ ~44 / 328 │ ~96 / 328 │ ├─────────────────────────────────────┼───────────────────┼──────────────────┤ │ Coverage % │ 13.4% │ ~29.3% │ └─────────────────────────────────────┴───────────────────┴──────────────────┘ NO_CHANGELOG=true --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d89ad56 commit 7588640

308 files changed

Lines changed: 11133 additions & 10 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/test/java/com/databricks/jdbc/integration/fakeservice/tests/ConnectionIntegrationTests.java

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22

33
import static com.databricks.jdbc.integration.IntegrationTestUtil.*;
44
import static org.junit.jupiter.api.Assertions.*;
5-
import static org.junit.jupiter.api.Assertions.assertThrows;
65

76
import com.databricks.jdbc.common.DatabricksJdbcUrlParams;
87
import com.databricks.jdbc.exception.DatabricksSQLException;
98
import com.databricks.jdbc.integration.fakeservice.AbstractFakeServiceIntegrationTests;
109
import com.databricks.jdbc.integration.fakeservice.FakeServiceConfigLoader;
11-
import java.sql.Connection;
12-
import java.sql.DriverManager;
13-
import java.sql.SQLException;
10+
import java.sql.*;
1411
import java.util.Properties;
1512
import org.junit.jupiter.api.Test;
1613

@@ -83,7 +80,7 @@ void testPATinOAuthTokenPassThrough() throws Exception {
8380
conn.close();
8481
}
8582

86-
// --- Connection management tests ---
83+
// --- Connection properties and management tests ---
8784

8885
@Test
8986
void testIsClosed_NewConnection() throws SQLException {
@@ -127,6 +124,41 @@ void testGetSchema_ReturnsNonNull() throws SQLException {
127124
conn.close();
128125
}
129126

127+
@Test
128+
void testGetMetaData_ReturnsNonNull() throws SQLException {
129+
Connection conn = getValidJDBCConnection();
130+
131+
DatabaseMetaData metaData = conn.getMetaData();
132+
assertNotNull(metaData, "getMetaData() should return non-null");
133+
assertNotNull(metaData.getDriverName(), "Driver name should not be null");
134+
assertFalse(metaData.getDriverName().isEmpty(), "Driver name should not be empty");
135+
136+
conn.close();
137+
}
138+
139+
@Test
140+
void testGetWarnings_AndClearWarnings() throws SQLException {
141+
Connection conn = getValidJDBCConnection();
142+
143+
// New connection may or may not have warnings, but getWarnings() should not throw
144+
SQLWarning warnings = conn.getWarnings();
145+
// clearWarnings should not throw
146+
conn.clearWarnings();
147+
assertNull(conn.getWarnings(), "Warnings should be null after clearWarnings()");
148+
149+
conn.close();
150+
}
151+
152+
@Test
153+
void testGetClientInfo_ReturnsProperties() throws SQLException {
154+
Connection conn = getValidJDBCConnection();
155+
156+
Properties clientInfo = conn.getClientInfo();
157+
assertNotNull(clientInfo, "getClientInfo() should return non-null Properties");
158+
159+
conn.close();
160+
}
161+
130162
private Properties createConnectionProperties(Properties extraProps) {
131163
Properties connProps = new Properties();
132164
connProps.putAll(extraProps);

src/test/java/com/databricks/jdbc/integration/fakeservice/tests/ExecutionIntegrationTests.java

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,81 @@ void testExecuteAsyncStatement() throws Exception {
278278
rs2.unwrap(IDatabricksResultSet.class).getStatementStatus().getState());
279279
}
280280

281+
// --- Statement lifecycle and property tests ---
282+
283+
@Test
284+
void testStatement_CloseAndIsClosed() throws SQLException {
285+
Statement stmt = connection.createStatement();
286+
assertFalse(stmt.isClosed(), "New statement should not be closed");
287+
288+
stmt.close();
289+
assertTrue(stmt.isClosed(), "Statement should be closed after close()");
290+
}
291+
292+
@Test
293+
void testStatement_GetConnection() throws SQLException {
294+
Statement stmt = connection.createStatement();
295+
Connection stmtConn = stmt.getConnection();
296+
assertNotNull(stmtConn, "getConnection() should return non-null");
297+
assertSame(connection, stmtConn, "getConnection() should return the parent connection");
298+
299+
stmt.close();
300+
}
301+
302+
@Test
303+
void testStatement_MaxRows() throws SQLException {
304+
Statement stmt = connection.createStatement();
305+
306+
// Default maxRows should be 0 (no limit)
307+
assertEquals(0, stmt.getMaxRows(), "Default maxRows should be 0");
308+
309+
stmt.setMaxRows(100);
310+
assertEquals(100, stmt.getMaxRows(), "maxRows should be 100 after setMaxRows(100)");
311+
312+
// setMaxRows(0) means no limit
313+
stmt.setMaxRows(0);
314+
assertEquals(0, stmt.getMaxRows(), "maxRows should be 0 after setMaxRows(0)");
315+
316+
// Negative value should throw
317+
assertThrows(
318+
SQLException.class, () -> stmt.setMaxRows(-1), "setMaxRows(-1) should throw SQLException");
319+
320+
stmt.close();
321+
}
322+
323+
@Test
324+
void testStatement_QueryTimeout() throws SQLException {
325+
Statement stmt = connection.createStatement();
326+
327+
// Default timeout should be 0 (no timeout)
328+
assertEquals(0, stmt.getQueryTimeout(), "Default queryTimeout should be 0");
329+
330+
stmt.setQueryTimeout(30);
331+
assertEquals(30, stmt.getQueryTimeout(), "queryTimeout should be 30 after setQueryTimeout(30)");
332+
333+
// Negative value should throw
334+
assertThrows(
335+
SQLException.class,
336+
() -> stmt.setQueryTimeout(-1),
337+
"setQueryTimeout(-1) should throw SQLException");
338+
339+
stmt.close();
340+
}
341+
342+
@Test
343+
void testStatement_Warnings() throws SQLException {
344+
Statement stmt = connection.createStatement();
345+
346+
// getWarnings should not throw
347+
SQLWarning warnings = stmt.getWarnings();
348+
349+
// clearWarnings should not throw
350+
stmt.clearWarnings();
351+
assertNull(stmt.getWarnings(), "Warnings should be null after clearWarnings()");
352+
353+
stmt.close();
354+
}
355+
281356
// --- Execution result handling tests (getResultSet, getUpdateCount, getMoreResults) ---
282357

283358
@Test
@@ -538,7 +613,5 @@ void testPreparedStatementBatch_ClearBatch() throws SQLException {
538613
assertEquals(10, rs.getInt("id"));
539614
assertEquals("fresh1", rs.getString("col1"));
540615
assertFalse(rs.next(), "Should only have 1 row");
541-
542-
deleteTable(connection, tableName);
543616
}
544617
}

0 commit comments

Comments
 (0)