3 import static org.junit.Assert.*;
5 import org.junit.After;
6 import org.junit.Before;
10 import java.util.ArrayList;
11 import java.util.Collections;
12 import java.util.HashMap;
13 import java.util.Properties;
26 static final ArrayList<String>
default_perms =
new ArrayList<String>() {
39 static final String
super_user = PROPERTIES.getProperty(
"default_super_user");
40 static final String
super_password = PROPERTIES.getProperty(
"default_user_password");
42 static final String
user1 = PROPERTIES.getProperty(
"user1");
43 static final String
user1_password = PROPERTIES.getProperty(
"user1_password");
44 static final String
user_url = PROPERTIES.getProperty(
"user_db_connection_url");
45 static final String
user_table1 = PROPERTIES.getProperty(
"tst_table1");
46 static final String
user_table2 = PROPERTIES.getProperty(
"tst_table2");
51 public void setUp() throws Exception {
53 Connection l_conn = DriverManager.getConnection(
54 PROPERTIES.getProperty(
"default_db_connection_url"),
57 Statement st = l_conn.createStatement();
74 Connection default_conn = DriverManager.getConnection(
75 PROPERTIES.getProperty(
"default_db_connection_url"),
78 Statement st = default_conn.createStatement();
84 private void run_command(Statement st, String cmd)
throws SQLException {
86 st.executeUpdate(cmd);
87 }
catch (SQLException sE) {
90 if (0 != sE.getErrorCode()) {
91 System.out.println(
"run_command ERROR");
92 System.out.println(sE.toString());
100 Statement st = x_conn.createStatement();
106 }
catch (SQLException sE) {
107 System.out.println(
"set_user2 ERROR");
108 System.out.println(sE.toString());
116 private void set_user1(
boolean extra_table)
throws Exception {
117 Statement st = m_super_conn.createStatement();
118 Connection
conn = null;
128 st = conn.createStatement();
131 if (extra_table ==
true) {
135 }
catch (SQLException sE) {
136 System.out.println(
"set_user1 ERROR");
137 System.out.println(sE.toString());
141 if (conn != null) conn.close();
146 Statement st = m_super_conn.createStatement();
154 }
catch (SQLException sE) {
155 System.out.println(
"set_user1 ERROR");
156 System.out.println(sE.toString());
166 Statement st = m_super_conn.createStatement();
174 }
catch (SQLException sE) {
175 System.out.println(
"drop_setup ERROR");
176 System.out.println(sE.toString());
185 DatabaseMetaData dM = m_super_conn.getMetaData();
187 assertNotEquals(null, dM.getDatabaseProductVersion());
221 T = PROPERTIES.getProperty(
"base_t3");
237 D = PROPERTIES.getProperty(
"default_db");
239 T = PROPERTIES.getProperty(
"base_table_ptrn");
252 boolean extra_table =
false;
273 boolean extra_table =
false;
294 boolean extra_table =
false;
315 boolean extra_table =
true;
321 T = PROPERTIES.getProperty(
"table_ptrn");
337 boolean extra_table =
true;
341 D = PROPERTIES.getProperty(
"user_db");
343 T = PROPERTIES.getProperty(
"table_ptrn");
347 ArrayList<String> possible_tables =
new ArrayList<String>() {
360 boolean extra_table =
true;
364 D = PROPERTIES.getProperty(
"user_db");
366 T = PROPERTIES.getProperty(
"table_ptrn");
371 ArrayList<String> possible_tables =
new ArrayList<String>() {
385 boolean extra_table =
true;
390 D = PROPERTIES.getProperty(
"user_db");
392 T = PROPERTIES.getProperty(
"table_ptrn");
396 ArrayList<String> possible_tables =
new ArrayList<String>() {
401 PROPERTIES.getProperty(
"user2"),
412 ArrayList<HashMap<String, String>>
rows =
new ArrayList<HashMap<String, String>>();
415 assertEquals(qt.result_count, rows.size());
417 HashMap<String, Integer> record_count_accumulator =
new HashMap<String, Integer>();
418 for (HashMap<String, String> record : rows) {
419 String table_name = record.get(
"TABLE_NAME");
421 assertTrue(possible_tables.contains(table_name));
422 String privilege = record.get(
"PRIVILEGE");
423 String grantee = record.get(
"GRANTEE");
427 String key = table_name + privilege + grantee;
429 record_count_accumulator.put(
430 key, record_count_accumulator.getOrDefault(key, 0) + 1);
435 for (
Integer count : record_count_accumulator.values()) {
437 assertEquals(1, count.intValue());
448 assertEquals(7, privileges.getMetaData().getColumnCount());
450 while (privileges.next()) {
451 HashMap<String, String> record =
new HashMap<String, String>();
452 record.put(
"TABLE_CAT", privileges.getString(
"TABLE_CAT"));
453 record.put(
"TABLE_SCHEM", privileges.getString(
"TABLE_SCHEM"));
454 record.put(
"TABLE_NAME", privileges.getString(
"TABLE_NAME"));
455 record.put(
"PRIVILEGE", privileges.getString(
"PRIVILEGE"));
456 record.put(
"GRANTOR", privileges.getString(
"GRANTOR"));
457 record.put(
"GRANTEE", privileges.getString(
"GRANTEE"));
458 record.put(
"IS_GRANTABLE", privileges.getString(
"IS_GRANTABLE"));
489 int max = m_super_conn.getMetaData().getDatabaseMajorVersion();
490 assertNotEquals(0, max);
491 int min = m_super_conn.getMetaData().getDatabaseMinorVersion();
492 assertNotEquals(0, max);
518 ArrayList<String> sorted_tables =
new ArrayList<String>();
519 int column_count = rs.getMetaData().getColumnCount();
521 for (
int i = 1; i <= column_count; i++) {
522 if (rs.getMetaData().getColumnName(i) ==
"TABLE_NAME") {
523 sorted_tables.add(rs.getString(i));
527 Collections.sort(sorted_tables);
528 return sorted_tables;
533 ArrayList<String> heavyDB_2_tables =
new ArrayList<String>() {
535 add(
"test_base_table1");
536 add(
"test_base_table2");
537 add(
"test_base_table3");
540 ArrayList<String> system_tables =
new ArrayList<String>() {
544 add(
"memory_details");
545 add(
"memory_summary");
547 add(
"role_assignments");
549 add(
"storage_details");
556 ResultSet heavyDB_2_tables_result_set =
557 m_super_conn.getMetaData().
getTables(
"heavyDB_2", null, null, null);
558 ArrayList<String> actual_heavyDB_2_tables =
560 assertEquals(heavyDB_2_tables, actual_heavyDB_2_tables);
562 ResultSet system_tables_result_set =
563 m_super_conn.getMetaData().
getTables(
"information_schema", null, null, null);
564 ArrayList<String> actual_system_tables =
566 assertTrue(actual_system_tables.containsAll(system_tables));