2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 AT&T. 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.
18 * ============LICENSE_END=========================================================
21 package org.onap.appc.adapter.iaas;
23 import static org.mockito.BDDMockito.given;
24 import static org.mockito.BDDMockito.then;
25 import static org.mockito.Matchers.eq;
26 import static org.mockito.Matchers.isA;
27 import static org.mockito.Matchers.isNull;
28 import static org.mockito.Mockito.only;
30 import java.util.Dictionary;
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.runners.MockitoJUnitRunner;
36 import org.onap.appc.adapter.iaas.impl.ProviderAdapterImpl;
37 import org.osgi.framework.BundleContext;
38 import org.osgi.framework.ServiceRegistration;
40 @RunWith(MockitoJUnitRunner.class)
41 public class AppcProviderAdapterActivatorTest {
44 private ServiceRegistration serviceRegistration;
46 private BundleContext bundleContext;
48 private AppcProviderAdapterActivator appcProviderAdapterActivator = new AppcProviderAdapterActivator();
52 given(bundleContext.registerService(eq(ProviderAdapter.class), isA(ProviderAdapterImpl.class), isNull(
53 Dictionary.class))).willReturn(serviceRegistration);
57 public void start_shouldRegisterService_whenRegistrationOccursForTheFirstTime() throws Exception {
60 then(bundleContext).should(only())
61 .registerService(eq(ProviderAdapter.class), isA(ProviderAdapterImpl.class), isNull(
66 public void start_shouldRegisterServiceOnlyOnce_whenServiceRegistrationIsNotNull() throws Exception {
74 then(bundleContext).should(only()).registerService(eq(ProviderAdapter.class), isA(ProviderAdapterImpl.class), isNull(
79 public void stop_shouldUnregisterService_whenServiceRegistrationObjectIsNotNull() throws Exception {
87 then(serviceRegistration).should().unregister();
91 public void stop_shouldNotAttemptToUnregisterService_whenServiceHasAlreadyBeenUnregistered()
101 then(serviceRegistration).should(only()).unregister();
104 private void registerService() throws Exception {
105 appcProviderAdapterActivator.start(bundleContext);
108 private void unregisterService() throws Exception {
109 appcProviderAdapterActivator.stop(bundleContext);