2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.config.util;
10 import static org.junit.Assert.assertEquals;
12 import java.lang.management.ManagementFactory;
15 import javax.management.MBeanServer;
16 import javax.management.ObjectName;
18 import org.junit.After;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.opendaylight.controller.config.api.jmx.ConfigTransactionControllerMXBean;
22 import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
23 import org.opendaylight.controller.config.util.jolokia.ConfigTransactionJolokiaClient;
25 public class ConfigTransactionClientsTest {
27 private final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
28 private String jolokiaURL;
29 private ConfigTransactionControllerMXBean transactionController;
30 private ObjectName transactionControllerON;
31 private ConfigTransactionClient jmxTransactionClient,
32 jolokiaTransactionClient;
35 public void setUp() throws Exception {
36 jolokiaURL = JolokiaHelper.startTestingJolokia();
37 transactionController = new TestingConfigTransactionController();
38 transactionControllerON = new ObjectName(ObjectNameUtil.ON_DOMAIN + ":"
39 + ObjectNameUtil.TYPE_KEY + "=TransactionController");
40 mbs.registerMBean(transactionController, transactionControllerON);
41 jmxTransactionClient = new ConfigTransactionJMXClient(null,
42 transactionControllerON,
43 ManagementFactory.getPlatformMBeanServer());
44 jolokiaTransactionClient = new ConfigTransactionJolokiaClient(
45 jolokiaURL, transactionControllerON, null);
49 public void cleanUp() throws Exception {
50 JolokiaHelper.stopJolokia();
51 if (transactionControllerON != null) {
52 mbs.unregisterMBean(transactionControllerON);
57 public void testLookupConfigBeans() throws Exception {
58 Set<ObjectName> jmxLookup = testClientLookupConfigBeans(jmxTransactionClient);
59 Set<ObjectName> jolokiaLookup = testClientLookupConfigBeans(jolokiaTransactionClient);
60 assertEquals(jmxLookup, jolokiaLookup);
63 private Set<ObjectName> testClientLookupConfigBeans(
64 ConfigTransactionClient client) {
65 Set<ObjectName> beans = client.lookupConfigBeans();
66 for (ObjectName on : beans) {
67 assertEquals("Module", on.getKeyProperty("type"));
69 assertEquals(3, beans.size());