2 * ============LICENSE_START=======================================================
4 * ================================================================================
6 *=================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.appc.aai.client;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.mockito.Mock;
27 import org.mockito.runners.MockitoJUnitRunner;
28 import org.onap.appc.aai.client.node.AAIResourceNode;
29 import org.osgi.framework.BundleContext;
30 import org.osgi.framework.ServiceRegistration;
32 import java.lang.reflect.Field;
33 import java.util.Dictionary;
34 import java.util.List;
36 import static org.hamcrest.CoreMatchers.is;
37 import static org.junit.Assert.assertEquals;
38 import static org.junit.Assert.assertThat;
39 import static org.mockito.Matchers.any;
40 import static org.mockito.Matchers.anyString;
41 import static org.mockito.Mockito.verify;
42 import static org.mockito.Mockito.when;
44 @RunWith(MockitoJUnitRunner.class)
45 public class AppcAaiClientActivatorTest {
47 AppcAaiClientActivator appcAaiClientActivator;
48 Field registrationsField;
52 ServiceRegistration serviceRegistration;
55 public void setUp() throws Exception {
56 this.appcAaiClientActivator = new AppcAaiClientActivator();
57 this.registrationsField = AppcAaiClientActivator.class.getDeclaredField("registrations");
58 registrationsField.setAccessible(true);
59 when(ctx.registerService(anyString(), any(AAIResourceNode.class), any(Dictionary.class)))
60 .thenReturn(serviceRegistration);
64 public void start() throws Exception {
65 appcAaiClientActivator.start(ctx);
66 List<ServiceRegistration> registrations = (List<ServiceRegistration>) registrationsField.get(appcAaiClientActivator);
67 assertEquals(1, registrations.size());
68 assertThat(registrations.get(0), is(serviceRegistration));
72 public void stop() throws Exception {
73 appcAaiClientActivator.start(ctx);
74 appcAaiClientActivator.stop(ctx);
75 verify(serviceRegistration).unregister();