|
4 | 4 |
|
5 | 5 | import org.firebirdsql.common.extension.UsesDatabaseExtension; |
6 | 6 | import org.firebirdsql.common.extension.UsesDatabaseExtension.UsesDatabaseForAll; |
| 7 | +import org.firebirdsql.common.matchers.SQLExceptionMatchers; |
7 | 8 | import org.firebirdsql.jaybird.props.PropertyNames; |
8 | 9 | import org.firebirdsql.jaybird.util.SearchPathHelper; |
9 | 10 | import org.junit.jupiter.api.Test; |
|
17 | 18 | import java.sql.ResultSetMetaData; |
18 | 19 | import java.sql.SQLDataException; |
19 | 20 | import java.sql.SQLException; |
| 21 | +import java.sql.SQLFeatureNotSupportedException; |
20 | 22 | import java.util.List; |
21 | 23 |
|
22 | 24 | import static org.firebirdsql.common.FBTestProperties.getConnectionViaDriverManager; |
23 | 25 | import static org.firebirdsql.common.FBTestProperties.getDefaultSupportInfo; |
24 | 26 | import static org.firebirdsql.common.FbAssumptions.assumeNoSchemaSupport; |
25 | 27 | import static org.firebirdsql.common.FbAssumptions.assumeSchemaSupport; |
| 28 | +import static org.firebirdsql.common.matchers.SQLExceptionMatchers.message; |
26 | 29 | import static org.hamcrest.MatcherAssert.assertThat; |
27 | 30 | import static org.hamcrest.Matchers.empty; |
28 | 31 | import static org.hamcrest.Matchers.is; |
| 32 | +import static org.hamcrest.Matchers.startsWith; |
29 | 33 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; |
30 | 34 | import static org.junit.jupiter.api.Assertions.assertEquals; |
31 | 35 | import static org.junit.jupiter.api.Assertions.assertNull; |
@@ -203,6 +207,97 @@ void connectionSearchPath(String searchPath, String expectedSchema, String expec |
203 | 207 | } |
204 | 208 | } |
205 | 209 |
|
| 210 | + @Test |
| 211 | + void setSearchPath_noSchemaSupport_throwsFBDriverNotCapable() throws Exception { |
| 212 | + assumeNoSchemaSupport(); |
| 213 | + try (var connection = getConnectionViaDriverManager()) { |
| 214 | + assertThrows(FBDriverNotCapableException.class, () -> connection.setSearchPath("SYSTEM")); |
| 215 | + } |
| 216 | + } |
| 217 | + |
| 218 | + @ParameterizedTest |
| 219 | + @NullAndEmptySource |
| 220 | + @ValueSource(strings = { " ", " " }) |
| 221 | + void setSearchPath_schemaSupport_nullOrBlank_notAccepted(String searchPath) throws Exception { |
| 222 | + assumeSchemaSupport(); |
| 223 | + try (var connection = getConnectionViaDriverManager()) { |
| 224 | + var exception = assertThrows(SQLDataException.class, () -> connection.setSearchPath(searchPath)); |
| 225 | + assertThat(exception, message(startsWith("search path must have at least one schema"))); |
| 226 | + } |
| 227 | + } |
| 228 | + |
| 229 | + @ParameterizedTest |
| 230 | + @CsvSource(useHeadersInDisplayName = true, textBlock = """ |
| 231 | + searchPath, expectedSearchPath |
| 232 | + PUBLIC, '"PUBLIC", "SYSTEM"' |
| 233 | + 'PUBLIC, SYSTEM', '"PUBLIC", "SYSTEM"' |
| 234 | + public, '"PUBLIC", "SYSTEM"' |
| 235 | + "public", '"public", "SYSTEM"' |
| 236 | + SCHEMA_1, '"SCHEMA_1", "SYSTEM"' |
| 237 | + "case_sensitive", '"case_sensitive", "SYSTEM"' |
| 238 | + # NOTE Unquoted! |
| 239 | + case_sensitive, '"CASE_SENSITIVE", "SYSTEM"' |
| 240 | + 'SCHEMA_1, "case_sensitive", SYSTEM, PUBLIC', '"SCHEMA_1", "case_sensitive", "SYSTEM", "PUBLIC"' |
| 241 | + """) |
| 242 | + void setSearchPath_schemaSupport(String searchPath, String expectedSearchPath) throws Exception { |
| 243 | + assumeSchemaSupport(); |
| 244 | + try (var connection = getConnectionViaDriverManager()) { |
| 245 | + connection.setSearchPath(searchPath); |
| 246 | + |
| 247 | + assertEquals(expectedSearchPath, connection.getSearchPath(), "searchPath"); |
| 248 | + } |
| 249 | + } |
| 250 | + |
| 251 | + @Test |
| 252 | + void setSearchPathList_stringArr_noSchemaSupport_throwsFBDriverNotCapable() throws Exception { |
| 253 | + assumeNoSchemaSupport(); |
| 254 | + try (var connection = getConnectionViaDriverManager()) { |
| 255 | + assertThrows(SQLFeatureNotSupportedException.class, () -> connection.setSearchPathList("SYSTEM")); |
| 256 | + } |
| 257 | + } |
| 258 | + |
| 259 | + // As setSearchPathList(String...) goes through setSearchPathList(List<String>), we only tests through the latter |
| 260 | + |
| 261 | + @Test |
| 262 | + void setSearchPathList_stringList_noSchemaSupport_throwsFBDriverNotCapable() throws Exception { |
| 263 | + assumeNoSchemaSupport(); |
| 264 | + try (var connection = getConnectionViaDriverManager()) { |
| 265 | + assertThrows(SQLFeatureNotSupportedException.class, () -> connection.setSearchPathList(List.of("SYSTEM"))); |
| 266 | + } |
| 267 | + } |
| 268 | + |
| 269 | + @Test |
| 270 | + void setSearchPathList_stringList_schemaSupport_empty_notAccepted() throws Exception { |
| 271 | + assumeSchemaSupport(); |
| 272 | + try (var connection = getConnectionViaDriverManager()) { |
| 273 | + var exception = assertThrows(SQLDataException.class, () -> connection.setSearchPathList(List.of())); |
| 274 | + assertThat(exception, message(startsWith("search path must have at least one schema"))); |
| 275 | + } |
| 276 | + } |
| 277 | + |
| 278 | + @ParameterizedTest |
| 279 | + @CsvSource(useHeadersInDisplayName = true, textBlock = """ |
| 280 | + searchPath, expectedSearchPath |
| 281 | + PUBLIC, '"PUBLIC", "SYSTEM"' |
| 282 | + 'PUBLIC, SYSTEM', '"PUBLIC", "SYSTEM"' |
| 283 | + public, '"PUBLIC", "SYSTEM"' |
| 284 | + "public", '"public", "SYSTEM"' |
| 285 | + SCHEMA_1, '"SCHEMA_1", "SYSTEM"' |
| 286 | + "case_sensitive", '"case_sensitive", "SYSTEM"' |
| 287 | + # NOTE Unquoted! |
| 288 | + case_sensitive, '"CASE_SENSITIVE", "SYSTEM"' |
| 289 | + 'SCHEMA_1, "case_sensitive", SYSTEM, PUBLIC', '"SCHEMA_1", "case_sensitive", "SYSTEM", "PUBLIC"' |
| 290 | + """) |
| 291 | + void setSearchPathList_stringList_schemaSupport(String searchPath, String expectedSearchPath) throws Exception { |
| 292 | + assumeSchemaSupport(); |
| 293 | + try (var connection = getConnectionViaDriverManager()) { |
| 294 | + List<String> searchPathList = SearchPathHelper.parseSearchPath(searchPath); |
| 295 | + connection.setSearchPathList(searchPathList); |
| 296 | + |
| 297 | + assertEquals(expectedSearchPath, connection.getSearchPath(), "searchPath"); |
| 298 | + } |
| 299 | + } |
| 300 | + |
206 | 301 | private static void checkSchemaResolution(Connection connection, String expectedSchema) throws SQLException { |
207 | 302 | try (var pstmt = connection.prepareStatement("select * from TABLE_ONE")) { |
208 | 303 | ResultSetMetaData rsmd = pstmt.getMetaData(); |
|
0 commit comments