summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLathishbabu Ganesan <lathishbabu.ganesan@ericsson.com>2019-02-07 06:52:38 -0500
committerTakamune Cho <takamune.cho@att.com>2019-02-07 18:24:56 +0000
commitb6509fd1f339a8166c4b2c8a28f6dd7b6f867a60 (patch)
treec699160c957c9f4beaba705e2758a298f127ad50
parentbfe4a57e79e9baa04159749c0b6e2647b8db0824 (diff)
Added unit test cases for Instar client class
Increased Test coverage from 0% to 100% Issue-ID: APPC-1401 Change-Id: I4b1151d63b2aadf9a98cb147ec9fb4725e817ca2 Signed-off-by: Lathishbabu Ganesan <lathishbabu.ganesan@ericsson.com>
-rw-r--r--appc-outbound/appc-network-inventory-client/provider/src/test/java/org/onap/appc/instar/node/TestInstarClientActivator.java70
1 files changed, 70 insertions, 0 deletions
diff --git a/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/onap/appc/instar/node/TestInstarClientActivator.java b/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/onap/appc/instar/node/TestInstarClientActivator.java
new file mode 100644
index 000000000..3121aec9e
--- /dev/null
+++ b/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/onap/appc/instar/node/TestInstarClientActivator.java
@@ -0,0 +1,70 @@
+/*-
+ * ============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.instar.node;
+
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.LinkedList;
+import java.util.List;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.mockito.internal.util.reflection.Whitebox;
+import org.onap.appc.instar.InstarClientActivator;
+import org.onap.appc.system.node.SourceSystemNode;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+public class TestInstarClientActivator {
+
+ private BundleContext ctx;
+ private InstarClientActivator instarClientActivatorSpy;
+ ServiceRegistration serviceRegistration;
+ private List<ServiceRegistration> registrations = new LinkedList<>();
+
+ @Before
+ public void setUp() {
+ ctx = Mockito.mock(BundleContext.class);
+ instarClientActivatorSpy = new InstarClientActivator();
+ serviceRegistration = Mockito.mock(ServiceRegistration.class);
+ registrations.add(serviceRegistration);
+ }
+
+ @Test
+ public void testStart() throws Exception {
+ when(ctx.registerService(eq(SourceSystemNode.class.getName()), anyObject(), eq(null)))
+ .thenReturn(serviceRegistration);
+ instarClientActivatorSpy.start(ctx);
+ List<ServiceRegistration> registrations = (List<ServiceRegistration>) Whitebox
+ .getInternalState(instarClientActivatorSpy, "registrations");
+ assertNotNull(registrations.get(0));
+ }
+
+ @Test
+ public void testStop() throws Exception {
+ Whitebox.setInternalState(instarClientActivatorSpy, "registrations", registrations);
+ instarClientActivatorSpy.stop(ctx);
+ verify(serviceRegistration, times(1)).unregister();
+ }
+}