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=========================================================
20 package org.onap.sdnc.config;
22 import static org.hamcrest.CoreMatchers.is;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertThat;
26 import java.lang.reflect.Field;
27 import java.util.Dictionary;
28 import java.util.List;
30 import org.junit.After;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.mockito.Mock;
35 import org.mockito.Mockito;
36 import org.mockito.MockitoAnnotations;
37 import org.mockito.runners.MockitoJUnitRunner;
38 import org.onap.sdnc.config.params.ParamsHandlerActivator;
39 import org.onap.sdnc.config.params.parser.PropertyDefinitionNode;
40 import org.osgi.framework.BundleContext;
41 import org.osgi.framework.ServiceRegistration;
43 @RunWith(MockitoJUnitRunner.class)
44 public class TestParamsHandlerActivator {
46 ParamsHandlerActivator paramsHandlerActivator;
47 Field registrationsField;
53 ServiceRegistration serviceRegistration;
56 public void setUp() throws Exception {
57 this.paramsHandlerActivator = new ParamsHandlerActivator();
58 this.registrationsField = ParamsHandlerActivator.class.getDeclaredField("registrations");
59 registrationsField.setAccessible(true);
60 MockitoAnnotations.initMocks(this);
61 Mockito.when(ctx.registerService(Mockito.anyString(), Mockito.any(PropertyDefinitionNode.class),
62 Mockito.any(Dictionary.class))).thenReturn(serviceRegistration);
66 public void start() throws Exception {
67 paramsHandlerActivator.start(ctx);
68 List<ServiceRegistration> registrations = (List<ServiceRegistration>) registrationsField
69 .get(paramsHandlerActivator);
70 assertEquals(1, registrations.size());
71 assertThat(registrations.get(0), is(serviceRegistration));
75 public void stop() throws Exception {
76 paramsHandlerActivator.start(ctx);
77 paramsHandlerActivator.stop(ctx);
78 Mockito.verify(serviceRegistration).unregister();
82 public void stopActivator() throws Exception {
83 paramsHandlerActivator.stop(ctx);