2 * Copyright (c) 2017 Pantheon Technologies s.r.o. 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
8 package org.opendaylight.bgpcep.programming.impl;
10 import static org.mockito.Matchers.any;
11 import static org.mockito.Mockito.doAnswer;
12 import static org.mockito.Mockito.doReturn;
13 import static org.mockito.Mockito.timeout;
14 import static org.mockito.Mockito.verify;
15 import static org.mockito.MockitoAnnotations.initMocks;
16 import static org.opendaylight.protocol.util.CheckUtil.checkNotPresentConfiguration;
17 import static org.opendaylight.protocol.util.CheckUtil.checkPresentConfiguration;
19 import io.netty.util.Timer;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.mockito.Mock;
23 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
24 import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest;
25 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
26 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
27 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
28 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.programming.config.rev170301.odl.programming.OdlProgrammingConfig;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.programming.config.rev170301.odl.programming.OdlProgrammingConfigKey;
31 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
32 import org.osgi.framework.BundleContext;
33 import org.osgi.framework.ServiceRegistration;
35 public class InstructionDeployerImplTest extends AbstractConcurrentDataBrokerTest {
37 private RpcProviderRegistry rpcRegistry;
39 private NotificationPublishService notifs;
43 private ClusterSingletonServiceProvider cssp;
45 private ClusterSingletonServiceRegistration singletonServiceRegistration;
47 private BundleContext bundleContext;
49 private ServiceRegistration serviceRegistration;
52 public void setUp() throws Exception {
54 doAnswer(invocationOnMock -> this.singletonServiceRegistration).when(this.cssp)
55 .registerClusterSingletonService(any(ClusterSingletonService.class));
57 doReturn(this.serviceRegistration).when(this.bundleContext).registerService(any(String.class), any(), any());
61 public void testInstructionDeployer() throws Exception {
62 final InstructionDeployerImpl deployer = new InstructionDeployerImpl(getDataBroker(), this.rpcRegistry,
63 this.notifs, this.timer, this.cssp, this.bundleContext);
65 checkPresentConfiguration(getDataBroker(), deployer.getInstructionIID());
67 final String instructionId = "newInstruction";
68 deployer.writeConfiguration(instructionId);
69 final KeyedInstanceIdentifier<OdlProgrammingConfig, OdlProgrammingConfigKey> intructionIID =
70 deployer.getInstructionIID().child(OdlProgrammingConfig.class, new OdlProgrammingConfigKey(instructionId));
71 checkPresentConfiguration(getDataBroker(), intructionIID);
72 verify(this.cssp, timeout(100)).registerClusterSingletonService(any());
73 verify(this.bundleContext, timeout(100)).registerService(any(String.class), any(), any());
75 deployer.removeConfiguration(instructionId);
76 checkNotPresentConfiguration(getDataBroker(), intructionIID);
77 verify(this.singletonServiceRegistration, timeout(100)).close();
78 verify(this.serviceRegistration, timeout(100)).unregister();