-
Notifications
You must be signed in to change notification settings - Fork 623
Expand file tree
/
Copy pathGenericJDBCTest.java
More file actions
71 lines (61 loc) · 2.34 KB
/
GenericJDBCTest.java
File metadata and controls
71 lines (61 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package com.clickhouse.jdbc;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertThrows;
@Test(groups = { "integration" })
public class GenericJDBCTest extends JdbcIntegrationTest {
public Connection getConnection(Properties properties) throws SQLException {
if (properties == null) {
properties = new Properties();
}
return newDataSource(properties).getConnection();
}
@Test
public void connectionTest() throws SQLException {
try (Connection connection = getConnection(null)) {
Assert.assertNotNull(connection);
Assert.assertTrue(connection.isValid(1));
}
}
@Test
public void connectionWithPropertiesTest() throws SQLException {
Properties properties = new Properties();
properties.setProperty("user", "default");
properties.setProperty("password", "FAKE123456FAKE");
assertFalse(getConnection(properties).isValid(10));
}
@Test
public void basicStatementTest() {
try (Connection connection = getConnection(null);
Statement statement = connection.createStatement()) {
Assert.assertNotNull(statement);
ResultSet resultSet = statement.executeQuery("SELECT 1");
Assert.assertNotNull(resultSet);
Assert.assertTrue(resultSet.next());
Assert.assertEquals(resultSet.getInt(1), 1);
} catch (SQLException e) {
Assert.fail("Failed to create statement", e);
}
}
@Test
public void basicPreparedStatementTest() {
try (Connection connection = getConnection(null);
PreparedStatement statement = connection.prepareStatement("SELECT ?")) {
Assert.assertNotNull(statement);
statement.setInt(1, 1);
ResultSet resultSet = statement.executeQuery();
Assert.assertNotNull(resultSet);
Assert.assertTrue(resultSet.next());
Assert.assertEquals(resultSet.getInt(1), 1);
} catch (SQLException e) {
Assert.fail("Failed to create statement", e);
}
}
}