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;
12 import java.util.List;
13 import javax.management.ObjectName;
14 import org.junit.Before;
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.stateful07.cfg.PCEPStatefulCapabilityModuleFactory;
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.Stateful07TopologySessionListenerModuleFactory;
29 import org.opendaylight.controller.config.yang.programming.impl.AbstractInstructionSchedulerTest;
30 import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderContext;
31 import org.opendaylight.protocol.pcep.spi.pojo.SimplePCEPExtensionProviderContext;
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");
43 public void setUp() throws Exception {
46 setupMockService(PCEPExtensionProviderContext.class, new SimplePCEPExtensionProviderContext());
50 public void testValidationExceptionTopologyIdNotSet() throws Exception {
54 } catch (final ValidationException e) {
55 assertTrue(e.getMessage().contains("TopologyId is not set"));
60 public void testCreateBean() throws Exception {
61 final CommitStatus status = createInstance();
62 assertBeanCount(1, FACTORY_NAME);
63 assertStatus(status, 18, 0, 0);
67 public void testReusingOldInstance() throws Exception {
69 final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
70 assertBeanCount(1, FACTORY_NAME);
71 final CommitStatus status = transaction.commit();
72 assertBeanCount(1, FACTORY_NAME);
73 assertStatus(status, 0, 0, 18);
77 public void testReconfigure() throws Exception {
79 final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
80 assertBeanCount(1, FACTORY_NAME);
81 final PCEPTopologyProviderModuleMXBean mxBean = transaction.newMXBeanProxy(
82 transaction.lookupConfigBean(FACTORY_NAME, INSTANCE_NAME), PCEPTopologyProviderModuleMXBean.class);
83 mxBean.setTopologyId(new TopologyId("new-pcep-topology"));
84 final CommitStatus status = transaction.commit();
85 assertBeanCount(1, FACTORY_NAME);
86 assertStatus(status, 0, 1, 17);
89 private CommitStatus createInstance(final TopologyId topologyId) throws Exception {
90 final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
91 createPCEPTopologyProviderModuleInstance(transaction, topologyId);
92 return transaction.commit();
95 private CommitStatus createInstance() throws Exception {
96 return createInstance(TOPOLOGY_ID);
99 private ObjectName createPCEPTopologyProviderModuleInstance(final ConfigTransactionJMXClient transaction, final TopologyId topologyId)
101 final ObjectName objectName = transaction.createModule(FACTORY_NAME, INSTANCE_NAME);
102 final ObjectName asyncDataBrokerON = createAsyncDataBrokerInstance(transaction);
103 final ObjectName dataBrokerON = createCompatibleDataBrokerInstance(transaction);
104 final ObjectName notificationBrokerON = createNotificationBrokerInstance(transaction);
105 final ObjectName bindingBrokerON = createBindingBrokerImpl(transaction, dataBrokerON, notificationBrokerON);
106 final ObjectName schedulerON = createInstructionSchedulerModuleInstance(transaction, asyncDataBrokerON, bindingBrokerON,
107 notificationBrokerON);
108 final ObjectName sourceTopology = PCEPTopologyProviderModuleTest.createPCEPTopologyProviderModuleInstance(transaction,
109 asyncDataBrokerON, bindingBrokerON, schedulerON);
111 final PCEPTunnelTopologyProviderModuleMXBean mxBean = transaction.newMXBeanProxy(objectName,
112 PCEPTunnelTopologyProviderModuleMXBean.class);
113 mxBean.setDataProvider(asyncDataBrokerON);
114 mxBean.setRpcRegistry(bindingBrokerON);
115 mxBean.setScheduler(schedulerON);
116 mxBean.setTopologyId(topologyId);
117 mxBean.setSourceTopology(sourceTopology);
122 public List<ModuleFactory> getModuleFactories() {
123 final List<ModuleFactory> moduleFactories = super.getModuleFactories();
124 moduleFactories.add(new PCEPTunnelTopologyProviderModuleFactory());
125 moduleFactories.add(new PCEPTopologyProviderModuleFactory());
126 moduleFactories.add(new PCEPDispatcherImplModuleFactory());
127 moduleFactories.add(new PCEPSessionProposalFactoryImplModuleFactory());
128 moduleFactories.add(new NettyThreadgroupModuleFactory());
129 moduleFactories.add(new SimplePCEPExtensionProviderContextModuleFactory());
130 moduleFactories.add(new Stateful07TopologySessionListenerModuleFactory());
131 moduleFactories.add(new PCEPStatefulCapabilityModuleFactory());
132 return moduleFactories;
136 public List<String> getYangModelsPaths() {
137 final List<String> paths = super.getYangModelsPaths();
138 paths.add("/META-INF/yang/network-topology@2013-10-21.yang");
139 paths.add("/META-INF/yang/network-topology-pcep.yang");
140 paths.add("/META-INF/yang/network-topology-pcep-programming.yang");
141 paths.add("/META-INF/yang/network-topology-programming.yang");
142 paths.add("/META-INF/yang/topology-tunnel.yang");
143 paths.add("/META-INF/yang/topology-tunnel-pcep.yang");
144 paths.add("/META-INF/yang/topology-tunnel-pcep-programming.yang");
145 paths.add("/META-INF/yang/topology-tunnel-p2p.yang");
146 paths.add("/META-INF/yang/topology-tunnel-programming.yang");
147 paths.add("/META-INF/yang/odl-network-topology.yang");
148 paths.add("/META-INF/yang/yang-ext.yang");
149 paths.add("/META-INF/yang/pcep-types.yang");
150 paths.add("/META-INF/yang/rsvp.yang");
151 paths.add("/META-INF/yang/iana.yang");
152 paths.add("/META-INF/yang/network-concepts.yang");
153 paths.add("/META-INF/yang/ieee754.yang");