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%2FConfigRegistryClientsTest.java;h=0524f0019a1414aa3282f515005b3e10df38aebd;hb=dd281c0e33267296ad3babbffd03e1122cdb127e;hp=4c99c7770a4e3701719e9577fb5ccca7991c5924;hpb=3c23bcbd856bec57ceecbbda3f84bebd4994b0b6;p=controller.git diff --git a/opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/ConfigRegistryClientsTest.java b/opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/ConfigRegistryClientsTest.java index 4c99c7770a..0524f0019a 100644 --- a/opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/ConfigRegistryClientsTest.java +++ b/opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/ConfigRegistryClientsTest.java @@ -7,19 +7,28 @@ */ 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.ConfigRegistry; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThat; +import static org.junit.matchers.JUnitMatchers.hasItem; + +import java.lang.management.ManagementFactory; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; import javax.management.InstanceNotFoundException; import javax.management.MBeanServer; import javax.management.ObjectName; -import java.lang.management.ManagementFactory; -import java.util.Set; -import static org.junit.Assert.assertEquals; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.controller.config.api.ConfigRegistry; + +import com.google.common.collect.Sets; public class ConfigRegistryClientsTest { @@ -27,6 +36,8 @@ public class ConfigRegistryClientsTest { private ObjectName testingRegistryON; private final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); private ConfigRegistryClient jmxRegistryClient; + private ConfigTransactionClient jmxTransactionClient; + private Map map; @Before public void setUp() throws Exception { @@ -35,6 +46,7 @@ public class ConfigRegistryClientsTest { mbs.registerMBean(testingRegistry, testingRegistryON); jmxRegistryClient = new ConfigRegistryJMXClient( ManagementFactory.getPlatformMBeanServer()); + map = new HashMap<>(); } @After @@ -44,10 +56,93 @@ public class ConfigRegistryClientsTest { } } + @Test + public void testCreateTransaction() throws Exception{ + jmxTransactionClient = jmxRegistryClient.createTransaction(); + assertNotNull(jmxTransactionClient); + } + + @Test + public void testGetConfigTransactionClient2() throws Exception{ + jmxTransactionClient = jmxRegistryClient.getConfigTransactionClient("transactionName"); + assertNotNull(jmxTransactionClient); + } + + @Test + public void testGetConfigTransactionClient() throws Exception{ + jmxTransactionClient = jmxRegistryClient.getConfigTransactionClient(testingRegistryON); + assertNotNull(jmxTransactionClient); + } + + @Test(expected = IllegalArgumentException.class) + public void testNewMXBeanProxy() throws Exception{ + if (jmxRegistryClient instanceof ConfigRegistryJMXClient) { + ConfigRegistryJMXClient client = (ConfigRegistryJMXClient) jmxRegistryClient; + assertNull(client.newMXBeanProxy(testingRegistryON, String.class)); + } else { + throw new AssertionError("brm msg"); + } + } + + @Test + public void testBeginConfig() throws Exception{ + Assert.assertNotNull(jmxRegistryClient.beginConfig()); + } + + @Test + public void testCommitConfig() throws Exception{ + assertNull(jmxRegistryClient.commitConfig(testingRegistryON)); + } + + @Test + public void testGetOpenConfigs() throws Exception{ + assertNull(jmxRegistryClient.getOpenConfigs()); + } + + @Test(expected = RuntimeException.class) + public void testGetVersion() throws Exception{ + assertEquals(3, jmxRegistryClient.getVersion()); + } + + @Test + public void testGetAvailableModuleNames() throws Exception{ + assertNull(jmxRegistryClient.getAvailableModuleNames()); + } + + @Test + public void testIsHealthy() throws Exception{ + assertEquals(false, jmxRegistryClient.isHealthy()); + } + + @Test + public void testLookupConfigBeans3() throws Exception{ + Set son = jmxRegistryClient.lookupConfigBeans(); + assertEquals(3, son.size()); + } + + @Test + public void testLookupConfigBeans2() throws Exception{ + Set son = jmxRegistryClient.lookupConfigBeans(TestingConfigRegistry.moduleName1); + assertEquals(2, son.size()); + } + + @Test + public void testLookupConfigBeans() throws Exception{ + Set son = jmxRegistryClient.lookupConfigBeans(TestingConfigRegistry.moduleName1, TestingConfigRegistry.instName1); + Set on = Sets.newHashSet(TestingConfigRegistry.conf2); + assertEquals(on, son); + } + + @Test + public void testLookupConfigBean() throws Exception{ + ObjectName on = jmxRegistryClient.lookupConfigBean(TestingConfigRegistry.moduleName1, null); + assertEquals(TestingConfigRegistry.conf3, on); + } + @Test public void testLookupRuntimeBeans() throws Exception { Set jmxLookup = lookupRuntimeBeans(jmxRegistryClient); - assertEquals(Sets.newHashSet(testingRegistry.run2, testingRegistry.run1, testingRegistry.run3), jmxLookup); + assertEquals(Sets.newHashSet(TestingConfigRegistry.run2, TestingConfigRegistry.run1, TestingConfigRegistry.run3), jmxLookup); } private Set lookupRuntimeBeans(ConfigRegistryClient client) @@ -67,13 +162,13 @@ public class ConfigRegistryClientsTest { jmxRegistryClient, TestingConfigRegistry.moduleName1, TestingConfigRegistry.instName1); assertEquals(1, jmxLookup.size()); - assertEquals(Sets.newHashSet(testingRegistry.run2), jmxLookup); + assertEquals(Sets.newHashSet(TestingConfigRegistry.run2), jmxLookup); jmxLookup = clientLookupRuntimeBeansWithModuleAndInstance( jmxRegistryClient, TestingConfigRegistry.moduleName2, TestingConfigRegistry.instName2); assertEquals(1, jmxLookup.size()); - assertEquals(Sets.newHashSet(testingRegistry.run3), jmxLookup); + assertEquals(Sets.newHashSet(TestingConfigRegistry.run3), jmxLookup); jmxLookup = clientLookupRuntimeBeansWithModuleAndInstance( jmxRegistryClient, TestingConfigRegistry.moduleName1, @@ -91,4 +186,78 @@ public class ConfigRegistryClientsTest { } return beans; } + + @Test + public void testCheckConfigBeanExists() throws Exception{ + jmxRegistryClient.checkConfigBeanExists(testingRegistryON); + assertEquals(true, TestingConfigRegistry.checkBool); + } + + @Test + public void testLookupConfigBeanByServiceInterfaceName() throws Exception{ + ObjectName on = clientLookupConfigBeanByServiceInterfaceName(); + assertEquals(TestingConfigRegistry.conf1, on); + } + + private ObjectName clientLookupConfigBeanByServiceInterfaceName(){ + return jmxRegistryClient.lookupConfigBeanByServiceInterfaceName("qnameA", "refA"); + } + + @Test + public void testGetServiceMapping() throws Exception{ + assertNull(jmxRegistryClient.getServiceMapping()); + } + + @Test + public void testLookupServiceReferencesByServiceInterfaceName() throws Exception{ + map.put("conf2", TestingConfigRegistry.conf2); + assertEquals(map, jmxRegistryClient.lookupServiceReferencesByServiceInterfaceName("qnameB")); + } + + @Test + public void testLookupServiceInterfaceNames() throws Exception{ + assertThat(clientLookupServiceInterfaceNames(testingRegistryON), hasItem(TestingConfigRegistry.serviceQName1)); + assertThat(clientLookupServiceInterfaceNames(testingRegistryON), hasItem(TestingConfigRegistry.serviceQName2)); + } + + private Set clientLookupServiceInterfaceNames(ObjectName client) throws InstanceNotFoundException{ + return jmxRegistryClient.lookupServiceInterfaceNames(client); + } + + @Test + public void testGetServiceInterfaceName() throws Exception{ + assertNull(jmxRegistryClient.getServiceInterfaceName(null, null)); + } + + @Test(expected = RuntimeException.class) + public void testInvokeMethod() throws Exception{ + assertNull(jmxRegistryClient.invokeMethod(testingRegistryON, "name", null, null)); + } + + @Test(expected = RuntimeException.class) + public void testGetAttributeCurrentValue() throws Exception{ + assertNull(jmxRegistryClient.getAttributeCurrentValue(testingRegistryON, "attrName")); + } + + @Test + public void testGetAvailableModuleFactoryQNames() throws Exception{ + for(String str : jmxRegistryClient.getAvailableModuleFactoryQNames()){ + if(str != TestingConfigRegistry.moduleName1){ + assertEquals(TestingConfigRegistry.moduleName2, str); + } + else{ + assertEquals(TestingConfigRegistry.moduleName1, str); + } + } + } + + @Test + public void testGetServiceReference() throws Exception{ + Assert.assertNotNull(jmxRegistryClient.getServiceReference(null, null)); + } + + @Test(expected = UnsupportedOperationException.class) + public void testcheckServiceReferenceExists() throws Exception{ + jmxRegistryClient.checkServiceReferenceExists(testingRegistryON); + } }