|
21 | 21 | import java.sql.DriverPropertyInfo; |
22 | 22 | import java.sql.SQLException; |
23 | 23 | import java.util.Properties; |
| 24 | +import java.util.logging.Level; |
24 | 25 | import java.util.logging.Logger; |
| 26 | +import org.junit.jupiter.api.Assertions; |
25 | 27 | import org.junit.jupiter.api.BeforeEach; |
26 | 28 | import org.junit.jupiter.api.Test; |
27 | 29 |
|
28 | | -public class BigQueryDriverTest { |
| 30 | +public class BigQueryDriverTest extends BigQueryJdbcLoggingBaseTest { |
29 | 31 |
|
30 | 32 | static BigQueryDriver bigQueryDriver; |
31 | 33 |
|
@@ -104,4 +106,63 @@ public void testConnectWithInvalidUrlChainsNoException() throws SQLException { |
104 | 106 | new Properties()); |
105 | 107 | assertThat(connection.isClosed()).isFalse(); |
106 | 108 | } |
| 109 | + |
| 110 | + @Test |
| 111 | + public void testUnknownPropertyWarningIsLogged() throws SQLException { |
| 112 | + Connection connection = |
| 113 | + bigQueryDriver.connect( |
| 114 | + "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" |
| 115 | + + "OAuthType=2;OAuthAccessToken=redactedToken;ProjectId=t;LogLevel=3;" |
| 116 | + + "MyUnknownSetting=Value", |
| 117 | + new Properties()); |
| 118 | + assertThat(connection.isClosed()).isFalse(); |
| 119 | + |
| 120 | + boolean foundWarning = |
| 121 | + capturedLogs.stream() |
| 122 | + .anyMatch( |
| 123 | + r -> |
| 124 | + r.getLevel() == Level.WARNING |
| 125 | + && r.getMessage() |
| 126 | + .contains("Wrong value or unknown setting: MYUNKNOWNSETTING")); |
| 127 | + assertThat(foundWarning).isTrue(); |
| 128 | + } |
| 129 | + |
| 130 | + @Test |
| 131 | + public void testMalformedUrlExceptionIsLogged() { |
| 132 | + Assertions.assertThrows( |
| 133 | + SQLException.class, |
| 134 | + () -> |
| 135 | + bigQueryDriver.connect( |
| 136 | + "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" |
| 137 | + + "OAuthType=2;OAuthAccessToken=redactedToken;ProjectId=t;LogLevel=3;" |
| 138 | + + "MalformedPropertyWithoutEquals", |
| 139 | + new Properties())); |
| 140 | + |
| 141 | + boolean foundSevere = |
| 142 | + capturedLogs.stream() |
| 143 | + .anyMatch( |
| 144 | + r -> |
| 145 | + r.getLevel() == Level.SEVERE |
| 146 | + && r.getMessage().contains("Failed to parse connection URL")); |
| 147 | + assertThat(foundSevere).isTrue(); |
| 148 | + } |
| 149 | + |
| 150 | + @Test |
| 151 | + public void testInvalidLogLevelExceptionIsLogged() { |
| 152 | + Assertions.assertThrows( |
| 153 | + SQLException.class, |
| 154 | + () -> |
| 155 | + bigQueryDriver.connect( |
| 156 | + "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" |
| 157 | + + "OAuthType=2;OAuthAccessToken=redactedToken;ProjectId=t;LogLevel=invalidInt;", |
| 158 | + new Properties())); |
| 159 | + |
| 160 | + boolean foundSevere = |
| 161 | + capturedLogs.stream() |
| 162 | + .anyMatch( |
| 163 | + r -> |
| 164 | + r.getLevel() == Level.SEVERE |
| 165 | + && r.getMessage().contains("Failed to parse connection URL properties")); |
| 166 | + assertThat(foundSevere).isTrue(); |
| 167 | + } |
107 | 168 | } |
0 commit comments