Rework BGP timers to work with channel
[bgpcep.git] / bgp / topology-provider / src / test / java / org / opendaylight / controller / config / yang / bgp / topology / provider / LinkstateTopologyBuilderModuleTest.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.bgp.topology.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.bgp.rib.impl.AbstractRIBImplModuleTest;
21 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
22
23 public class LinkstateTopologyBuilderModuleTest extends AbstractRIBImplModuleTest {
24
25     private static final String FACTORY_NAME = LinkstateTopologyBuilderModuleFactory.NAME;
26     private static final String INSTANCE_NAME = "bgp-linkstate-topology-instance";
27
28     @Override
29     protected List<ModuleFactory> getModuleFactories() {
30         final List<ModuleFactory> moduleFactories = super.getModuleFactories();
31         moduleFactories.add(new LinkstateTopologyBuilderModuleFactory());
32         return moduleFactories;
33     }
34
35     @Override
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");
40         return paths;
41     }
42
43     @Test
44     public void testValidationExceptionTopologyIdNotSet() throws Exception {
45         try {
46             createLinkstateTopologyBuilderModuleInstance(null);
47             fail();
48         } catch (final ValidationException e) {
49             assertTrue(e.getMessage().contains("TopologyId is not set."));
50         }
51     }
52
53     @Test
54     public void testCreateBean() throws Exception {
55         final CommitStatus status = createLinkstateTopologyBuilderModuleInstance();
56         assertBeanCount(1, FACTORY_NAME);
57         assertStatus(status, 14, 0, 0);
58     }
59
60     @Test
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);
68     }
69
70     @Test
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);
81     }
82
83     private CommitStatus createLinkstateTopologyBuilderModuleInstance() throws Exception {
84         return createLinkstateTopologyBuilderModuleInstance(new TopologyId("bgp-topology"));
85     }
86
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();
97     }
98 }