2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
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.
19 * ============LICENSE_END=========================================================
22 package org.onap.appc.adapter.ansible;
24 import static org.mockito.BDDMockito.given;
25 import static org.mockito.BDDMockito.then;
26 import static org.mockito.Matchers.eq;
27 import static org.mockito.Matchers.isA;
28 import static org.mockito.Matchers.isNull;
29 import static org.mockito.Mockito.only;
31 import java.util.Dictionary;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.mockito.Mock;
36 import org.mockito.runners.MockitoJUnitRunner;
37 import org.onap.appc.adapter.ansible.impl.AnsibleAdapterImpl;
38 import org.osgi.framework.BundleContext;
39 import org.osgi.framework.ServiceRegistration;
41 @RunWith(MockitoJUnitRunner.class)
43 public class AnsibleActivatorTest {
46 private ServiceRegistration serviceRegistration;
48 private BundleContext bundleContext;
50 private AnsibleActivator ansibleActivator = new AnsibleActivator();
54 given(bundleContext.registerService(eq(AnsibleAdapter.class), isA(AnsibleAdapterImpl.class), isNull(
55 Dictionary.class))).willReturn(serviceRegistration);
59 public void start_shouldRegisterService_whenRegistrationOccursForTheFirstTime() throws Exception {
62 then(bundleContext).should(only())
63 .registerService(eq(AnsibleAdapter.class), isA(AnsibleAdapterImpl.class), isNull(
68 public void start_shouldRegisterServiceOnlyOnce_whenServiceRegistrationIsNotNull() throws Exception {
76 then(bundleContext).should(only()).registerService(eq(AnsibleAdapter.class), isA(AnsibleAdapterImpl.class), isNull(
81 public void stop_shouldUnregisterService_whenServiceRegistrationObjectIsNotNull() throws Exception {
89 then(serviceRegistration).should().unregister();
93 public void stop_shouldNotAttemptToUnregisterService_whenServiceHasAlreadyBeenUnregistered()
103 then(serviceRegistration).should(only()).unregister();
106 private void registerService() throws Exception {
107 ansibleActivator.start(bundleContext);
110 private void unregisterService() throws Exception {
111 ansibleActivator.stop(bundleContext);