2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Ericsson. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
6 * file except in compliance with the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software distributed under the License
11 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12 * or implied. See the License for the specific language governing permissions and limitations under
15 * SPDX-License-Identifier: Apache-2.0
16 * ============LICENSE_END=========================================================
19 package org.onap.appc.instar.node;
21 import static org.junit.Assert.assertNotNull;
22 import static org.mockito.Matchers.anyObject;
23 import static org.mockito.Matchers.eq;
24 import static org.mockito.Mockito.times;
25 import static org.mockito.Mockito.verify;
26 import static org.mockito.Mockito.when;
28 import java.util.LinkedList;
29 import java.util.List;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.mockito.Mockito;
33 import org.mockito.internal.util.reflection.Whitebox;
34 import org.onap.appc.instar.InstarClientActivator;
35 import org.onap.appc.system.node.SourceSystemNode;
36 import org.osgi.framework.BundleContext;
37 import org.osgi.framework.ServiceRegistration;
39 public class TestInstarClientActivator {
41 private BundleContext ctx;
42 private InstarClientActivator instarClientActivatorSpy;
43 ServiceRegistration serviceRegistration;
44 private List<ServiceRegistration> registrations = new LinkedList<>();
48 ctx = Mockito.mock(BundleContext.class);
49 instarClientActivatorSpy = new InstarClientActivator();
50 serviceRegistration = Mockito.mock(ServiceRegistration.class);
51 registrations.add(serviceRegistration);
55 public void testStart() throws Exception {
56 when(ctx.registerService(eq(SourceSystemNode.class.getName()), anyObject(), eq(null)))
57 .thenReturn(serviceRegistration);
58 instarClientActivatorSpy.start(ctx);
59 List<ServiceRegistration> registrations = (List<ServiceRegistration>) Whitebox
60 .getInternalState(instarClientActivatorSpy, "registrations");
61 assertNotNull(registrations.get(0));
65 public void testStop() throws Exception {
66 Whitebox.setInternalState(instarClientActivatorSpy, "registrations", registrations);
67 instarClientActivatorSpy.stop(ctx);
68 verify(serviceRegistration, times(1)).unregister();