/* * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.controller.config.util; import com.google.common.collect.Sets; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.opendaylight.controller.config.api.jmx.ObjectNameUtil; import javax.management.MBeanServer; import javax.management.ObjectName; import java.lang.management.ManagementFactory; import java.util.Set; import static org.junit.Assert.assertEquals; public class ConfigTransactionClientsTest { private final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); private TestingConfigTransactionController transactionController; private ObjectName transactionControllerON; private ConfigTransactionClient jmxTransactionClient; @Before public void setUp() throws Exception { transactionController = new TestingConfigTransactionController(); transactionControllerON = new ObjectName(ObjectNameUtil.ON_DOMAIN + ":" + ObjectNameUtil.TYPE_KEY + "=TransactionController"); mbs.registerMBean(transactionController, transactionControllerON); jmxTransactionClient = new ConfigTransactionJMXClient(null, transactionControllerON, ManagementFactory.getPlatformMBeanServer()); } @After public void cleanUp() throws Exception { if (transactionControllerON != null) { mbs.unregisterMBean(transactionControllerON); } } @Test public void testLookupConfigBeans() throws Exception { Set jmxLookup = testClientLookupConfigBeans(jmxTransactionClient); assertEquals(Sets.newHashSet(transactionController.conf1, transactionController.conf2, transactionController.conf3), jmxLookup); } private Set testClientLookupConfigBeans( ConfigTransactionClient client) { Set beans = client.lookupConfigBeans(); for (ObjectName on : beans) { assertEquals("Module", on.getKeyProperty("type")); } assertEquals(3, beans.size()); return beans; } }