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.bgp.topology.provider;
10 import static org.junit.Assert.assertTrue;
11 import static org.junit.Assert.fail;
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.bgp.rib.impl.AbstractRIBImplModuleTest;
21 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
23 public class LinkstateTopologyBuilderModuleTest extends AbstractRIBImplModuleTest {
25 private static final String FACTORY_NAME = LinkstateTopologyBuilderModuleFactory.NAME;
26 private static final String INSTANCE_NAME = "bgp-linkstate-topology-instance";
29 protected List<ModuleFactory> getModuleFactories() {
30 final List<ModuleFactory> moduleFactories = super.getModuleFactories();
31 moduleFactories.add(new LinkstateTopologyBuilderModuleFactory());
32 return moduleFactories;
36 public List<String> getYangModelsPaths() {
37 final List<String> paths = super.getYangModelsPaths();
38 paths.add("/META-INF/yang/network-topology@2013-10-21.yang");
39 paths.add("/META-INF/yang/l3-unicast-igp-topology@2013-10-21.yang");
44 public void testValidationExceptionTopologyIdNotSet() throws Exception {
46 createLinkstateTopologyBuilderModuleInstance(null);
48 } catch (final ValidationException e) {
49 assertTrue(e.getMessage().contains("TopologyId is not set."));
54 public void testCreateBean() throws Exception {
55 final CommitStatus status = createLinkstateTopologyBuilderModuleInstance();
56 assertBeanCount(1, FACTORY_NAME);
57 assertStatus(status, 14, 0, 0);
61 public void testReusingOldInstance() throws Exception {
62 createLinkstateTopologyBuilderModuleInstance();
63 final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
64 assertBeanCount(1, FACTORY_NAME);
65 final CommitStatus status = transaction.commit();
66 assertBeanCount(1, FACTORY_NAME);
67 assertStatus(status, 0, 0, 14);
71 public void testReconfigure() throws Exception {
72 createLinkstateTopologyBuilderModuleInstance();
73 final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
74 assertBeanCount(1, FACTORY_NAME);
75 final LinkstateTopologyBuilderModuleMXBean mxBean = transaction.newMXBeanProxy(transaction.lookupConfigBean(FACTORY_NAME,
76 INSTANCE_NAME), LinkstateTopologyBuilderModuleMXBean.class);
77 mxBean.setTopologyId(new TopologyId("new-bgp-topology"));
78 final CommitStatus status = transaction.commit();
79 assertBeanCount(1, FACTORY_NAME);
80 assertStatus(status, 0, 1, 13);
83 private CommitStatus createLinkstateTopologyBuilderModuleInstance() throws Exception {
84 return createLinkstateTopologyBuilderModuleInstance(new TopologyId("bgp-topology"));
87 private CommitStatus createLinkstateTopologyBuilderModuleInstance(final TopologyId topologyId) throws Exception {
88 final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
89 final ObjectName linkstateTopoBuilderON = transaction.createModule(FACTORY_NAME, INSTANCE_NAME);
90 final LinkstateTopologyBuilderModuleMXBean mxBean = transaction.newMXBeanProxy(linkstateTopoBuilderON,
91 LinkstateTopologyBuilderModuleMXBean.class);
92 final ObjectName dataBrokerON = createDataBrokerInstance(transaction);
93 mxBean.setDataProvider(dataBrokerON);
94 mxBean.setLocalRib(createRIBImplModuleInstance(transaction, dataBrokerON));
95 mxBean.setTopologyId(topologyId);
96 return transaction.commit();