2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
20 * ============LICENSE_END=========================================================
23 package org.onap.appc.adapter.ansible;
25 import static org.mockito.BDDMockito.given;
26 import static org.mockito.BDDMockito.then;
27 import static org.mockito.Matchers.eq;
28 import static org.mockito.Matchers.isA;
29 import static org.mockito.Matchers.isNull;
30 import static org.mockito.Mockito.only;
32 import java.util.Dictionary;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 import org.mockito.Mock;
37 import org.mockito.runners.MockitoJUnitRunner;
38 import org.onap.appc.adapter.ansible.impl.AnsibleAdapterImpl;
39 import org.osgi.framework.BundleContext;
40 import org.osgi.framework.ServiceRegistration;
42 @RunWith(MockitoJUnitRunner.class)
44 public class AnsibleActivatorTest {
47 private ServiceRegistration<AnsibleAdapter> serviceRegistration;
49 private BundleContext bundleContext;
51 private AnsibleActivator ansibleActivator = new AnsibleActivator();
55 given(bundleContext.registerService(eq(AnsibleAdapter.class), isA(AnsibleAdapterImpl.class), isNull(
56 Dictionary.class))).willReturn(serviceRegistration);
60 public void start_shouldRegisterService_whenRegistrationOccursForTheFirstTime() throws Exception {
63 then(bundleContext).should(only())
64 .registerService(eq(AnsibleAdapter.class), isA(AnsibleAdapterImpl.class), isNull(
69 public void start_shouldRegisterServiceOnlyOnce_whenServiceRegistrationIsNotNull() throws Exception {
77 then(bundleContext).should(only()).registerService(eq(AnsibleAdapter.class), isA(AnsibleAdapterImpl.class), isNull(
82 public void stop_shouldUnregisterService_whenServiceRegistrationObjectIsNotNull() throws Exception {
90 then(serviceRegistration).should().unregister();
94 public void stop_shouldNotAttemptToUnregisterService_whenServiceHasAlreadyBeenUnregistered()
104 then(serviceRegistration).should(only()).unregister();
107 private void registerService() throws Exception {
108 ansibleActivator.start(bundleContext);
111 private void unregisterService() throws Exception {
112 ansibleActivator.stop(bundleContext);