From: Maros Marsalek Date: Tue, 9 Sep 2014 07:25:17 +0000 (+0200) Subject: Bug 1520 - Increased test coverage X-Git-Tag: release/helium~114 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=76cc965bd2d9978fedcbe19603c98e7752abf5a8 Bug 1520 - Increased test coverage Added new tests for ConfigTransactionClients Change-Id: I0b31e37902804594dda3683556005a3b40414048 Signed-off-by: Igor Bartak Signed-off-by: Maros Marsalek --- diff --git a/opendaylight/config/config-util/pom.xml b/opendaylight/config/config-util/pom.xml index fd9c1b91e3..29a5526451 100644 --- a/opendaylight/config/config-util/pom.xml +++ b/opendaylight/config/config-util/pom.xml @@ -23,6 +23,10 @@ guava test + + org.opendaylight.yangtools + mockito-configuration + diff --git a/opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/AttributeEntryTest.java b/opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/AttributeEntryTest.java new file mode 100644 index 0000000000..b2afd3542e --- /dev/null +++ b/opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/AttributeEntryTest.java @@ -0,0 +1,32 @@ +package org.opendaylight.controller.config.util; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class AttributeEntryTest { + + private AttributeEntry attributeEntryClient; + private final String key = "myKey"; + private final String description = "myDescription"; + private final String type = "myType"; + private final boolean boolValue = false; + + @Before + public void setUp() throws Exception { + attributeEntryClient = new AttributeEntry("myKey", "myDescription", null, "myType", false); + } + + @Test + public void testAttributeEntryGetters() throws Exception{ + assertEquals(key, attributeEntryClient.getKey()); + assertEquals(description, attributeEntryClient.getDescription()); + final Object value = attributeEntryClient.getValue(); + assertNull(value); + assertEquals(type, attributeEntryClient.getType()); + assertEquals(boolValue, attributeEntryClient.isRw()); + } +} 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 13043458c0..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,6 +56,89 @@ 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); @@ -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); + } } 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..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 @@ -7,24 +7,39 @@ */ package org.opendaylight.controller.config.util; -import com.google.common.collect.Sets; +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.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; +import com.google.common.collect.Sets; 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 +47,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 +63,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 +76,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()); + } } diff --git a/opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/TestingConfigRegistry.java b/opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/TestingConfigRegistry.java index e0d4c85943..ab6cda935b 100644 --- a/opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/TestingConfigRegistry.java +++ b/opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/TestingConfigRegistry.java @@ -7,6 +7,7 @@ */ package org.opendaylight.controller.config.util; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; @@ -26,20 +27,31 @@ import com.google.common.collect.Sets; public class TestingConfigRegistry implements ConfigRegistryMXBean { static final ObjectName conf1, conf2, conf3, run1, run2, run3; + public static String check; + public static boolean checkBool; + private Map map = new HashMap<>(); public static final String moduleName1 = "moduleA"; public static final String moduleName2 = "moduleB"; public static final String instName1 = "instA"; public static final String instName2 = "instB"; + public static final String refName1 = "refA"; + public static final String refName2 = "refB"; + public static final String serviceQName1 = "qnameA"; + public static final String serviceQName2 = "qnameB"; static { conf1 = ObjectNameUtil.createON(ObjectNameUtil.ON_DOMAIN + ":type=Module," + ObjectNameUtil.MODULE_FACTORY_NAME_KEY - + "=" + moduleName1); + + "=" + moduleName1 + "," + ObjectNameUtil.SERVICE_QNAME_KEY + + "=" + serviceQName1 + "," + ObjectNameUtil.REF_NAME_KEY + + "=" + refName1); conf2 = ObjectNameUtil.createON(ObjectNameUtil.ON_DOMAIN + ":type=Module," + ObjectNameUtil.MODULE_FACTORY_NAME_KEY + "=" + moduleName1 + "," + ObjectNameUtil.INSTANCE_NAME_KEY - + "=" + instName1); + + "=" + instName1 + "," + ObjectNameUtil.SERVICE_QNAME_KEY + + "=" + serviceQName2 + "," + ObjectNameUtil.REF_NAME_KEY + + "=" + refName1); conf3 = ObjectNameUtil.createON(ObjectNameUtil.ON_DOMAIN + ":type=Module," + ObjectNameUtil.MODULE_FACTORY_NAME_KEY + "=" + moduleName2 + "," + ObjectNameUtil.INSTANCE_NAME_KEY @@ -55,11 +67,15 @@ public class TestingConfigRegistry implements ConfigRegistryMXBean { + ":type=RuntimeBean," + ObjectNameUtil.MODULE_FACTORY_NAME_KEY + "=" + moduleName2 + "," + ObjectNameUtil.INSTANCE_NAME_KEY + "=" + instName2); + + check = null; + checkBool = false; + } @Override public ObjectName beginConfig() { - return null; + return conf2; } @Override @@ -146,42 +162,60 @@ public class TestingConfigRegistry implements ConfigRegistryMXBean { @Override public void checkConfigBeanExists(ObjectName objectName) throws InstanceNotFoundException { - throw new UnsupportedOperationException(); + Set configBeans = Sets. newHashSet(run1, run2, run3); + if(configBeans.size()>0){ + checkBool = true; + } } @Override public ObjectName lookupConfigBeanByServiceInterfaceName(String serviceInterfaceQName, String refName) { - throw new UnsupportedOperationException(); + if (serviceInterfaceQName.equals(serviceQName1) && refName.equals(refName1)) { + return conf1; + } + else{ + return null; + } } @Override public Map> getServiceMapping() { - throw new UnsupportedOperationException(); + return null; } @Override public Map lookupServiceReferencesByServiceInterfaceName(String serviceInterfaceQName) { - throw new UnsupportedOperationException(); + + if(serviceInterfaceQName.equals(serviceQName1)){ + map.put("conf1", conf1); + } + else if(serviceInterfaceQName.equals(serviceQName2)){ + map.put("conf2", conf2); + } + else{ + map.put("conf3", conf3); + } + return map; } @Override public Set lookupServiceInterfaceNames(ObjectName objectName) throws InstanceNotFoundException { - throw new UnsupportedOperationException(); + return Sets. newHashSet(serviceQName1, serviceQName2); } @Override public String getServiceInterfaceName(String namespace, String localName) { - throw new UnsupportedOperationException(); + return null; } @Override public Set getAvailableModuleFactoryQNames() { - throw new UnsupportedOperationException(); + return Sets. newHashSet(moduleName1, moduleName2); } @Override public ObjectName getServiceReference(String serviceInterfaceQName, String refName) throws InstanceNotFoundException { - throw new UnsupportedOperationException(); + return conf1; } @Override diff --git a/opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/TestingConfigTransactionController.java b/opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/TestingConfigTransactionController.java index 4d16f51ae5..ee1e61967d 100644 --- a/opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/TestingConfigTransactionController.java +++ b/opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/TestingConfigTransactionController.java @@ -7,6 +7,7 @@ */ package org.opendaylight.controller.config.util; +import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -24,6 +25,10 @@ public class TestingConfigTransactionController implements ConfigTransactionControllerMXBean { public final ObjectName conf1, conf2, conf3; + public ObjectName conf4; + public String check; + Map mapSub; + Map> map; public static final String moduleName1 = "moduleA"; public static final String moduleName2 = "moduleB"; @@ -42,17 +47,29 @@ public class TestingConfigTransactionController implements + ":type=Module," + ObjectNameUtil.MODULE_FACTORY_NAME_KEY + "=" + moduleName2 + "," + ObjectNameUtil.INSTANCE_NAME_KEY + "=" + instName2); + conf4 = ObjectNameUtil.createON(ObjectNameUtil.ON_DOMAIN + + ":type=Module," + ObjectNameUtil.MODULE_FACTORY_NAME_KEY + + "=" + moduleName2 + "," + ObjectNameUtil.INSTANCE_NAME_KEY + + "=" + instName2); + mapSub = new HashMap(); + map = new HashMap>(); } @Override public ObjectName createModule(String moduleName, String instanceName) throws InstanceAlreadyExistsException { - return null; + //return null; + return ObjectNameUtil.createON(ObjectNameUtil.ON_DOMAIN + + ":type=Module," + ObjectNameUtil.MODULE_FACTORY_NAME_KEY + + "=" + moduleName); } @Override public void destroyModule(ObjectName objectName) throws InstanceNotFoundException { + if(objectName != null){ + conf4 = null; + } } @Override @@ -65,7 +82,8 @@ public class TestingConfigTransactionController implements @Override public String getTransactionName() { - return null; + //return null; + return "transactionName"; } @Override @@ -113,66 +131,69 @@ public class TestingConfigTransactionController implements @Override public void checkConfigBeanExists(ObjectName objectName) throws InstanceNotFoundException { - throw new UnsupportedOperationException(); + check = "configBeanExists"; } @Override public ObjectName saveServiceReference(String serviceInterfaceName, String refName, ObjectName moduleON) throws InstanceNotFoundException { - throw new UnsupportedOperationException(); + return moduleON; } @Override public void removeServiceReference(String serviceInterfaceName, String refName) { - throw new UnsupportedOperationException(); + check = refName; } @Override public void removeAllServiceReferences() { - throw new UnsupportedOperationException(); + check = null; } @Override public ObjectName lookupConfigBeanByServiceInterfaceName(String serviceInterfaceQName, String refName) { - throw new UnsupportedOperationException(); + return conf3; } @Override public Map> getServiceMapping() { - throw new UnsupportedOperationException(); + mapSub.put("A",conf2); + map.put("AA", mapSub); + return map; } @Override public Map lookupServiceReferencesByServiceInterfaceName(String serviceInterfaceQName) { - throw new UnsupportedOperationException(); + mapSub.put("A",conf2); + return mapSub; } @Override public Set lookupServiceInterfaceNames(ObjectName objectName) throws InstanceNotFoundException { - throw new UnsupportedOperationException(); + return Sets.newHashSet("setA"); } @Override public String getServiceInterfaceName(String namespace, String localName) { - throw new UnsupportedOperationException(); + return check=namespace+localName; } @Override public boolean removeServiceReferences(ObjectName objectName) throws InstanceNotFoundException { - throw new UnsupportedOperationException(); + return true; } @Override public Set getAvailableModuleFactoryQNames() { - throw new UnsupportedOperationException(); + return Sets.newHashSet("availableModuleFactoryQNames"); } @Override public ObjectName getServiceReference(String serviceInterfaceQName, String refName) throws InstanceNotFoundException { - throw new UnsupportedOperationException(); + return conf3; } @Override public void checkServiceReferenceExists(ObjectName objectName) throws InstanceNotFoundException { - throw new UnsupportedOperationException(); + check = "referenceExist"; } }