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_ep_provider;
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.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;
40 * Test for {@link SxpEpProviderProviderInstance}.
42 @RunWith(PowerMockRunner.class)
43 @PrepareForTest({SxpEpProviderProviderInstance.class})
44 public class SxpEpProviderProviderInstanceTest {
47 private DataBroker dataBroker;
49 private BindingAwareBroker bindingAwareBroker;
51 private ClusterSingletonServiceProvider clusterSingletonService;
53 private BaseEndpointService endpointService;
55 private DomainSpecificRegistry domainSpecificRegistry;
57 private SgtGeneratorConfig sgtGeneratorConfig;
59 private SxpEpProviderProvider sxpEpProvider;
61 private ClusterSingletonServiceRegistration clusterSingletonRegistration;
63 private SxpEpProviderProviderImpl sxpEpProviderProvider;
65 private EPToSgtMapper epToSgtMapper;
67 private EPPolicyTemplateProviderRegistry epPolicyTemplateProviderRegistry;
69 private SxpEpProviderProviderInstance instance;
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);
78 whenNew(SxpEpProviderProviderImpl.class)
79 .withArguments(dataBroker, endpointService, domainSpecificRegistry, sgtGeneratorConfig)
80 .thenReturn(sxpEpProviderProvider);
82 instance = new SxpEpProviderProviderInstance(dataBroker, endpointService, domainSpecificRegistry,
83 clusterSingletonService, sgtGeneratorConfig);
87 public void tearDown() throws Exception {
88 Mockito.verifyNoMoreInteractions(dataBroker, bindingAwareBroker, clusterSingletonService, sxpEpProvider,
89 clusterSingletonRegistration, sgtGeneratorConfig, endpointService, domainSpecificRegistry);
93 public void testInitialize() throws Exception {
94 instance.initialize();
95 Mockito.verify(clusterSingletonService).registerClusterSingletonService(instance);
99 public void testInstantiateServiceInstance() throws Exception {
100 instance.instantiateServiceInstance();
102 verifyNew(SxpEpProviderProviderImpl.class).withArguments(dataBroker, endpointService, domainSpecificRegistry,
107 public void testCloseServiceInstance() throws Exception {
108 instance.instantiateServiceInstance();
109 final ListenableFuture<Void> future = instance.closeServiceInstance();
111 Mockito.verify(sxpEpProviderProvider).close();
112 Assert.assertTrue(future.isDone());
113 Assert.assertNull(future.get());
117 public void testCloseServiceInstance_null() throws Exception {
118 final ListenableFuture<Void> future = instance.closeServiceInstance();
120 Assert.assertTrue(future.isDone());
121 Assert.assertNull(future.get());
125 public void testClose() throws Exception {
126 instance.initialize();
127 Mockito.verify(clusterSingletonService).registerClusterSingletonService(instance);
130 Mockito.verify(clusterSingletonRegistration).close();
134 public void testClose_null() throws Exception {
139 public void testGetIdentifier() throws Exception {
140 final ServiceGroupIdentifier identifier = instance.getIdentifier();
141 Assert.assertEquals("gbp-service-group-identifier", identifier.getValue());
145 public void testGetEPToSgtMapper() throws Exception {
146 instance.instantiateServiceInstance();
147 Assert.assertEquals(epToSgtMapper, instance.getEPToSgtMapper());
151 public void testGetEPPolicyTemplateProviderRegistry() throws Exception {
152 instance.instantiateServiceInstance();
153 Assert.assertEquals(epPolicyTemplateProviderRegistry, instance.getEPPolicyTemplateProviderRegistry());