cleanup of Deprecated classes for config subsystem
[groupbasedpolicy.git] / sxp-integration / sxp-ep-provider / src / test / java / org / opendaylight / controller / config / yang / config / groupbasedpolicy / sxp_integration / sxp_ep_provider / SxpEpProviderProviderInstanceTest.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_ep_provider;
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.api.DomainSpecificRegistry;
26 import org.opendaylight.groupbasedpolicy.sxp.ep.provider.api.EPPolicyTemplateProviderRegistry;
27 import org.opendaylight.groupbasedpolicy.sxp.ep.provider.api.EPToSgtMapper;
28 import org.opendaylight.groupbasedpolicy.sxp.ep.provider.impl.SxpEpProviderProviderImpl;
29 import org.opendaylight.groupbasedpolicy.sxp.ep.provider.spi.SxpEpProviderProvider;
30 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
31 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
32 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
33 import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.BaseEndpointService;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.groupbasedpolicy.sxp.integration.sxp.ep.provider.model.rev160302.SgtGeneratorConfig;
36 import org.powermock.core.classloader.annotations.PrepareForTest;
37 import org.powermock.modules.junit4.PowerMockRunner;
38
39 /**
40  * Test for {@link SxpEpProviderProviderInstance}.
41  */
42 @RunWith(PowerMockRunner.class)
43 @PrepareForTest({SxpEpProviderProviderInstance.class})
44 public class SxpEpProviderProviderInstanceTest {
45
46     @Mock
47     private DataBroker dataBroker;
48     @Mock
49     private BindingAwareBroker bindingAwareBroker;
50     @Mock
51     private ClusterSingletonServiceProvider clusterSingletonService;
52     @Mock
53     private BaseEndpointService endpointService;
54     @Mock
55     private DomainSpecificRegistry domainSpecificRegistry;
56     @Mock
57     private SgtGeneratorConfig sgtGeneratorConfig;
58     @Mock
59     private SxpEpProviderProvider sxpEpProvider;
60     @Mock
61     private ClusterSingletonServiceRegistration clusterSingletonRegistration;
62     @Mock
63     private SxpEpProviderProviderImpl sxpEpProviderProvider;
64     @Mock
65     private EPToSgtMapper epToSgtMapper;
66     @Mock
67     private EPPolicyTemplateProviderRegistry epPolicyTemplateProviderRegistry;
68
69     private SxpEpProviderProviderInstance instance;
70
71     @Before
72     public void setUp() throws Exception {
73         Mockito.when(clusterSingletonService.registerClusterSingletonService(Matchers.<ClusterSingletonService>any()))
74                 .thenReturn(clusterSingletonRegistration);
75         Mockito.when(sxpEpProviderProvider.getEPToSgtMapper()).thenReturn(epToSgtMapper);
76         Mockito.when(sxpEpProviderProvider.getEPPolicyTemplateProviderRegistry()).thenReturn(epPolicyTemplateProviderRegistry);
77
78         whenNew(SxpEpProviderProviderImpl.class)
79                 .withArguments(dataBroker, endpointService, domainSpecificRegistry, sgtGeneratorConfig)
80                 .thenReturn(sxpEpProviderProvider);
81
82         instance = new SxpEpProviderProviderInstance(dataBroker, endpointService, domainSpecificRegistry,
83                 clusterSingletonService, sgtGeneratorConfig);
84     }
85
86     @After
87     public void tearDown() throws Exception {
88         Mockito.verifyNoMoreInteractions(dataBroker, bindingAwareBroker, clusterSingletonService, sxpEpProvider,
89                 clusterSingletonRegistration, sgtGeneratorConfig, endpointService, domainSpecificRegistry);
90     }
91
92     @Test
93     public void testInitialize() throws Exception {
94         instance.initialize();
95         Mockito.verify(clusterSingletonService).registerClusterSingletonService(instance);
96     }
97
98     @Test
99     public void testInstantiateServiceInstance() throws Exception {
100         instance.instantiateServiceInstance();
101
102         verifyNew(SxpEpProviderProviderImpl.class).withArguments(dataBroker, endpointService, domainSpecificRegistry,
103                 sgtGeneratorConfig);
104     }
105
106     @Test
107     public void testCloseServiceInstance() throws Exception {
108         instance.instantiateServiceInstance();
109         final ListenableFuture<Void> future = instance.closeServiceInstance();
110
111         Mockito.verify(sxpEpProviderProvider).close();
112         Assert.assertTrue(future.isDone());
113         Assert.assertNull(future.get());
114     }
115
116     @Test
117     public void testCloseServiceInstance_null() throws Exception {
118         final ListenableFuture<Void> future = instance.closeServiceInstance();
119
120         Assert.assertTrue(future.isDone());
121         Assert.assertNull(future.get());
122     }
123
124     @Test
125     public void testClose() throws Exception {
126         instance.initialize();
127         Mockito.verify(clusterSingletonService).registerClusterSingletonService(instance);
128
129         instance.close();
130         Mockito.verify(clusterSingletonRegistration).close();
131     }
132
133     @Test
134     public void testClose_null() throws Exception {
135         instance.close();
136     }
137
138     @Test
139     public void testGetIdentifier() throws Exception {
140         final ServiceGroupIdentifier identifier = instance.getIdentifier();
141         Assert.assertEquals("gbp-service-group-identifier", identifier.getValue());
142     }
143
144     @Test
145     public void testGetEPToSgtMapper() throws Exception {
146         instance.instantiateServiceInstance();
147         Assert.assertEquals(epToSgtMapper, instance.getEPToSgtMapper());
148     }
149
150     @Test
151     public void testGetEPPolicyTemplateProviderRegistry() throws Exception {
152         instance.instantiateServiceInstance();
153         Assert.assertEquals(epPolicyTemplateProviderRegistry, instance.getEPPolicyTemplateProviderRegistry());
154     }
155 }