Test coverage for AppcNetconfAdapterActivator 72/77872/3
authorJoss Armstrong <joss.armstrong@ericsson.com>
Tue, 5 Feb 2019 13:59:47 +0000 (13:59 +0000)
committerPatrick Brady <patrick.brady@att.com>
Wed, 6 Feb 2019 21:32:54 +0000 (21:32 +0000)
Added 100% coverage for untested class. Moved other test
file to correct package.

Issue-ID: APPC-1389
Change-Id: I73e768f21d5cda8865f891c63b9ad3f3ea2cce80
Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/AppcNetconfAdapterActivator.java
appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/AppcNetconfAdapterActivatorTest.java [new file with mode: 0644]
appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/OperationalStateValidatorTest.java [moved from appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/OperationalStateValidatorTest.java with 98% similarity]

index 2c44c69..f412223 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.
@@ -61,13 +63,13 @@ public class AppcNetconfAdapterActivator implements BundleActivator {
             /*
             * The reference to the actual implementation object that implements the services
             */
-            NetconfClientFactory clientFactory = new NetconfClientFactory();                
+            NetconfClientFactory clientFactory = new NetconfClientFactory();
             factoryRegistration = context.registerService(NetconfClientFactory.class, clientFactory, null);
             NetconfDataAccessService dataAccessService = new NetconfDataAccessServiceImpl();
             //set dblib service
             ServiceReference sref = context.getServiceReference(DbLibService.class.getName());
             dataAccessService.setDbLibService((DbLibService)context.getService(sref));
-            ///////////////////////////////////
+
             factoryRegistration = context.registerService(NetconfDataAccessService.class, dataAccessService, null);
         }
     }
diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/AppcNetconfAdapterActivatorTest.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/AppcNetconfAdapterActivatorTest.java
new file mode 100644 (file)
index 0000000..c1321ec
--- /dev/null
@@ -0,0 +1,42 @@
+package org.onap.appc.adapter.netconf;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.appc.adapter.netconf.internal.NetconfDataAccessServiceImpl;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.powermock.reflect.Whitebox;
+
+public class AppcNetconfAdapterActivatorTest {
+
+    private BundleContext bundle;
+
+    @Before
+    public void setup() {
+        bundle = Mockito.mock(BundleContext.class);
+    }
+
+    @Test
+    public void testStart() throws Exception {
+        AppcNetconfAdapterActivator activator = new AppcNetconfAdapterActivator();
+        activator.start(bundle);
+        Mockito.verify(bundle, Mockito.times(2)).registerService(Mockito.any(Class.class),
+                Mockito.any(NetconfDataAccessServiceImpl.class), Mockito.any());
+    }
+
+    @Test
+    public void testStop() throws Exception {
+        AppcNetconfAdapterActivator activator = Mockito.spy(new AppcNetconfAdapterActivator());
+        ServiceRegistration registration = Mockito.mock(ServiceRegistration.class);
+        ServiceRegistration reporterRegistration = Mockito.mock(ServiceRegistration.class);
+        ServiceRegistration factoryRegistration = Mockito.mock(ServiceRegistration.class);
+        ServiceRegistration dbRegistration = Mockito.mock(ServiceRegistration.class);
+        Whitebox.setInternalState(activator, "registration", registration);
+        Whitebox.setInternalState(activator, "reporterRegistration", reporterRegistration);
+        Whitebox.setInternalState(activator, "factoryRegistration", factoryRegistration);
+        Whitebox.setInternalState(activator, "dbRegistration", dbRegistration);
+        activator.stop(bundle);
+        Mockito.verify(dbRegistration).unregister();
+    }
+}
@@ -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.
  * ============LICENSE_END=========================================================
  */
 
-import org.onap.appc.exceptions.APPCException;
-import org.junit.Test;
-import org.onap.appc.adapter.netconf.OperationalStateValidator;
-import org.onap.appc.adapter.netconf.OperationalStateValidatorFactory;
-import org.onap.appc.adapter.netconf.VnfType;
+package org.onap.appc.adapter.netconf;
 
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.fail;
+import org.junit.Test;
+import org.onap.appc.exceptions.APPCException;
 
 
 public class OperationalStateValidatorTest {