Test coverage in encryptiontool package 24/78124/4
authorJoss Armstrong <joss.armstrong@ericsson.com>
Fri, 8 Feb 2019 16:29:32 +0000 (16:29 +0000)
committerTakamune Cho <takamune.cho@att.com>
Mon, 11 Feb 2019 14:13:26 +0000 (14:13 +0000)
Increased coverage to 100%

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

index e7c4b71..3792325 100644 (file)
@@ -5,6 +5,8 @@
  * Copyright (C) 2017-2019 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.
@@ -26,16 +28,16 @@ public class Constants
 {
 
     public static final String DBLIB_SERVICE = "org.onap.ccsdk.sli.core.dblib.DBResourceManager";
-    public static final String DEVICE_AUTHENTICATION="DEVICE_AUTHENTICATION";
-    public static final String SCHEMA_SDNCTL="SDNCTL";
+    public static final String DEVICE_AUTHENTICATION = "DEVICE_AUTHENTICATION";
+    public static final String SCHEMA_SDNCTL = "SDNCTL";
 
     private static final String SDNC_CONFIG_DIR_VAR = "SDNC_CONFIG_DIR";
 
-    public static final String APPC_CONFIG_DIR="/opt/onap/appc/data/properties";
+    public static final String APPC_CONFIG_DIR = "/opt/onap/appc/data/properties";
 
-    public static final String VNF_TYPE="vnf_Type";
-    public static final String ACTION="action";
-    public static final String PROTOCOL="protocol";
-    public static final String URL="url";
+    public static final String VNF_TYPE = "vnf_Type";
+    public static final String ACTION = "action";
+    public static final String PROTOCOL = "protocol";
+    public static final String URL = "url";
 
 }
index 9a9d495..94af762 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.
@@ -48,15 +50,15 @@ public class LoadFromDB {
         try {
 
             dbResourceManager = DbServiceUtil.initDbLibService();
-            CachedRowSet data = DbServiceUtil.getData(tableName, argList, Constants.SCHEMA_SDNCTL, getselectData,clause );
+            CachedRowSet data = DbServiceUtil.getData(tableName, argList, Constants.SCHEMA_SDNCTL, getselectData, clause );
 
-            Map <String,String> mp = new HashMap<String,String>();
+            Map <String, String> mp = new HashMap<>();
             while (data.next()) {
 
-              mp.put(data.getString(1)+"."+data.getString(2)+"."+data.getString(3)+"."+"user",data.getString(4));
-              mp.put(data.getString(1)+"."+data.getString(2)+"."+data.getString(3)+"."+"password",data.getString(5));
-              mp.put(data.getString(1)+"."+data.getString(2)+"."+data.getString(3)+"."+"port",data.getString(6));
-              mp.put(data.getString(1)+"."+data.getString(2)+"."+data.getString(3)+"."+"url","");
+              mp.put(data.getString(1) + "." + data.getString(2) + "."+data.getString(3) + "."+"user", data.getString(4));
+              mp.put(data.getString(1) + "." + data.getString(2) + "."+data.getString(3) + "."+"password", data.getString(5));
+              mp.put(data.getString(1) + "." + data.getString(2) + "."+data.getString(3) + "."+"port", data.getString(6));
+              mp.put(data.getString(1) + "." + data.getString(2) + "."+data.getString(3) + "."+"url", "");
               rowCount++;
             }
 
diff --git a/appc-config/appc-encryption-tool/provider/src/test/java/org/onap/appc/encryptiontool/EncryptionToolActivatorTest.java b/appc-config/appc-encryption-tool/provider/src/test/java/org/onap/appc/encryptiontool/EncryptionToolActivatorTest.java
new file mode 100644 (file)
index 0000000..470536a
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * ============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;
+
+import java.util.LinkedList;
+import java.util.List;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.powermock.reflect.Whitebox;
+
+public class EncryptionToolActivatorTest {
+
+    @Test
+    public void testStart() throws Exception {
+        BundleContext bundleContext = Mockito.mock(BundleContext.class);
+        EncryptionToolActivator activator = new EncryptionToolActivator();
+        activator.start(bundleContext);
+        Mockito.verify(bundleContext).registerService(Mockito.anyString(), Mockito.anyObject(), Mockito.any());
+    }
+
+    @Test
+    public void testStop() throws Exception {
+        BundleContext bundleContext = Mockito.mock(BundleContext.class);
+        EncryptionToolActivator activator = new EncryptionToolActivator();
+        List<ServiceRegistration> registrations = new LinkedList<ServiceRegistration>();
+        ServiceRegistration registration = Mockito.mock(ServiceRegistration.class);
+        registrations.add(registration);
+        Whitebox.setInternalState(activator, "registrations", registrations);
+        activator.stop(bundleContext);
+        Mockito.verify(registration).unregister();
+    }
+
+}