From b6509fd1f339a8166c4b2c8a28f6dd7b6f867a60 Mon Sep 17 00:00:00 2001 From: Lathishbabu Ganesan Date: Thu, 7 Feb 2019 06:52:38 -0500 Subject: 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 --- .../instar/node/TestInstarClientActivator.java | 70 ++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 appc-outbound/appc-network-inventory-client/provider/src/test/java/org/onap/appc/instar/node/TestInstarClientActivator.java (limited to 'appc-outbound/appc-network-inventory-client/provider') 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 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 registrations = (List) 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(); + } +} -- cgit 1.2.3-korg