Added test case for DbService util 84/78684/2
authorLathishbabu Ganesan <lathishbabu.ganesan@ericsson.com>
Mon, 18 Feb 2019 16:05:01 +0000 (11:05 -0500)
committerTakamune Cho <takamune.cho@att.com>
Mon, 18 Feb 2019 19:37:20 +0000 (19:37 +0000)
Increased the coverage from 22% to 82%

Issue-ID: APPC-1448
Change-Id: I478367d6f5aac4a453b6d711a81c0ee5cefcdd36
Signed-off-by: Lathishbabu Ganesan <lathishbabu.ganesan@ericsson.com>
appc-config/appc-encryption-tool/provider/src/test/java/org/onap/appc/encryptiontool/wrapper/TestDbServiceUtil.java [new file with mode: 0644]

diff --git a/appc-config/appc-encryption-tool/provider/src/test/java/org/onap/appc/encryptiontool/wrapper/TestDbServiceUtil.java b/appc-config/appc-encryption-tool/provider/src/test/java/org/onap/appc/encryptiontool/wrapper/TestDbServiceUtil.java
new file mode 100644 (file)
index 0000000..530a575
--- /dev/null
@@ -0,0 +1,80 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Ericsson. All rights reserved.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.encryptiontool.wrapper;
+
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.when;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+import javax.sql.rowset.CachedRowSet;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.ccsdk.sli.core.dblib.DBResourceManager;
+import org.powermock.reflect.Whitebox;
+
+
+public class TestDbServiceUtil {
+
+    private DBResourceManager jdbcDataSource;
+    private CachedRowSet cachedRowSet;
+    private List<String> argList = new ArrayList<>();
+
+    @Before
+    public void setUp() {
+        jdbcDataSource = Mockito.mock(DBResourceManager.class);
+        cachedRowSet = Mockito.mock(CachedRowSet.class);
+    }
+
+    @Test
+    public void testUpdateDB() throws SQLException {
+        Whitebox.setInternalState(DbServiceUtil.class, "jdbcDataSource", jdbcDataSource);
+        when(jdbcDataSource.writeData(eq("update tableName set  where "), anyObject(), eq(Constants.SCHEMA_SDNCTL)))
+                .thenReturn(true);
+        assertTrue(DbServiceUtil.updateDB("tableName", argList, "", ""));
+    }
+
+    @Test
+    public void testGetData() throws SQLException {
+        Whitebox.setInternalState(DbServiceUtil.class, "jdbcDataSource", jdbcDataSource);
+        when(jdbcDataSource.getData(eq("select from tableName where "), anyObject(), eq(Constants.SCHEMA_SDNCTL)))
+                .thenReturn(cachedRowSet);
+        assertSame(cachedRowSet, DbServiceUtil.getData("tableName", argList, Constants.SCHEMA_SDNCTL, "", ""));
+    }
+
+    @Test
+    public void testDeleteData() throws SQLException {
+        Whitebox.setInternalState(DbServiceUtil.class, "jdbcDataSource", jdbcDataSource);
+        when(jdbcDataSource.writeData(eq("delete from tableName"), anyObject(), eq(Constants.SCHEMA_SDNCTL)))
+                .thenReturn(true);
+        assertTrue(DbServiceUtil.deleteData("tableName", argList));
+    }
+
+    @Test
+    public void testInsertDB() throws SQLException {
+        Whitebox.setInternalState(DbServiceUtil.class, "jdbcDataSource", jdbcDataSource);
+        when(jdbcDataSource.writeData(eq("INSERT INTO  tableName ( )   VALUES ()"), anyObject(),
+                eq(Constants.SCHEMA_SDNCTL))).thenReturn(true);
+        assertTrue(DbServiceUtil.insertDB("tableName", argList, "", ""));
+    }
+}