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