Test coverage in wrapperEncryptionTool 02/78202/2
authorJoss Armstrong <joss.armstrong@ericsson.com>
Mon, 11 Feb 2019 11:37:11 +0000 (11:37 +0000)
committerTakamune Cho <takamune.cho@att.com>
Mon, 11 Feb 2019 14:15:02 +0000 (14:15 +0000)
Increased coverage from 0% to 81%

Issue-ID: APPC-1409
Change-Id: I1b4d285eff9fad8a60e855a97ff843078d628862
Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/wrapper/WrapperEncryptionTool.java
appc-config/appc-encryption-tool/provider/src/test/java/org/onap/appc/encryptiontool/wrapper/WrapperEncryptionToolTest.java [new file with mode: 0644]

index e29920e..1be6967 100644 (file)
@@ -5,6 +5,8 @@
  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications 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.
@@ -49,8 +51,8 @@ public class WrapperEncryptionTool {
         String action = args[4];
         String port = args[5];
         String url = args[6];
-        log.info("vnfType = " + vnfType + " protocol = " + protocol + " user=" + user + " password=" + password
-                + " action=" + action + " port=" + port + " url=" + url);
+        log.info("vnfType = " + vnfType + " protocol = " + protocol + " " + USER_PARAM + "=" + user + " " + PASS_PARAM
+                + "=" + password + " action=" + action + " " + PORT_PARAM + "=" + port + " " + URL_PARAM + "=" + url);
 
         if (StringUtils.isBlank(user)) {
             log.info("ERROR-USER can not be null");
diff --git a/appc-config/appc-encryption-tool/provider/src/test/java/org/onap/appc/encryptiontool/wrapper/WrapperEncryptionToolTest.java b/appc-config/appc-encryption-tool/provider/src/test/java/org/onap/appc/encryptiontool/wrapper/WrapperEncryptionToolTest.java
new file mode 100644 (file)
index 0000000..5e68150
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * ============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.encryptiontool.wrapper;
+
+import java.io.IOException;
+import java.sql.SQLException;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.onap.ccsdk.sli.core.dblib.DbLibService;
+import org.onap.ccsdk.sli.core.dblib.DBResourceManager;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import com.sun.rowset.CachedRowSetImpl;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest(DbServiceUtil.class)
+public class WrapperEncryptionToolTest {
+
+    private DbLibService dbLibService;
+    private DBResourceManager dbResourceManager;
+
+
+    @Test
+    public void testAnsible() throws SQLException, IOException {
+        PowerMockito.mockStatic(DbServiceUtil.class);
+        dbLibService = Mockito.mock(DbLibService.class);
+        dbResourceManager = Mockito.mock(DBResourceManager.class);
+        CachedRowSetImpl rowset = Mockito.mock(CachedRowSetImpl.class);
+        Mockito.when(rowset.first()).thenReturn(true);
+        Mockito.when(rowset.getString(Mockito.anyString()))
+            .thenReturn(null);
+        PowerMockito.when(DbServiceUtil.getData(Mockito.anyString(), Mockito.anyList(), Mockito.anyString(),
+                Mockito.anyString(), Mockito.anyString())).thenReturn(rowset);
+        PowerMockito.when(DbServiceUtil.initDbLibService()).thenReturn(dbResourceManager);
+        WrapperEncryptionTool.main(new String[] {"VNF-TYPE", "ANSIBLE", "USER", "PASS", "ACTION", "PORT", "URL"});
+        Mockito.verify(dbResourceManager).cleanUp();
+    }
+
+    @Test
+    public void testNonAnsible() throws SQLException, IOException {
+        PowerMockito.mockStatic(DbServiceUtil.class);
+        dbLibService = Mockito.mock(DbLibService.class);
+        dbResourceManager = Mockito.mock(DBResourceManager.class);
+        CachedRowSetImpl rowset = Mockito.mock(CachedRowSetImpl.class);
+        Mockito.when(rowset.first()).thenReturn(true);
+        Mockito.when(rowset.getString(Mockito.anyString()))
+            .thenReturn(null);
+        PowerMockito.when(DbServiceUtil.getData(Mockito.anyString(), Mockito.anyList(), Mockito.anyString(),
+                Mockito.anyString(), Mockito.anyString())).thenReturn(rowset);
+        PowerMockito.when(DbServiceUtil.initDbLibService()).thenReturn(dbResourceManager);
+        WrapperEncryptionTool.main(new String[] {"VNF-TYPE", "TEST", "USER", "PASS", "ACTION", "PORT", "URL"});
+        Mockito.verify(dbResourceManager).cleanUp();
+    }
+}