Add blueprint XML for bgp-evpn
[bgpcep.git] / bgp / flowspec / src / test / java / org / opendaylight / controller / config / yang / bgp / flowspec / FlowspecModuleTest.java
1 /*
2  * Copyright (c) 2015 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.flowspec;
9
10 import com.google.common.collect.Lists;
11 import javax.management.ObjectName;
12 import org.junit.Before;
13 import org.junit.Test;
14 import org.opendaylight.controller.config.api.jmx.CommitStatus;
15 import org.opendaylight.controller.config.manager.impl.AbstractConfigTest;
16 import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver;
17 import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;
18 import org.opendaylight.controller.config.yang.bgp.parser.spi.SimpleBGPExtensionProviderContextModuleFactory;
19 import org.opendaylight.controller.config.yang.bgp.parser.spi.SimpleBGPExtensionProviderContextModuleTest;
20 import org.opendaylight.controller.config.yang.bgp.rib.spi.RIBExtensionsImplModuleFactory;
21 import org.opendaylight.controller.config.yang.bgp.rib.spi.RIBExtensionsImplModuleTest;
22
23 /**
24  * Created by cgasparini on 18.6.2015.
25  */
26 public class FlowspecModuleTest extends AbstractConfigTest {
27
28     private static final String FACTORY_NAME = FlowspecModuleFactory.NAME;
29     private static final String INSTANCE_NAME = "bgp-flowspec-impl";
30
31     @Before
32     public void setUp() {
33         super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(mockedContext, new FlowspecModuleFactory(),
34             new SimpleBGPExtensionProviderContextModuleFactory(), new RIBExtensionsImplModuleFactory()));
35     }
36
37     @Test
38     public void testLSTypeDefaultValue() throws Exception {
39         final CommitStatus status = createFlowspecModuleInstance();
40         assertBeanCount(1, FACTORY_NAME);
41         assertStatus(status, 3, 0, 0);
42     }
43
44     @Test
45     public void testCreateBean() throws Exception {
46         final CommitStatus status = createFlowspecModuleInstance();
47         assertBeanCount(1, FACTORY_NAME);
48         assertStatus(status, 3, 0, 0);
49     }
50
51     @Test
52     public void testReusingOldInstance() throws Exception {
53         createFlowspecModuleInstance();
54         final ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
55         assertBeanCount(1, FACTORY_NAME);
56         final CommitStatus status = transaction.commit();
57         assertBeanCount(1, FACTORY_NAME);
58         assertStatus(status, 0, 0, 3);
59     }
60
61     @Test
62     public void testReconfigureInstance() throws Exception {
63         createFlowspecModuleInstance();
64         ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
65         assertBeanCount(1, FACTORY_NAME);
66         CommitStatus status = transaction.commit();
67         assertBeanCount(1, FACTORY_NAME);
68         assertStatus(status, 0, 0, 3);
69     }
70
71     private CommitStatus createFlowspecModuleInstance() throws Exception {
72         final ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
73         final ObjectName flowspecON = transaction.createModule(FACTORY_NAME, INSTANCE_NAME);
74
75         SimpleBGPExtensionProviderContextModuleTest.createBGPExtensionsModuleInstance(transaction, Lists.newArrayList(flowspecON));
76         RIBExtensionsImplModuleTest.createRIBExtensionsModuleInstance(transaction, Lists.newArrayList(flowspecON));
77         return transaction.commit();
78     }
79
80 }