BUG-6650: ep-ip/sgt, update/rename models and yangs for sxp-ise-adapter
[groupbasedpolicy.git] / sxp-integration / sxp-ise-adapter / src / test / java / org / opendaylight / controller / config / yang / config / groupbasedpolicy / sxp_integration / sxp_ise_adapter / SxpIseAdapterProviderInstanceTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.config.yang.config.groupbasedpolicy.sxp_integration.sxp_ise_adapter;
10
11 import static org.powermock.api.mockito.PowerMockito.verifyNew;
12 import static org.powermock.api.mockito.PowerMockito.whenNew;
13
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;
33
34 /**
35  * Test for {@link SxpIseAdapterProviderInstance}.
36  */
37 @RunWith(PowerMockRunner.class)
38 @PrepareForTest({SxpIseAdapterProviderInstance.class})
39 public class SxpIseAdapterProviderInstanceTest {
40
41     @Mock
42     private DataBroker dataBroker;
43     @Mock
44     private BindingAwareBroker bindingAwareBroker;
45     @Mock
46     private ClusterSingletonServiceProvider clusterSingletonService;
47     @Mock
48     private SxpEpProviderProvider sxpEpProvider;
49     @Mock
50     private GbpIseAdapterProvider gbpIseAdapterProvider;
51     @Mock
52     private ClusterSingletonServiceRegistration clusterSingletonRegistration;
53
54     private SxpIseAdapterProviderInstance instance;
55
56     @Before
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);
61
62         instance = new SxpIseAdapterProviderInstance(dataBroker, bindingAwareBroker, clusterSingletonService, sxpEpProvider);
63     }
64
65     @After
66     public void tearDown() throws Exception {
67         Mockito.verifyNoMoreInteractions(dataBroker, bindingAwareBroker, clusterSingletonService, sxpEpProvider,
68                 gbpIseAdapterProvider, clusterSingletonRegistration);
69     }
70
71     @Test
72     public void testInitialize() throws Exception {
73         instance.initialize();
74         Mockito.verify(clusterSingletonService).registerClusterSingletonService(instance);
75     }
76
77     @Test
78     public void testInstantiateServiceInstance() throws Exception {
79         instance.instantiateServiceInstance();
80
81         verifyNew(GbpIseAdapterProvider.class).withArguments(dataBroker, bindingAwareBroker, sxpEpProvider);
82     }
83
84     @Test
85     public void testCloseServiceInstance() throws Exception {
86         instance.instantiateServiceInstance();
87         final ListenableFuture<Void> future = instance.closeServiceInstance();
88
89         Mockito.verify(gbpIseAdapterProvider).close();
90         Assert.assertTrue(future.isDone());
91         Assert.assertNull(future.get());
92     }
93
94     @Test
95     public void testCloseServiceInstance_null() throws Exception {
96         final ListenableFuture<Void> future = instance.closeServiceInstance();
97
98         Assert.assertTrue(future.isDone());
99         Assert.assertNull(future.get());
100     }
101
102     @Test
103     public void testClose() throws Exception {
104         instance.initialize();
105         Mockito.verify(clusterSingletonService).registerClusterSingletonService(instance);
106
107         instance.close();
108         Mockito.verify(clusterSingletonRegistration).close();
109     }
110
111     @Test
112     public void testClose_null() throws Exception {
113         instance.close();
114     }
115
116     @Test
117     public void testGetIdentifier() throws Exception {
118         final ServiceGroupIdentifier identifier = instance.getIdentifier();
119         Assert.assertEquals("gbp-service-group-identifier", identifier.getValue());
120     }
121 }