Debian Codegraph @

src/test/java/com/zaxxer/hikari/pool/JdbcDriverTest.java

raw
1 /*
2 * Copyright (C) 2014 Brett Wooldridge
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package com.zaxxer.hikari.pool;
17
18 import static com.zaxxer.hikari.pool.TestElf.newHikariConfig;
19 import static org.junit.Assert.assertNotNull;
20 import static org.junit.Assert.assertTrue;
21
22 import java.sql.Connection;
23 import java.sql.SQLException;
24
25 import org.junit.After;
26 import org.junit.Test;
27
28 import com.zaxxer.hikari.HikariConfig;
29 import com.zaxxer.hikari.HikariDataSource;
30 import com.zaxxer.hikari.util.DriverDataSource;
31
32 public class JdbcDriverTest
33 {
34 private HikariDataSource ds;
35
36 @After
37 public void teardown()
38 {
39 if (ds != null) {
40 ds.close();
41 }
42 }
43
44 @Test
45 public void driverTest1() throws SQLException
46 {
47 HikariConfig config = newHikariConfig();
48 config.setMinimumIdle(1);
49 config.setMaximumPoolSize(1);
50 config.setConnectionTestQuery("VALUES 1");
51 config.setDriverClassName("com.zaxxer.hikari.mocks.StubDriver");
52 config.setJdbcUrl("jdbc:stub");
53 config.addDataSourceProperty("user", "bart");
54 config.addDataSourceProperty("password", "simpson");
55
56 ds = new HikariDataSource(config);
57
58 assertTrue(ds.isWrapperFor(DriverDataSource.class));
59
60 DriverDataSource unwrap = ds.unwrap(DriverDataSource.class);
61 assertNotNull(unwrap);
62
63 try (Connection connection = ds.getConnection()) {
64 // test that getConnection() succeeds
65 }
66 }
67
68 @Test
69 public void driverTest2() throws SQLException
70 {
71 HikariConfig config = newHikariConfig();
72
73 config.setMinimumIdle(1);
74 config.setMaximumPoolSize(1);
75 config.setConnectionTestQuery("VALUES 1");
76 config.setDriverClassName("com.zaxxer.hikari.mocks.StubDriver");
77 config.setJdbcUrl("jdbc:invalid");
78
79 try {
80 ds = new HikariDataSource(config);
81 }
82 catch (RuntimeException e) {
83 assertTrue(e.getMessage().contains("claims to not accept"));
84 }
85 }
86 }