]> git.8kb.co.uk Git - pgpool-ii/pgpool-ii_2.2.5/blob - test/jdbc/PgpoolTest.java
Attempt to send a proper failure message to frontend when authentication
[pgpool-ii/pgpool-ii_2.2.5] / test / jdbc / PgpoolTest.java
1 import java.util.*;
2 import java.io.*;
3 import java.sql.*;
4
5 public abstract class PgpoolTest {
6     protected String url = "jdbc:postgresql://";
7     protected String user;
8     protected String password;
9     protected String dbname;
10     protected String host;
11     protected String port;
12     protected String options;
13     protected Connection connection;
14     protected PrintWriter logwriter;
15
16     public PgpoolTest()
17     {
18         try {
19             Properties prop = new Properties();
20             prop.load(new FileInputStream("pgpool.properties"));
21             host = prop.getProperty("pgpooltest.host");
22             port = prop.getProperty("pgpooltest.port");
23             user = prop.getProperty("pgpooltest.user");
24             password = prop.getProperty("pgpooltest.password");
25             dbname = prop.getProperty("pgpooltest.dbname");
26             options = prop.getProperty("pgpooltest.options");
27             
28             url = url + host + ":" + port + "/" + dbname;
29
30             if (!options.equals(""))
31                 url = url + "?" + options;
32
33             File dir = new File("result");
34             dir.mkdir();
35
36             logwriter = new PrintWriter(new FileWriter("result/" + getTestName()), true);
37             try {
38                 Class.forName("org.postgresql.Driver");
39                 connection = DriverManager.getConnection(url, user, password);
40             } catch (ClassNotFoundException e) {
41                 System.out.println("cannot load JDBC Driver");
42                 System.exit(1);
43             } catch (Exception e) {
44                 System.out.println("cannot connect to pgpool");
45                 System.exit(1);
46             }
47         } catch (Exception e) {
48             System.out.println("cannot read property file");
49             System.exit(1);
50         }
51     }
52
53     public void check() {
54         try {
55             String command_line = "diff -u expected/" + getTestName() + " result/" +
56                 getTestName();
57             Process proc;
58
59             proc = Runtime.getRuntime().exec(command_line);
60             proc.waitFor();
61             System.out.print(getTestName() + ": ");
62             if (proc.exitValue() == 0)
63                 System.out.println("ok");
64             else if (proc.exitValue() == 0)
65                 System.out.println("FAIL");
66             else
67                 System.out.println("unknown error" + proc.exitValue());
68         } catch (Exception e) {
69             e.printStackTrace();
70         }
71     }
72
73     public abstract void do_test() throws SQLException, IOException;
74     public abstract String getTestName();
75 }