2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.config.yang.config.groupbasedpolicy.sxp_integration.sxp_ise_adapter;
11 import static org.powermock.api.mockito.PowerMockito.verifyNew;
12 import static org.powermock.api.mockito.PowerMockito.whenNew;
14 import com.google.common.util.concurrent.ListenableFuture;
15 import org.junit.After;
16 import org.junit.Assert;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.junit.runner.RunWith;
20 import org.mockito.Matchers;
21 import org.mockito.Mock;
22 import org.mockito.Mockito;
23 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
24 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
25 import org.opendaylight.groupbasedpolicy.sxp.ep.provider.spi.SxpEpProviderProvider;
26 import org.opendaylight.groupbasedpolicy.sxp_ise_adapter.impl.GbpIseAdapterProvider;
27 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
28 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
29 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
30 import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
31 import org.powermock.core.classloader.annotations.PrepareForTest;
32 import org.powermock.modules.junit4.PowerMockRunner;
35 * Test for {@link SxpIseAdapterProviderInstance}.
37 @RunWith(PowerMockRunner.class)
38 @PrepareForTest({SxpIseAdapterProviderInstance.class})
39 public class SxpIseAdapterProviderInstanceTest {
42 private DataBroker dataBroker;
44 private BindingAwareBroker bindingAwareBroker;
46 private ClusterSingletonServiceProvider clusterSingletonService;
48 private SxpEpProviderProvider sxpEpProvider;
50 private GbpIseAdapterProvider gbpIseAdapterProvider;
52 private ClusterSingletonServiceRegistration clusterSingletonRegistration;
54 private SxpIseAdapterProviderInstance instance;
57 public void setUp() throws Exception {
58 Mockito.when(clusterSingletonService.registerClusterSingletonService(Matchers.<ClusterSingletonService>any()))
59 .thenReturn(clusterSingletonRegistration);
60 whenNew(GbpIseAdapterProvider.class).withArguments(dataBroker, bindingAwareBroker, sxpEpProvider).thenReturn(gbpIseAdapterProvider);
62 instance = new SxpIseAdapterProviderInstance(dataBroker, bindingAwareBroker, clusterSingletonService, sxpEpProvider);
66 public void tearDown() throws Exception {
67 Mockito.verifyNoMoreInteractions(dataBroker, bindingAwareBroker, clusterSingletonService, sxpEpProvider,
68 gbpIseAdapterProvider, clusterSingletonRegistration);
72 public void testInitialize() throws Exception {
73 instance.initialize();
74 Mockito.verify(clusterSingletonService).registerClusterSingletonService(instance);
78 public void testInstantiateServiceInstance() throws Exception {
79 instance.instantiateServiceInstance();
81 verifyNew(GbpIseAdapterProvider.class).withArguments(dataBroker, bindingAwareBroker, sxpEpProvider);
85 public void testCloseServiceInstance() throws Exception {
86 instance.instantiateServiceInstance();
87 final ListenableFuture<Void> future = instance.closeServiceInstance();
89 Mockito.verify(gbpIseAdapterProvider).close();
90 Assert.assertTrue(future.isDone());
91 Assert.assertNull(future.get());
95 public void testCloseServiceInstance_null() throws Exception {
96 final ListenableFuture<Void> future = instance.closeServiceInstance();
98 Assert.assertTrue(future.isDone());
99 Assert.assertNull(future.get());
103 public void testClose() throws Exception {
104 instance.initialize();
105 Mockito.verify(clusterSingletonService).registerClusterSingletonService(instance);
108 Mockito.verify(clusterSingletonRegistration).close();
112 public void testClose_null() throws Exception {
117 public void testGetIdentifier() throws Exception {
118 final ServiceGroupIdentifier identifier = instance.getIdentifier();
119 Assert.assertEquals("gbp-service-group-identifier", identifier.getValue());