Rework PCEP timers to work on channel
[bgpcep.git] / pcep / tunnel-provider / src / test / java / org / opendaylight / controller / config / yang / pcep / tunnel / provider / PCEPTunnelTopologyProviderModuleTest.java
1 /*
2  * Copyright (c) 2014 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 package org.opendaylight.controller.config.yang.pcep.tunnel.provider;
9
10 import static org.junit.Assert.assertTrue;
11 import static org.junit.Assert.fail;
12
13 import java.util.List;
14 import javax.management.ObjectName;
15 import org.junit.Test;
16 import org.opendaylight.controller.config.api.ValidationException;
17 import org.opendaylight.controller.config.api.jmx.CommitStatus;
18 import org.opendaylight.controller.config.spi.ModuleFactory;
19 import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;
20 import org.opendaylight.controller.config.yang.netty.threadgroup.NettyThreadgroupModuleFactory;
21 import org.opendaylight.controller.config.yang.pcep.impl.PCEPDispatcherImplModuleFactory;
22 import org.opendaylight.controller.config.yang.pcep.impl.PCEPSessionProposalFactoryImplModuleFactory;
23 import org.opendaylight.controller.config.yang.pcep.spi.SimplePCEPExtensionProviderContextModuleFactory;
24 import org.opendaylight.controller.config.yang.pcep.stateful02.cfg.Stateful02PCEPSessionProposalFactoryModuleFactory;
25 import org.opendaylight.controller.config.yang.pcep.topology.provider.PCEPTopologyProviderModuleFactory;
26 import org.opendaylight.controller.config.yang.pcep.topology.provider.PCEPTopologyProviderModuleMXBean;
27 import org.opendaylight.controller.config.yang.pcep.topology.provider.PCEPTopologyProviderModuleTest;
28 import org.opendaylight.controller.config.yang.pcep.topology.provider.Stateful02TopologySessionListenerModuleFactory;
29 import org.opendaylight.controller.config.yang.programming.impl.AbstractInstructionSchedulerTest;
30 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
31
32 public class PCEPTunnelTopologyProviderModuleTest extends AbstractInstructionSchedulerTest {
33
34     private static final String FACTORY_NAME = PCEPTunnelTopologyProviderModuleFactory.NAME;
35     private static final String INSTANCE_NAME = "pcep-tunnel-topology-provider-instance";
36
37     private static final TopologyId TOPOLOGY_ID = new TopologyId("pcep-topology");
38
39     @Test
40     public void testValidationExceptionTopologyIdNotSet() throws Exception {
41         try {
42             createInstance(null);
43             fail();
44         } catch (final ValidationException e) {
45             assertTrue(e.getMessage().contains("TopologyId is not set"));
46         }
47     }
48
49     @Test
50     public void testCreateBean() throws Exception {
51         final CommitStatus status = createInstance();
52         assertBeanCount(1, FACTORY_NAME);
53         assertStatus(status, 16, 0, 0);
54     }
55
56     @Test
57     public void testReusingOldInstance() throws Exception {
58         createInstance();
59         final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
60         assertBeanCount(1, FACTORY_NAME);
61         final CommitStatus status = transaction.commit();
62         assertBeanCount(1, FACTORY_NAME);
63         assertStatus(status, 0, 0, 16);
64     }
65
66     @Test
67     public void testReconfigure() throws Exception {
68         createInstance();
69         final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
70         assertBeanCount(1, FACTORY_NAME);
71         final PCEPTopologyProviderModuleMXBean mxBean = transaction.newMXBeanProxy(
72                 transaction.lookupConfigBean(FACTORY_NAME, INSTANCE_NAME), PCEPTopologyProviderModuleMXBean.class);
73         mxBean.setTopologyId(new TopologyId("new-pcep-topology"));
74         final CommitStatus status = transaction.commit();
75         assertBeanCount(1, FACTORY_NAME);
76         assertStatus(status, 0, 1, 15);
77     }
78
79     private CommitStatus createInstance(final TopologyId topologyId) throws Exception {
80         final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
81         createPCEPTopologyProviderModuleInstance(transaction, topologyId);
82         return transaction.commit();
83     }
84
85     private CommitStatus createInstance() throws Exception {
86         return createInstance(TOPOLOGY_ID);
87     }
88
89     private ObjectName createPCEPTopologyProviderModuleInstance(final ConfigTransactionJMXClient transaction, final TopologyId topologyId)
90             throws Exception {
91         final ObjectName objectName = transaction.createModule(FACTORY_NAME, INSTANCE_NAME);
92         final ObjectName dataBrokerON = createDataBrokerInstance(transaction);
93         final ObjectName notificationBrokerON = createNotificationBrokerInstance(transaction);
94         final ObjectName bindingBrokerON = createBindingBrokerImpl(transaction, dataBrokerON, notificationBrokerON);
95         final ObjectName schedulerON = createInstructionSchedulerModuleInstance(transaction, dataBrokerON, bindingBrokerON,
96                 notificationBrokerON);
97         final ObjectName sourceTopology = PCEPTopologyProviderModuleTest.createPCEPTopologyProviderModuleInstance(transaction,
98                 dataBrokerON, bindingBrokerON, schedulerON);
99
100         final PCEPTunnelTopologyProviderModuleMXBean mxBean = transaction.newMXBeanProxy(objectName,
101                 PCEPTunnelTopologyProviderModuleMXBean.class);
102         mxBean.setDataProvider(dataBrokerON);
103         mxBean.setRpcRegistry(bindingBrokerON);
104         mxBean.setScheduler(schedulerON);
105         mxBean.setTopologyId(topologyId);
106         mxBean.setSourceTopology(sourceTopology);
107         return objectName;
108     }
109
110     @Override
111     public List<ModuleFactory> getModuleFactories() {
112         final List<ModuleFactory> moduleFactories = super.getModuleFactories();
113         moduleFactories.add(new PCEPTunnelTopologyProviderModuleFactory());
114         moduleFactories.add(new PCEPTopologyProviderModuleFactory());
115         moduleFactories.add(new PCEPDispatcherImplModuleFactory());
116         moduleFactories.add(new PCEPSessionProposalFactoryImplModuleFactory());
117         moduleFactories.add(new NettyThreadgroupModuleFactory());
118         moduleFactories.add(new SimplePCEPExtensionProviderContextModuleFactory());
119         moduleFactories.add(new Stateful02TopologySessionListenerModuleFactory());
120         moduleFactories.add(new Stateful02PCEPSessionProposalFactoryModuleFactory());
121         return moduleFactories;
122     }
123
124     @Override
125     public List<String> getYangModelsPaths() {
126         final List<String> paths = super.getYangModelsPaths();
127         paths.add("/META-INF/yang/network-topology@2013-10-21.yang");
128         return paths;
129     }
130 }