added file to test VServerInfo.java
[appc.git] / appc-outbound / appc-aai-client / provider / src / test / java / org / onap / appc / aai / client / AppcAaiClientActivatorTest.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright 2019 IBM
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
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.appc.aai.client;
22
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;
31
32 import java.lang.reflect.Field;
33 import java.util.Dictionary;
34 import java.util.List;
35
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;
43
44 @RunWith(MockitoJUnitRunner.class)
45 public class AppcAaiClientActivatorTest {
46
47     AppcAaiClientActivator appcAaiClientActivator;
48     Field registrationsField;
49     @Mock
50     BundleContext ctx;
51     @Mock
52     ServiceRegistration serviceRegistration;
53
54     @Before
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);
61     }
62
63     @Test
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));
69     }
70
71     @Test
72     public void stop() throws Exception {
73         appcAaiClientActivator.start(ctx);
74         appcAaiClientActivator.stop(ctx);
75         verify(serviceRegistration).unregister();
76     }
77 }