X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-util%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Futil%2FConfigTransactionClientsTest.java;h=2f50513345c2b3ef727a8c027a1206ed78fe8bd9;hb=e316a0ef36279a72767703d190f38a39d7d49395;hp=a6df1e91a5e5188e81137aae8284ab5ad6288d94;hpb=9fb64948564e252018f9b1e13e7cea2c92f991aa;p=controller.git diff --git a/opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/ConfigTransactionClientsTest.java b/opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/ConfigTransactionClientsTest.java index a6df1e91a5..2f50513345 100644 --- a/opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/ConfigTransactionClientsTest.java +++ b/opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/ConfigTransactionClientsTest.java @@ -8,32 +8,41 @@ package org.opendaylight.controller.config.util; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; import java.lang.management.ManagementFactory; +import java.util.Collections; +import java.util.Map; import java.util.Set; +import javax.management.Attribute; +import javax.management.MBeanException; import javax.management.MBeanServer; import javax.management.ObjectName; import org.junit.After; +import org.junit.Assert; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; -import org.opendaylight.controller.config.api.jmx.ConfigTransactionControllerMXBean; +import org.opendaylight.controller.config.api.ValidationException; +import org.opendaylight.controller.config.api.ValidationException.ExceptionMessageWithStackTrace; import org.opendaylight.controller.config.api.jmx.ObjectNameUtil; -import org.opendaylight.controller.config.util.jolokia.ConfigTransactionJolokiaClient; -public class ConfigTransactionClientsTest { +import com.google.common.collect.Sets; +public class ConfigTransactionClientsTest { private final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); - private String jolokiaURL; - private ConfigTransactionControllerMXBean transactionController; + private TestingConfigTransactionController transactionController; private ObjectName transactionControllerON; - private ConfigTransactionClient jmxTransactionClient, - jolokiaTransactionClient; + private ConfigTransactionClient jmxTransactionClient; + Attribute attr; + @Before public void setUp() throws Exception { - jolokiaURL = JolokiaHelper.startTestingJolokia(); transactionController = new TestingConfigTransactionController(); transactionControllerON = new ObjectName(ObjectNameUtil.ON_DOMAIN + ":" + ObjectNameUtil.TYPE_KEY + "=TransactionController"); @@ -41,13 +50,10 @@ public class ConfigTransactionClientsTest { jmxTransactionClient = new ConfigTransactionJMXClient(null, transactionControllerON, ManagementFactory.getPlatformMBeanServer()); - jolokiaTransactionClient = new ConfigTransactionJolokiaClient( - jolokiaURL, transactionControllerON, null); } @After public void cleanUp() throws Exception { - JolokiaHelper.stopJolokia(); if (transactionControllerON != null) { mbs.unregisterMBean(transactionControllerON); } @@ -56,8 +62,9 @@ public class ConfigTransactionClientsTest { @Test public void testLookupConfigBeans() throws Exception { Set jmxLookup = testClientLookupConfigBeans(jmxTransactionClient); - Set jolokiaLookup = testClientLookupConfigBeans(jolokiaTransactionClient); - assertEquals(jmxLookup, jolokiaLookup); + assertEquals(Sets.newHashSet(transactionController.conf1, + transactionController.conf2, transactionController.conf3), + jmxLookup); } private Set testClientLookupConfigBeans( @@ -70,4 +77,246 @@ public class ConfigTransactionClientsTest { return beans; } + @Test + public void testGetObjectName() throws Exception { + testClientGetObjectName(jmxTransactionClient); + assertEquals(testClientGetObjectName(jmxTransactionClient), true); + } + + private boolean testClientGetObjectName(ConfigTransactionClient client) { + return transactionControllerON.equals(client.getObjectName()); + } + + @Test + public void testGetAvailableModuleNames() throws Exception { + Set jmxMN = testClientGetAvailableModuleNames(jmxTransactionClient); + assertNull(jmxMN); + } + + private Set testClientGetAvailableModuleNames( + ConfigTransactionClient client) { + return client.getAvailableModuleNames(); + } + + @Test + public void testGetTransactionName() throws Exception { + String jmxTN = testClientGetTransactionName(jmxTransactionClient); + assertEquals("transactionName", jmxTN); + } + + private String testClientGetTransactionName(ConfigTransactionClient client) { + return client.getTransactionName(); + } + + @Ignore + public void testGetVersion() throws Exception { + long jmxVersion = jmxTransactionClient.getVersion(); + assertNull(jmxVersion); + } + + @Ignore + public void testGetParentVersion() throws Exception { + long jmxParentVersion = jmxTransactionClient.getParentVersion(); + assertNull(jmxParentVersion); + } + + @Test + public void testValidateConfig() throws Exception { + jmxTransactionClient.validateConfig(); + } + + @Test + public void testAbortConfig() throws Exception { + jmxTransactionClient.abortConfig(); + } + + @Test + public void testDestroyModule2() throws Exception { + jmxTransactionClient.destroyModule("moduleB", "instB"); + assertNull(transactionController.conf4); + } + + @Test + public void testDestroyModule() throws Exception { + ObjectName on = testClientCreateModule(jmxTransactionClient); + jmxTransactionClient.destroyModule(on); + } + + @Test + public void testCreateModule() throws Exception { + ObjectName on = testClientCreateModule(jmxTransactionClient); + Assert.assertNotNull(on); + } + + private ObjectName testClientCreateModule(ConfigTransactionClient client) + throws Exception { + return client.createModule("testModuleName", "testInstanceName"); + } + + @Ignore + public void testAssertVersion() { + jmxTransactionClient.assertVersion((int)jmxTransactionClient.getParentVersion(), + (int)jmxTransactionClient.getVersion()); + } + + @Test(expected = NullPointerException.class) + public void testCommit() throws Exception { + jmxTransactionClient.commit(); + } + + @Test + public void testLookupConfigBeans2() throws Exception { + Set jmxLookup = testClientLookupConfigBeans2( + jmxTransactionClient, "moduleB"); + assertEquals(Sets.newHashSet(transactionController.conf3), jmxLookup); + } + + private Set testClientLookupConfigBeans2( + ConfigTransactionClient client, String moduleName) { + Set beans = client.lookupConfigBeans(moduleName); + assertEquals(1, beans.size()); + return beans; + } + + @Test + public void testLookupConfigBean() throws Exception { + Set jmxLookup = testClientLookupConfigBean( + jmxTransactionClient, "moduleB", "instB"); + assertEquals(Sets.newHashSet(transactionController.conf3), jmxLookup); + } + + private Set testClientLookupConfigBean( + ConfigTransactionClient client, String moduleName, + String instanceName) { + Set beans = client.lookupConfigBeans(moduleName, + instanceName); + assertEquals(1, beans.size()); + return beans; + } + + @Test + public void testLookupConfigBeans3() throws Exception { + Set jmxLookup = testClientLookupConfigBeans3( + jmxTransactionClient, "moduleB", "instB"); + assertEquals(Sets.newHashSet(transactionController.conf3), jmxLookup); + } + + private Set testClientLookupConfigBeans3( + ConfigTransactionClient client, String moduleName, + String instanceName) { + Set beans = client.lookupConfigBeans(moduleName, + instanceName); + assertEquals(1, beans.size()); + return beans; + } + + @Test + public void testCheckConfigBeanExists() throws Exception { + jmxTransactionClient.checkConfigBeanExists(transactionControllerON); + assertEquals("configBeanExists", transactionController.check); + } + + @Test + public void testSaveServiceReference() throws Exception { + assertEquals(transactionControllerON, jmxTransactionClient.saveServiceReference("serviceInterfaceName", "refName", transactionControllerON)); + } + + @Test + public void testRemoveServiceReference() throws Exception { + jmxTransactionClient.removeServiceReference("serviceInterface", "refName"); + assertEquals("refName", transactionController.check); + } + + @Test + public void testRemoveAllServiceReferences() throws Exception { + jmxTransactionClient.removeAllServiceReferences(); + assertNull(transactionController.check); + } + + @Test + public void testLookupConfigBeanByServiceInterfaceName() throws Exception { + assertEquals(transactionController.conf3, jmxTransactionClient.lookupConfigBeanByServiceInterfaceName("serviceInterface", "refName")); + } + + @Test + public void testGetServiceMapping() throws Exception { + Assert.assertNotNull(jmxTransactionClient.getServiceMapping()); + } + + @Test + public void testLookupServiceReferencesByServiceInterfaceName() throws Exception { + Assert.assertNotNull(jmxTransactionClient.lookupServiceReferencesByServiceInterfaceName("serviceInterfaceQName")); + } + + @Test + public void testLookupServiceInterfaceNames() throws Exception { + assertEquals(Sets.newHashSet("setA"), jmxTransactionClient.lookupServiceInterfaceNames(transactionControllerON)); + } + + @Test + public void testGetServiceInterfaceName() throws Exception { + assertEquals("namespace" + "localName", jmxTransactionClient.getServiceInterfaceName("namespace", "localName")); + } + + @Test + public void removeServiceReferences() throws Exception { + assertEquals(true, jmxTransactionClient.removeServiceReferences(transactionControllerON)); + } + + @Test + public void testGetServiceReference() throws Exception { + assertEquals(transactionController.conf3, jmxTransactionClient.getServiceReference("serviceInterfaceQName", "refName")); + } + + @Test + public void testCheckServiceReferenceExists() throws Exception { + jmxTransactionClient.checkServiceReferenceExists(transactionControllerON); + assertEquals("referenceExist", transactionController.check); + } + + @Test(expected = RuntimeException.class) + public void testValidateBean() throws Exception { + jmxTransactionClient.validateBean(transactionControllerON); + } + + @Test(expected = ValidationException.class) + public void testValidateBean2() throws Exception { + MBeanServer mbsLocal = mock(MBeanServer.class); + MBeanException mBeanException = new MBeanException(new ValidationException( + Collections.>emptyMap())); + doThrow(mBeanException).when(mbsLocal).invoke(transactionControllerON, "validate", null, null); + + ConfigTransactionJMXClient jmxTransactionClientFake = new ConfigTransactionJMXClient(null, + transactionControllerON, + mbsLocal); + jmxTransactionClientFake.validateBean(transactionControllerON); + } + + @Test(expected = RuntimeException.class) + public void testValidateBean3() throws Exception { + MBeanServer mbsLocal = mock(MBeanServer.class); + MBeanException mBeanException = new MBeanException(new RuntimeException()); + doThrow(mBeanException).when(mbsLocal).invoke(transactionControllerON, "validate", null, null); + ConfigTransactionJMXClient jmxTransactionClientFake = new ConfigTransactionJMXClient(null, + transactionControllerON, + mbsLocal); + jmxTransactionClientFake.validateBean(transactionControllerON); + } + + @Test(expected = IllegalArgumentException.class) + public void testSetAttribute() throws Exception { + attr = null; + jmxTransactionClient.setAttribute(transactionControllerON, "attrName", attr); + } + + @Test(expected = IllegalArgumentException.class) + public void testGetAttribute() throws Exception { + attr = jmxTransactionClient.getAttribute(transactionController.conf3, "attrName"); + assertNull(attr); + } + + @Test + public void testGetAvailableModuleFactoryQNames() throws Exception { + Assert.assertNotNull(jmxTransactionClient.getAvailableModuleFactoryQNames()); + } }