|
1 | 1 | package com.clickhouse.jdbc; |
2 | 2 |
|
3 | 3 | import com.clickhouse.client.api.ClientConfigProperties; |
| 4 | +import com.clickhouse.client.api.ClientMisconfigurationException; |
| 5 | +import com.clickhouse.client.api.ServerException; |
4 | 6 | import org.testng.Assert; |
5 | 7 | import org.testng.annotations.DataProvider; |
6 | 8 | import org.testng.annotations.Test; |
7 | 9 |
|
| 10 | +import java.sql.Connection; |
8 | 11 | import java.sql.DriverManager; |
9 | 12 | import java.sql.DriverPropertyInfo; |
10 | 13 | import java.sql.SQLException; |
| 14 | +import java.sql.Statement; |
11 | 15 | import java.util.HashMap; |
12 | 16 | import java.util.Map; |
13 | 17 | import java.util.Properties; |
14 | 18 |
|
| 19 | +import static org.testng.Assert.assertEquals; |
15 | 20 | import static org.testng.AssertJUnit.assertTrue; |
16 | 21 |
|
17 | 22 |
|
@@ -62,16 +67,16 @@ public void testGetPropertyInfo(String url, Properties props, Map<String, String |
62 | 67 | for (DriverPropertyInfo property : properties) { |
63 | 68 | Object expectedValue = checkPropertiesCopy.remove(property.name); |
64 | 69 | if (expectedValue != null) { |
65 | | - Assert.assertEquals(property.value, expectedValue); |
| 70 | + assertEquals(property.value, expectedValue); |
66 | 71 | } else { |
67 | 72 | for (DriverProperties driverProp : DriverProperties.values()) { |
68 | 73 | if (driverProp.getKey().equalsIgnoreCase(property.name)) { |
69 | | - Assert.assertEquals(property.value, driverProp.getDefaultValue()); |
| 74 | + assertEquals(property.value, driverProp.getDefaultValue()); |
70 | 75 | } |
71 | 76 | } |
72 | 77 | for (ClientConfigProperties clientProp : ClientConfigProperties.values()) { |
73 | 78 | if (clientProp.getKey().equalsIgnoreCase(property.name)) { |
74 | | - Assert.assertEquals(property.value, clientProp.getDefaultValue()); |
| 79 | + assertEquals(property.value, clientProp.getDefaultValue()); |
75 | 80 | } |
76 | 81 | } |
77 | 82 | } |
@@ -107,7 +112,7 @@ public void testGetDriverVersion() { |
107 | 112 | @Test(groups = {"integration"}, dataProvider = "testParsingDriverVersionDP") |
108 | 113 | public void testParsingDriverVersion(String version, int expectedMajor, int expectedMinor) { |
109 | 114 | int[] versions = Driver.parseVersion(version); |
110 | | - Assert.assertEquals(versions, new int[] { expectedMajor, expectedMinor }); |
| 115 | + assertEquals(versions, new int[] { expectedMajor, expectedMinor }); |
111 | 116 | } |
112 | 117 |
|
113 | 118 | @DataProvider(name = "testParsingDriverVersionDP") |
@@ -139,7 +144,55 @@ public void testGetParentLogger() { |
139 | 144 | driver.getParentLogger(); |
140 | 145 | Assert.fail("Should not reach here"); |
141 | 146 | } catch (SQLException e) { |
142 | | - Assert.assertEquals(e.getMessage(), "Method not supported"); |
| 147 | + assertEquals(e.getMessage(), "Method not supported"); |
143 | 148 | } |
144 | 149 | } |
| 150 | + |
| 151 | + @Test(groups = { "integration" }) |
| 152 | + public void testUnknownSettings() throws Exception { |
| 153 | + Driver driver = new Driver(); |
| 154 | + try { |
| 155 | + driver.connect(getEndpointString() + "?unknown_setting=1", new Properties()); |
| 156 | + Assert.fail("Exception expected"); |
| 157 | + } catch (SQLException e) { |
| 158 | + Assert.assertTrue(e.getCause() instanceof ClientMisconfigurationException); |
| 159 | + Assert.assertTrue(e.getCause().getMessage().contains("unknown_setting")); |
| 160 | + } |
| 161 | + |
| 162 | + try { |
| 163 | + Properties properties = new Properties(); |
| 164 | + properties.put("unknown_setting1", "1"); |
| 165 | + driver.connect(getEndpointString(), properties).close(); |
| 166 | + Assert.fail("Exception expected"); |
| 167 | + } catch (SQLException e) { |
| 168 | + Assert.assertTrue(e.getCause() instanceof ClientMisconfigurationException); |
| 169 | + Assert.assertTrue(e.getCause().getMessage().contains("unknown_setting1")); |
| 170 | + } |
| 171 | + |
| 172 | + { |
| 173 | + Properties properties = new Properties(); |
| 174 | + properties.put(DriverProperties.serverSetting("unknown_setting2"), "1"); |
| 175 | + try (Connection connection = getJdbcConnection(properties)) { |
| 176 | + try { |
| 177 | + connection.createStatement().execute("SELECT 1"); |
| 178 | + Assert.fail("Exception expected"); |
| 179 | + } catch (SQLException e) { |
| 180 | + Assert.assertTrue(e.getCause() instanceof ServerException); |
| 181 | + assertEquals(((ServerException) e.getCause()).getCode(), ServerException.UNKNOWN_SETTING); |
| 182 | + } |
| 183 | + } |
| 184 | + } |
| 185 | + |
| 186 | + { |
| 187 | + Properties properties = new Properties(); |
| 188 | + properties.put(DriverProperties.SECURE_CONNECTION.getKey(), "true"); |
| 189 | + properties.put(DriverProperties.SCHEMA_TERM.getKey(), "catalog"); |
| 190 | + try (Connection connection = getJdbcConnection(properties); |
| 191 | + Statement stmt = connection.createStatement()) { |
| 192 | + // |
| 193 | + } |
| 194 | + } |
| 195 | + |
| 196 | + driver.connect(getEndpointString() + "?unknown_setting=1&" + ClientConfigProperties.NO_THROW_ON_UNKNOWN_CONFIG + "=1", new Properties()).close(); |
| 197 | + } |
145 | 198 | } |
0 commit comments