33package org .firebirdsql .jdbc ;
44
55import org .firebirdsql .common .extension .UsesDatabaseExtension ;
6+ import org .firebirdsql .util .FirebirdSupportInfo ;
67import org .junit .jupiter .api .AfterAll ;
78import org .junit .jupiter .api .BeforeAll ;
89import org .junit .jupiter .api .Test ;
910import org .junit .jupiter .api .extension .RegisterExtension ;
11+ import org .junit .jupiter .params .ParameterizedTest ;
12+ import org .junit .jupiter .params .provider .NullSource ;
13+ import org .junit .jupiter .params .provider .ValueSource ;
1014
1115import java .sql .*;
1216import java .util .*;
1317
1418import static org .firebirdsql .common .FBTestProperties .getConnectionViaDriverManager ;
1519import static org .firebirdsql .common .FBTestProperties .getDefaultSupportInfo ;
1620import static org .firebirdsql .common .FBTestProperties .ifSchemaElse ;
21+ import static org .firebirdsql .common .FBTestProperties .resolveSchema ;
22+ import static org .firebirdsql .common .FbAssumptions .assumeFeature ;
1723import static org .firebirdsql .common .JdbcResourceHelper .closeQuietly ;
1824import static org .junit .jupiter .api .Assertions .*;
1925import static org .junit .jupiter .api .Assumptions .assumeTrue ;
2026
2127class FBDatabaseMetaDataPseudoColumnsTest {
2228
23- // TODO Add schema support: tests involving other schema
24-
25- //@formatter:off
2629 private static final String NORMAL_TABLE_NAME = "NORMAL_TABLE" ;
27- private static final String CREATE_NORMAL_TABLE = "create table " + NORMAL_TABLE_NAME + " ( "
28- + " ID integer primary key"
29- + ")" ;
30- private static final String NORMAL_TABLE2_NAME = "NORMAL_TABLE2" ;
31- private static final String CREATE_NORMAL_TABLE2 = "create table " + NORMAL_TABLE2_NAME + " ( "
32- + " ID integer primary key"
33- + ")" ;
30+ private static final String CREATE_NORMAL_TABLE = """
31+ create table NORMAL_TABLE (
32+ ID integer primary key
33+ )""" ;
34+ private static final String CREATE_NORMAL_TABLE2 = """
35+ create table NORMAL_TABLE2 (
36+ ID integer primary key
37+ )""" ;
3438 private static final String SINGLE_VIEW_NAME = "SINGLE_VIEW" ;
3539 private static final String CREATE_SINGLE_VIEW =
36- "create view " + SINGLE_VIEW_NAME + " as select id from " + NORMAL_TABLE_NAME ;
40+ "create view SINGLE_VIEW as select id from NORMAL_TABLE" ;
3741 private static final String MULTI_VIEW_NAME = "MULTI_VIEW" ;
38- private static final String CREATE_MULTI_VIEW = "create view " + MULTI_VIEW_NAME + " as "
39- + "select a.id as id1, b.id as id2 "
40- + "from " + NORMAL_TABLE_NAME + " as a, " + NORMAL_TABLE2_NAME + " as b" ;
42+ private static final String CREATE_MULTI_VIEW =
43+ "create view MULTI_VIEW as select a.id as id1, b.id as id2 from NORMAL_TABLE as a, NORMAL_TABLE2 as b" ;
4144 private static final String EXTERNAL_TABLE_NAME = "EXTERNAL_TABLE" ;
42- private static final String CREATE_EXTERNAL_TABLE = "create table " + EXTERNAL_TABLE_NAME
43- + " external file 'test_external_tbl.dat' ( "
44- + " ID integer not null"
45- + ")" ;
45+ private static final String CREATE_EXTERNAL_TABLE = """
46+ create table EXTERNAL_TABLE
47+ external file 'test_external_tbl.dat' (
48+ ID integer not null
49+ )""" ;
4650 private static final String GTT_PRESERVE_NAME = "GTT_PRESERVE" ;
47- private static final String CREATE_GTT_PRESERVE = "create global temporary table " + GTT_PRESERVE_NAME + " ( "
48- + " ID integer primary key"
49- + ") "
50- + " on commit preserve rows " ;
51+ private static final String CREATE_GTT_PRESERVE = "" "
52+ create global temporary table GTT_PRESERVE (
53+ ID integer primary key
54+ ) on commit preserve rows"" " ;
5155 private static final String GTT_DELETE_NAME = "GTT_DELETE" ;
52- private static final String CREATE_GTT_DELETE = "create global temporary table " + GTT_DELETE_NAME + " ("
53- + " ID integer primary key"
54- + ") "
55- + " on commit delete rows " ;
56- //@formatter:on
56+ private static final String CREATE_GTT_DELETE = """
57+ create global temporary table GTT_DELETE (
58+ ID integer primary key
59+ ) on commit delete rows""" ;
60+ private static final String CREATE_OTHER_SCHEMA = "create schema OTHER_SCHEMA" ;
61+ private static final String NORMAL_TABLE3_NAME = "NORMAL_TABLE3" ;
62+ private static final String CREATE_OTHER_SCHEMA_NORMAL_TABLE3 = """
63+ create table OTHER_SCHEMA.NORMAL_TABLE3 (
64+ ID integer primary key
65+ )""" ;
5766
5867 private static final MetadataResultSetDefinition getPseudoColumnsDefinition =
5968 new MetadataResultSetDefinition (PseudoColumnMetaData .class );
6069
6170 @ RegisterExtension
62- static final UsesDatabaseExtension .UsesDatabaseForAll usesDatabase = UsesDatabaseExtension .usesDatabaseForAll (
63- CREATE_NORMAL_TABLE ,
64- CREATE_NORMAL_TABLE2 ,
65- CREATE_SINGLE_VIEW ,
66- CREATE_MULTI_VIEW ,
67- CREATE_EXTERNAL_TABLE ,
68- CREATE_GTT_PRESERVE ,
69- CREATE_GTT_DELETE );
71+ static final UsesDatabaseExtension .UsesDatabaseForAll usesDatabase =
72+ UsesDatabaseExtension .usesDatabaseForAll (getDbInitStatements ());
7073
7174 private static final boolean supportsRecordVersion = getDefaultSupportInfo ()
7275 .supportsRecordVersionPseudoColumn ();
@@ -80,6 +83,24 @@ static void setupAll() throws SQLException {
8083 dbmd = con .getMetaData ();
8184 }
8285
86+ private static List <String > getDbInitStatements () {
87+ var statements = new ArrayList <>(List .of (
88+ CREATE_NORMAL_TABLE ,
89+ CREATE_NORMAL_TABLE2 ,
90+ CREATE_SINGLE_VIEW ,
91+ CREATE_MULTI_VIEW ,
92+ CREATE_EXTERNAL_TABLE ,
93+ CREATE_GTT_PRESERVE ,
94+ CREATE_GTT_DELETE ));
95+ if (getDefaultSupportInfo ().supportsSchemas ()) {
96+ statements .addAll (List .of (
97+ CREATE_OTHER_SCHEMA ,
98+ CREATE_OTHER_SCHEMA_NORMAL_TABLE3 ));
99+ }
100+
101+ return statements ;
102+ }
103+
83104 @ AfterAll
84105 static void tearDownAll () throws SQLException {
85106 try {
@@ -100,12 +121,14 @@ void testPseudoColumnsMetaDataColumns() throws Exception {
100121 }
101122 }
102123
103- @ Test
104- void testNormalTable_allPseudoColumns () throws Exception {
124+ @ ParameterizedTest
125+ @ NullSource
126+ @ ValueSource (strings = { "%" , "PUBLIC" })
127+ void testNormalTable_allPseudoColumns (String schemaPattern ) throws Exception {
105128 List <Map <PseudoColumnMetaData , Object >> validationRules =
106129 createStandardValidationRules (NORMAL_TABLE_NAME , "NO" );
107130
108- ResultSet pseudoColumns = dbmd .getPseudoColumns (null , null , NORMAL_TABLE_NAME , "%" );
131+ ResultSet pseudoColumns = dbmd .getPseudoColumns (null , resolveSchema ( schemaPattern ) , NORMAL_TABLE_NAME , "%" );
109132 validate (pseudoColumns , validationRules );
110133 }
111134
@@ -253,8 +276,9 @@ void testPattern_wildCardTable() throws Exception {
253276 tableCount += 1 ;
254277 }
255278
256- // System tables + the 7 tables created for this test
257- assertEquals (getDefaultSupportInfo ().getSystemTableCount () + 7 , tableCount ,
279+ // System tables + the tables created for this test
280+ int testTableCount = getDefaultSupportInfo ().supportsSchemas () ? 8 : 7 ;
281+ assertEquals (getDefaultSupportInfo ().getSystemTableCount () + testTableCount , tableCount ,
258282 "Unexpected number of pseudo columns" );
259283 }
260284 }
@@ -267,12 +291,25 @@ void testPattern_nullTable() throws Exception {
267291 tableCount += 1 ;
268292 }
269293
270- // System tables + the 7 tables created for this test
271- assertEquals (getDefaultSupportInfo ().getSystemTableCount () + 7 , tableCount ,
294+ // System tables + the tables created for this test
295+ int testTableCount = getDefaultSupportInfo ().supportsSchemas () ? 8 : 7 ;
296+ assertEquals (getDefaultSupportInfo ().getSystemTableCount () + testTableCount , tableCount ,
272297 "Unexpected number of pseudo columns" );
273298 }
274299 }
275300
301+ @ ParameterizedTest
302+ @ NullSource
303+ @ ValueSource (strings = { "%" , "OTHER_SCHEMA" , "OTHER\\ _SCHEMA" , "OTHER%" })
304+ void testOtherSchemaNormalTable2_allPseudoColumns (String schemaPattern ) throws Exception {
305+ assumeFeature (FirebirdSupportInfo ::supportsSchemas , "Test requires schema support" );
306+ List <Map <PseudoColumnMetaData , Object >> validationRules =
307+ createStandardValidationRules ("OTHER_SCHEMA" , NORMAL_TABLE3_NAME , "NO" );
308+
309+ ResultSet pseudoColumns = dbmd .getPseudoColumns (null , schemaPattern , NORMAL_TABLE3_NAME , "%" );
310+ validate (pseudoColumns , validationRules );
311+ }
312+
276313 private List <Map <PseudoColumnMetaData , Object >> createStandardValidationRules (String tableName ,
277314 String recordVersionNullable ) {
278315 return createStandardValidationRules (ifSchemaElse ("PUBLIC" , null ), tableName , recordVersionNullable );
@@ -342,6 +379,7 @@ private Map<PseudoColumnMetaData, Object> createDbkeyValidationRules(String sche
342379 return rules ;
343380 }
344381
382+ @ SuppressWarnings ("SameParameterValue" )
345383 private Map <PseudoColumnMetaData , Object > createRecordVersionValidationRules (String tableName , String nullable ) {
346384 return createRecordVersionValidationRules (ifSchemaElse ("PUBLIC" , null ), tableName , nullable );
347385 }
0 commit comments