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