Bug-5588: Missing topology-types in BGP-provided topologies
[bgpcep.git] / bgp / topology-provider / src / test / java / org / opendaylight / controller / config / yang / bgp / topology / provider / Ipv4ReachabilityTopologyBuilderModuleTest.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.reachability.ipv4.Ipv4ReachabilityTopologyBuilderModuleFactory;
21 import org.opendaylight.controller.config.yang.bgp.reachability.ipv4.Ipv4ReachabilityTopologyBuilderModuleMXBean;
22 import org.opendaylight.controller.config.yang.bgp.rib.impl.AbstractRIBImplModuleTest;
23 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
24
25 public class Ipv4ReachabilityTopologyBuilderModuleTest extends AbstractRIBImplModuleTest {
26
27     private static final String FACTORY_NAME = Ipv4ReachabilityTopologyBuilderModuleFactory.NAME;
28     private static final String INSTANCE_NAME = "bgp-reachability-ipv4-instance";
29
30     @Override
31     protected List<ModuleFactory> getModuleFactories() {
32         final List<ModuleFactory> moduleFactories = super.getModuleFactories();
33         moduleFactories.add(new Ipv4ReachabilityTopologyBuilderModuleFactory());
34         return moduleFactories;
35     }
36
37     @Override
38     public List<String> getYangModelsPaths() {
39         final List<String> paths = super.getYangModelsPaths();
40         paths.add("/META-INF/yang/network-topology@2013-10-21.yang");
41         paths.add("/META-INF/yang/l3-unicast-igp-topology@2013-10-21.yang");
42         paths.add("/META-INF/yang/bgp-inet.yang");
43         paths.add("/META-INF/yang/bmp-monitor.yang");
44         paths.add("/META-INF/yang/bmp-message.yang");
45         paths.add("/META-INF/yang/ietf-yang-types.yang");
46         paths.add("/META-INF/yang/odl-bgp-topology-types.yang");
47         return paths;
48     }
49
50     @Test
51     public void testValidationExceptionTopologyIdNotSet() throws Exception {
52         try {
53             createIpv4ReachabilityTopoBuilderModuleInstance(null);
54             fail();
55         } catch (final ValidationException e) {
56             assertTrue(e.getMessage().contains("TopologyId is not set."));
57         }
58     }
59
60     @Test
61     public void testCreateBean() throws Exception {
62         final CommitStatus status = createIpv4ReachabilityTopoBuilderModuleInstance();
63         assertBeanCount(1, FACTORY_NAME);
64         assertStatus(status, 11, 0, 0);
65     }
66
67     @Test
68     public void testReusingOldInstance() throws Exception {
69         createIpv4ReachabilityTopoBuilderModuleInstance();
70         final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
71         assertBeanCount(1, FACTORY_NAME);
72         final CommitStatus status = transaction.commit();
73         assertBeanCount(1, FACTORY_NAME);
74         assertStatus(status, 0, 0, 11);
75     }
76
77     @Test
78     public void testReconfigure() throws Exception {
79         createIpv4ReachabilityTopoBuilderModuleInstance();
80         final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
81         assertBeanCount(1, FACTORY_NAME);
82         final Ipv4ReachabilityTopologyBuilderModuleMXBean mxBean = transaction.newMXBeanProxy(transaction.lookupConfigBean(FACTORY_NAME,
83                 INSTANCE_NAME), Ipv4ReachabilityTopologyBuilderModuleMXBean.class);
84         mxBean.setTopologyId(new TopologyId("new-bgp-topology"));
85         final CommitStatus status = transaction.commit();
86         assertBeanCount(1, FACTORY_NAME);
87         assertStatus(status, 0, 1, 10);
88     }
89
90     private CommitStatus createIpv4ReachabilityTopoBuilderModuleInstance() throws Exception {
91         return createIpv4ReachabilityTopoBuilderModuleInstance(new TopologyId("bgp-topology"));
92     }
93
94     private CommitStatus createIpv4ReachabilityTopoBuilderModuleInstance(final TopologyId topologyId) throws Exception {
95         final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
96         final ObjectName ipv4ReachabilityBuilderON = transaction.createModule(FACTORY_NAME, INSTANCE_NAME);
97         final Ipv4ReachabilityTopologyBuilderModuleMXBean mxBean = transaction.newMXBeanProxy(ipv4ReachabilityBuilderON,
98                 Ipv4ReachabilityTopologyBuilderModuleMXBean.class);
99         final ObjectName dataBrokerON = createAsyncDataBrokerInstance(transaction);
100         mxBean.setDataProvider(dataBrokerON);
101         mxBean.setLocalRib(createRIBImplModuleInstance(transaction, dataBrokerON));
102         mxBean.setTopologyId(topologyId);
103         return transaction.commit();
104     }
105 }