2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * ================================================================================
9 * Modifications (C) 2019 Ericsson
10 * =============================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * ============LICENSE_END=========================================================
26 package org.onap.appc.dao.util.dbcp;
28 import org.junit.After;
29 import org.junit.Assert;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.onap.appc.dao.util.exception.DBConnectionPoolException;
34 import java.sql.Connection;
35 import java.sql.SQLException;
39 public class DBConnectionPoolTest {
40 private final String connectURI = "jdbc:h2:mem:~/test;MODE=MYSQL;DB_CLOSE_DELAY=-1";
41 private final String username = "sa";
42 private final String password = "sa";
43 private final String driverClass = "org.h2.Driver";
45 private DBConnectionPool dbcp;
46 private DBConnectionPool dbcp2;
47 private Connection connection;
50 public void setUp() throws Exception {
51 dbcp = new DBConnectionPool(connectURI, username, password, driverClass);
52 dbcp2 = new DBConnectionPool(connectURI, username, password, driverClass);
56 public void testGetConnection() {
58 connection = dbcp.getConnection();
59 } catch (DBConnectionPoolException e) {
60 Assert.fail(e.getMessage());
62 Assert.assertNotNull(connection);
66 public void testGetDataSourceStatus() {
67 Map<String, Integer> dataSourceStatus = dbcp.getDataSourceStatus();
68 Assert.assertNotNull(dataSourceStatus);
71 @Test(expected = DBConnectionPoolException.class)
72 public void testShutdown() throws DBConnectionPoolException {
74 connection = dbcp2.getConnection();
75 Assert.assertNull(connection);
86 if (connection != null) {
89 } catch (SQLException e) {