2 * Copyright (c) 2014 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
8 package org.opendaylight.controller.config.yang.pcep.tunnel.provider;
10 import static org.junit.Assert.assertTrue;
11 import static org.junit.Assert.fail;
13 import java.util.List;
15 import javax.management.ObjectName;
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;
34 public class PCEPTunnelTopologyProviderModuleTest extends AbstractInstructionSchedulerTest {
36 private static final String FACTORY_NAME = PCEPTunnelTopologyProviderModuleFactory.NAME;
37 private static final String INSTANCE_NAME = "pcep-tunnel-topology-provider-instance";
39 private static final TopologyId TOPOLOGY_ID = new TopologyId("pcep-topology");
42 public void testValidationExceptionTopologyIdNotSet() throws Exception {
46 } catch (ValidationException e) {
47 assertTrue(e.getMessage().contains("TopologyId is not set"));
52 public void testCreateBean() throws Exception {
53 CommitStatus status = createInstance();
54 assertBeanCount(1, FACTORY_NAME);
55 assertStatus(status, 17, 0, 0);
59 public void testReusingOldInstance() throws Exception {
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);
69 public void testReconfigure() throws Exception {
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);
81 private CommitStatus createInstance(final TopologyId topologyId) throws Exception {
82 ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
83 createPCEPTopologyProviderModuleInstance(transaction, topologyId);
84 return transaction.commit();
87 private CommitStatus createInstance() throws Exception {
88 return createInstance(TOPOLOGY_ID);
91 private ObjectName createPCEPTopologyProviderModuleInstance(final ConfigTransactionJMXClient transaction, final TopologyId topologyId)
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);
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);
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;
127 public List<String> getYangModelsPaths() {
128 final List<String> paths = super.getYangModelsPaths();
129 paths.add("/META-INF/yang/network-topology@2013-10-21.yang");