BUG-5685: Register BGP Peer Cluster Singleton Service
[bgpcep.git] / bgp / rib-impl / src / test / java / org / opendaylight / controller / config / yang / bgp / rib / impl / RIBImplModuleTest.java
1 /*
2  * Copyright (c) 2013 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.rib.impl;
9
10 import static org.junit.Assert.assertTrue;
11 import static org.junit.Assert.fail;
12 import org.junit.Test;
13 import org.opendaylight.controller.config.api.ValidationException;
14 import org.opendaylight.controller.config.api.jmx.CommitStatus;
15 import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
17
18 public class RIBImplModuleTest extends AbstractRIBImplModuleTest {
19     private static final int EXP_INSTANCES = 7;
20     private static final AsNumber AS_NUMBER = new AsNumber(500L);
21     private static final String INSTANCE_NAME = "rib-impl";
22     private static final String FACTORY_NAME = RIBImplModuleFactory.NAME;
23
24     @Test
25     public void testValidationExceptionRibIdNotSet() throws Exception {
26         try {
27             createRIBImplModuleInstance(null, AS_NUMBER, BGP_ID, CLUSTER_ID);
28             fail();
29         } catch (final ValidationException e) {
30             assertTrue(e.getMessage().contains("RibId is not set."));
31         }
32     }
33
34     @Test
35     public void testValidationExceptionLocalAsNotSet() throws Exception {
36         try {
37             createRIBImplModuleInstance(RIB_ID, null, BGP_ID, CLUSTER_ID);
38             fail();
39         } catch (final ValidationException e) {
40             assertTrue(e.getMessage().contains("LocalAs is not set."));
41         }
42     }
43
44     @Test
45     public void testValidationExceptionBgpIdNotSet() throws Exception {
46         try {
47             createRIBImplModuleInstance(RIB_ID, AS_NUMBER, null, CLUSTER_ID);
48             fail();
49         } catch (final ValidationException e) {
50             assertTrue(e.getMessage().contains("BgpRibId is not set."));
51         }
52     }
53
54     @Test
55     public void testCreateBean() throws Exception {
56         final CommitStatus status = createInstance();
57         assertBeanCount(1, FACTORY_NAME);
58         assertStatus(status, EXP_INSTANCES, 0, 0);
59     }
60
61     @Test
62     public void testReusingOldInstance() throws Exception {
63         createInstance();
64         final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
65         assertBeanCount(1, FACTORY_NAME);
66         final CommitStatus status = transaction.commit();
67         assertBeanCount(1, FACTORY_NAME);
68         assertStatus(status, 0, 0, EXP_INSTANCES);
69     }
70
71     @Test
72     public void testReconfigure() throws Exception {
73         createInstance();
74         final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
75         assertBeanCount(1, FACTORY_NAME);
76         final RIBImplModuleMXBean mxBean = transaction.newMXBeanProxy(transaction.lookupConfigBean(FACTORY_NAME, INSTANCE_NAME),
77                 RIBImplModuleMXBean.class);
78         mxBean.setLocalAs(new AsNumber(100L));
79         final CommitStatus status = transaction.commit();
80         assertBeanCount(1, FACTORY_NAME);
81         assertStatus(status, 0, 1, EXP_INSTANCES - 1);
82     }
83 }