27fca1704808d874576ff08a0d5a414e02827f9e
[bgpcep.git] / bgp / rib-impl / src / test / java / org / opendaylight / controller / config / yang / bgp / rib / impl / BaseBGPParserModuleTest.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
9 package org.opendaylight.controller.config.yang.bgp.rib.impl;
10
11 import org.junit.Before;
12 import org.junit.Test;
13 import org.opendaylight.controller.config.api.jmx.CommitStatus;
14 import org.opendaylight.controller.config.manager.impl.AbstractConfigTest;
15 import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver;
16 import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;
17
18 public class BaseBGPParserModuleTest extends AbstractConfigTest {
19
20     private static final String INSTANCE_NAME = "bgp-parser-instance";
21     private static final String FACTORY_NAME = BaseBGPParserModuleFactory.NAME;
22
23     @Before
24     public void setUp() throws Exception {
25         super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(this.mockedContext, new BaseBGPParserModuleFactory()));
26     }
27
28     @Test
29     public void testCreateBean() throws Exception {
30         final CommitStatus status = createInstance();
31         assertBeanCount(1, FACTORY_NAME);
32         assertStatus(status, 1, 0, 0);
33     }
34
35     @Test
36     public void testReusingOldInstance() throws Exception {
37         createInstance();
38         final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
39         assertBeanCount(1, FACTORY_NAME);
40         final CommitStatus status = transaction.commit();
41         assertBeanCount(1, FACTORY_NAME);
42         assertStatus(status, 0, 0, 1);
43     }
44
45     private CommitStatus createInstance() throws Exception {
46         final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
47         transaction.createModule(FACTORY_NAME, INSTANCE_NAME);
48         return transaction.commit();
49     }
50 }