From 252c513f9d3278390303cc528b4be02e73e961ce Mon Sep 17 00:00:00 2001 From: Joss Armstrong Date: Thu, 7 Feb 2019 10:33:35 +0000 Subject: Coverage in lock-manager Increased package coverage to 93% Issue-ID: APPC-1400 Change-Id: I4ff2a02466fc7a178c4d411ca4647b1c3877b405 Signed-off-by: Joss Armstrong --- .../lockmanager/impl/sql/JdbcLockManagerTest.java | 50 ++++++++++++++++++++++ .../impl/sql/MySqlConnectionFactoryTest.java | 44 +++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 appc-dispatcher/appc-dispatcher-common/lock-manager-lib/lock-manager-impl/src/test/java/org/onap/appc/lockmanager/impl/sql/JdbcLockManagerTest.java create mode 100644 appc-dispatcher/appc-dispatcher-common/lock-manager-lib/lock-manager-impl/src/test/java/org/onap/appc/lockmanager/impl/sql/MySqlConnectionFactoryTest.java (limited to 'appc-dispatcher') diff --git a/appc-dispatcher/appc-dispatcher-common/lock-manager-lib/lock-manager-impl/src/test/java/org/onap/appc/lockmanager/impl/sql/JdbcLockManagerTest.java b/appc-dispatcher/appc-dispatcher-common/lock-manager-lib/lock-manager-impl/src/test/java/org/onap/appc/lockmanager/impl/sql/JdbcLockManagerTest.java new file mode 100644 index 000000000..919a13c94 --- /dev/null +++ b/appc-dispatcher/appc-dispatcher-common/lock-manager-lib/lock-manager-impl/src/test/java/org/onap/appc/lockmanager/impl/sql/JdbcLockManagerTest.java @@ -0,0 +1,50 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2019 Ericsson + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.lockmanager.impl.sql; + +import java.sql.Connection; +import org.junit.Test; +import org.mockito.Mockito; +import org.onap.appc.dao.util.api.JdbcConnectionFactory; +import org.onap.appc.lockmanager.impl.sql.optimistic.MySqlLockManager; + +public class JdbcLockManagerTest { + + @Test + public void testOpenDbConnection() { + JdbcLockManager manager = new MySqlLockManager(); + JdbcConnectionFactory connectionFactory = Mockito.mock(JdbcConnectionFactory.class); + manager.setConnectionFactory(connectionFactory); + manager.openDbConnection(); + Mockito.verify(connectionFactory).openDbConnection(); + } + + @Test + public void testCloseDbConnection() { + JdbcLockManager manager = new MySqlLockManager(); + JdbcConnectionFactory connectionFactory = Mockito.mock(JdbcConnectionFactory.class); + manager.setConnectionFactory(connectionFactory); + Connection connection = Mockito.mock(Connection.class); + manager.closeDbConnection(connection); + Mockito.verify(connectionFactory).closeDbConnection(connection); + } +} diff --git a/appc-dispatcher/appc-dispatcher-common/lock-manager-lib/lock-manager-impl/src/test/java/org/onap/appc/lockmanager/impl/sql/MySqlConnectionFactoryTest.java b/appc-dispatcher/appc-dispatcher-common/lock-manager-lib/lock-manager-impl/src/test/java/org/onap/appc/lockmanager/impl/sql/MySqlConnectionFactoryTest.java new file mode 100644 index 000000000..cf96a5748 --- /dev/null +++ b/appc-dispatcher/appc-dispatcher-common/lock-manager-lib/lock-manager-impl/src/test/java/org/onap/appc/lockmanager/impl/sql/MySqlConnectionFactoryTest.java @@ -0,0 +1,44 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2019 Ericsson + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.lockmanager.impl.sql; + +import java.sql.SQLException; +import java.sql.DriverManager; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest(DriverManager.class) +public class MySqlConnectionFactoryTest { + + @Test + public void testRegisterDriver() throws SQLException { + PowerMockito.mockStatic(DriverManager.class); + MySqlConnectionFactory factory = new MySqlConnectionFactory(); + factory.registedDriver(); + PowerMockito.verifyStatic(); + } + +} -- cgit 1.2.3-korg