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