OmniSciDB  04ee39c94c
OmniSciConnectionTest.java
Go to the documentation of this file.
1 package com.omnisci.jdbc;
2 
3 import static org.junit.Assert.*;
4 
5 import org.junit.Test;
6 
7 import java.sql.*;
8 import java.sql.SQLException;
9 import java.util.Properties;
10 
11 public class OmniSciConnectionTest {
12  // Property_loader loads the values from 'connection.properties in resources
13  static Properties PROPERTIES = new Property_loader("connection_test.properties");
14  static final String user = PROPERTIES.getProperty("default_super_user");
15  static final String password = PROPERTIES.getProperty("default_user_password");
16 
17  /* Test the basic connection and methods functionality */
18 
19  @Test
20  public void tst1_binary_unencrypted() {
21  try {
22  String url = PROPERTIES.getProperty("binary_connection_url") + ":"
23  + PROPERTIES.getProperty("default_db");
24  Connection conn = DriverManager.getConnection(url, user, password);
25  assertNotEquals(null, conn);
26  conn.close();
27  boolean closed = conn.isClosed();
28  assertEquals(true, closed);
29  } catch (SQLException sq) {
30  String err = "Connection test failed " + sq.toString();
31  fail(err);
32  }
33  }
34 
35  @Test
36  public void tst1a_binary_encrypted() {
37  try {
38  String url = PROPERTIES.getProperty("binary_connection_url") + ":"
39  + PROPERTIES.getProperty("default_db") + ":binary_tls";
40  String key_store = PROPERTIES.getProperty("server_key_store");
41  ClassLoader cl = getClass().getClassLoader();
42  key_store = cl.getResource(key_store).getPath();
43  Properties pt = new Properties();
44  pt.setProperty("user", user);
45  pt.setProperty("password", password);
46  pt.setProperty("key_store", key_store);
47  pt.setProperty(
48  "key_store_pwd", PROPERTIES.getProperty("server_key_store_password"));
49  Connection conn = DriverManager.getConnection(url, pt);
50  assertNotEquals(null, conn);
51  conn.close();
52  boolean closed = conn.isClosed();
53  assertEquals(true, closed);
54  } catch (SQLException sq) {
55  String err = "Connection test failed " + sq.toString();
56  fail(err);
57  }
58  }
59 
60  @Test
61  public void tst2_http_unencrypted() {
62  try {
63  String url = PROPERTIES.getProperty("http_connection_url") + ":"
64  + PROPERTIES.getProperty("default_db") + ":http";
65  Connection conn = DriverManager.getConnection(url, user, password);
66  assertNotEquals(null, conn);
67  conn.close();
68  boolean closed = conn.isClosed();
69  assertEquals(true, closed);
70  } catch (SQLException sq) {
71  String err = "Connection test failed " + sq.toString();
72  fail(err);
73  }
74  }
75 
76  @Test
77  public void tst3_https_encrypted() {
78  try {
79  Properties pt = new Properties();
80  pt.setProperty("user", user);
81  pt.setProperty("password", password);
82  pt.setProperty("protocol", "https_insecure");
83  String url = PROPERTIES.getProperty("https_connection_url") + ":"
84  + PROPERTIES.getProperty("default_db");
85  Connection conn = DriverManager.getConnection(url, pt);
86  assertNotEquals(null, conn);
87  conn.close();
88  boolean closed = conn.isClosed();
89  assertEquals(true, closed);
90  } catch (SQLException sq) {
91  String err = "Connection test failed " + sq.toString();
92  fail(err);
93  }
94  }
95 
96  @Test
98  try {
99  String key_store = PROPERTIES.getProperty("server_key_store");
100  ClassLoader cl = getClass().getClassLoader();
101 
102  Properties pt = new Properties();
103  pt.setProperty("user", user);
104  pt.setProperty("password", password);
105  pt.setProperty("protocol", "https");
106  key_store = cl.getResource(key_store).getPath();
107  pt.setProperty("key_store", key_store);
108  pt.setProperty(
109  "key_store_pwd", PROPERTIES.getProperty("server_key_store_password"));
110 
111  String url = PROPERTIES.getProperty("https_connection_url") + ":"
112  + PROPERTIES.getProperty("default_db");
113 
114  Connection conn = DriverManager.getConnection(url, pt);
115  conn.close();
116  assertNotEquals(null, conn);
117  boolean closed = conn.isClosed();
118  assertEquals(true, closed);
119 
120  assertNotEquals(null, conn);
121  } catch (SQLException sq) {
122  String err = "Connection test failed " + sq.toString();
123  fail(err);
124  }
125  }
126 
127  @Test
128  public void tst5_connect() {
129  try {
130  String url = PROPERTIES.getProperty("failed_connection_url") + ":"
131  + PROPERTIES.getProperty("default_db");
132  Properties pt = new Properties();
133  pt.setProperty("user", user);
134  pt.setProperty("password", password);
135  Connection conn = DriverManager.getConnection(url, pt);
136  } catch (SQLException sq) {
137  assertEquals(sq.getMessage(),
138  "No suitable driver found for jdbc:NOT_omnisci:localhost:6274:omnisci");
139  return;
140  }
141  String err = "Connection should have thrown";
142  fail(err);
143  }
144 
145  @Test
146  public void tst6_connect() {
147  try {
148  String url = PROPERTIES.getProperty("binary_connection_url") + ":"
149  + PROPERTIES.getProperty("default_db");
150  Properties pt = new Properties();
151  pt.setProperty("user", user);
152  pt.setProperty("password", password);
153  pt.setProperty("db_name", "omnisci");
154  Connection conn = DriverManager.getConnection(url, pt);
155  } catch (SQLException sq) {
156  fail(sq.getMessage());
157  }
158  }
159 
160  @Test
161  public void tst7_connect() {
162  try {
163  String url = PROPERTIES.getProperty("binary_connection_url") + ":"
164  + PROPERTIES.getProperty("default_db");
165  Properties pt = new Properties();
166  pt.setProperty("user", user);
167  pt.setProperty("password", password);
168  pt.setProperty("db_name", "SomeOtherDB");
169  // Shouldn't fail (url over ride properties.
170  Connection conn = DriverManager.getConnection(url, pt);
171  } catch (SQLException sq) {
172  fail(sq.getMessage());
173  }
174  }
175 
176  @Test
177  public void tst8_connect() {
178  try {
179  String url = PROPERTIES.getProperty("default_mapd_connection_url") + ":"
180  + PROPERTIES.getProperty("default_db");
181  Properties pt = new Properties();
182  pt.setProperty("user", user);
183  pt.setProperty("password", password);
184  pt.setProperty("db_name", "SomeOtherDB");
185  // Shouldn't fail (url over ride properties.
186  Connection conn = DriverManager.getConnection(url, pt);
187  } catch (SQLException sq) {
188  fail(sq.getMessage());
189  }
190  }
191 }
static unsigned fail
Definition: testing.h:30