Merge "Table features : modified yang model. Patch set 2: Modified match types as...
[controller.git] / opendaylight / config / config-manager / src / test / java / org / opendaylight / controller / config / manager / impl / ConfigTransactionControllerImplTest.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.manager.impl;
9
10 import com.google.common.collect.Sets;
11 import org.junit.After;
12 import org.junit.Before;
13 import org.junit.Test;
14 import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
15 import org.opendaylight.controller.config.manager.impl.jmx.BaseJMXRegistrator;
16 import org.opendaylight.controller.config.manager.impl.jmx.TransactionJMXRegistrator;
17 import org.opendaylight.controller.config.manager.impl.jmx.TransactionModuleJMXRegistrator;
18 import org.opendaylight.controller.config.manager.impl.runtimembean.TestingRuntimeBean;
19 import org.opendaylight.controller.config.spi.ModuleFactory;
20 import org.osgi.framework.BundleContext;
21
22 import javax.management.MBeanServer;
23 import javax.management.MBeanServerFactory;
24 import javax.management.ObjectName;
25 import java.lang.management.ManagementFactory;
26 import java.util.HashMap;
27 import java.util.Map;
28 import java.util.Set;
29
30 import static org.junit.Assert.assertEquals;
31
32 public class ConfigTransactionControllerImplTest extends
33         AbstractLockedPlatformMBeanServerTest {
34
35     private BaseJMXRegistrator baseJMXRegistrator;
36
37     private ConfigTransactionControllerImpl testedTxController;
38     private MBeanServer transactionsMBeanServer;
39
40     private static final String transactionName123 = "testTX1";
41     private static final String transactionName4 = "testTX2";
42
43     private static final String moduleName124 = "module124";
44     private static final String moduleName3 = "module3";
45
46     private static final String instanceName134 = "instA";
47     private static final String instanceName2 = "instB";
48
49     private static final ObjectName name1 = ObjectNameUtil
50             .createTransactionModuleON(transactionName123, moduleName124, instanceName134);
51     private static final ObjectName name2 = ObjectNameUtil
52             .createTransactionModuleON(transactionName123, moduleName124, instanceName2);
53     private static final ObjectName name3 = ObjectNameUtil
54             .createTransactionModuleON(transactionName123, moduleName3, instanceName134);
55     private static final ObjectName name4 = ObjectNameUtil
56             .createTransactionModuleON(transactionName4, moduleName124, instanceName134);
57
58     @Before
59     public void setUp() throws Exception {
60         baseJMXRegistrator = new BaseJMXRegistrator(
61                 ManagementFactory.getPlatformMBeanServer());
62         transactionsMBeanServer = MBeanServerFactory.createMBeanServer();
63         Map<String, Map.Entry<ModuleFactory, BundleContext>> currentlyRegisteredFactories = new HashMap<>();
64         TransactionJMXRegistrator jmxRegistrator123 = baseJMXRegistrator
65                 .createTransactionJMXRegistrator(transactionName123);
66
67         testedTxController = new ConfigTransactionControllerImpl(
68                 transactionName123, jmxRegistrator123, 1, 1,
69                 currentlyRegisteredFactories, transactionsMBeanServer,
70                 ManagementFactory.getPlatformMBeanServer(), null);
71         TransactionModuleJMXRegistrator transactionModuleJMXRegistrator123 = testedTxController
72                 .getTxModuleJMXRegistrator();
73         transactionModuleJMXRegistrator123.registerMBean(
74                 new TestingRuntimeBean(), name1);
75         transactionModuleJMXRegistrator123.registerMBean(
76                 new TestingRuntimeBean(), name2);
77         transactionModuleJMXRegistrator123.registerMBean(
78                 new TestingRuntimeBean(), name3);
79         TransactionJMXRegistrator jmxRegistrator4 = baseJMXRegistrator
80                 .createTransactionJMXRegistrator(transactionName4);
81         jmxRegistrator4.createTransactionModuleJMXRegistrator().registerMBean(
82                 new TestingRuntimeBean(), name4);
83     }
84
85     @After
86     public void cleanUp() {
87         baseJMXRegistrator.close();
88         MBeanServerFactory.releaseMBeanServer(transactionsMBeanServer);
89     }
90
91     /**
92      * Tests if lookup method returns all beans with defined transaction name
93      *
94      * @throws Exception
95      */
96     @Test
97     public void testLookupConfigBeans() {
98         Set<ObjectName> beans = testedTxController.lookupConfigBeans();
99         assertEquals(Sets.newHashSet(name1, name2, name3), beans);
100     }
101
102     @Test
103     public void testLookupConfigBeansWithModuleName() {
104         Set<ObjectName> beans = testedTxController
105                 .lookupConfigBeans(moduleName124);
106         assertEquals(Sets.newHashSet(name1, name2), beans);
107     }
108
109     @Test
110     public void lookupConfigBeansWithModuleNameAndImplName() throws Exception {
111         Set<ObjectName> beans = testedTxController.lookupConfigBeans(
112                 moduleName124, instanceName134);
113         assertEquals(Sets.newHashSet(name1), beans);
114     }
115
116 }