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=37b08e4671cd1b424a140799fe6cc47036d33fd9;hb=3927509ec3ecfa32a51b725d2b7155d425f5b877;hp=5ce6d467995f54be7a0644da658741d163515931;hpb=1ff9939abc7a4072b07df6b79516fe344b1b42e3;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 5ce6d46799..37b08e4671 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 @@ -7,24 +7,36 @@ */ 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 com.google.common.collect.Sets; +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.ValidationException; +import org.opendaylight.controller.config.api.ValidationException.ExceptionMessageWithStackTrace; 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; + Attribute attr; + @Before public void setUp() throws Exception { @@ -32,7 +44,8 @@ public class ConfigTransactionClientsTest { transactionControllerON = new ObjectName(ObjectNameUtil.ON_DOMAIN + ":" + ObjectNameUtil.TYPE_KEY + "=TransactionController"); mbs.registerMBean(transactionController, transactionControllerON); - jmxTransactionClient = new ConfigTransactionJMXClient(null, transactionControllerON, + jmxTransactionClient = new ConfigTransactionJMXClient(null, + transactionControllerON, ManagementFactory.getPlatformMBeanServer()); } @@ -47,7 +60,8 @@ public class ConfigTransactionClientsTest { public void testLookupConfigBeans() throws Exception { Set jmxLookup = testClientLookupConfigBeans(jmxTransactionClient); assertEquals(Sets.newHashSet(transactionController.conf1, - transactionController.conf2, transactionController.conf3), jmxLookup); + transactionController.conf2, transactionController.conf3), + jmxLookup); } private Set testClientLookupConfigBeans( @@ -59,4 +73,247 @@ public class ConfigTransactionClientsTest { assertEquals(3, beans.size()); 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()); + } }