Merge "BUG 1712 - Distributed DataStore does not work properly with Transaction...
authorTom Pantelis <tpanteli@brocade.com>
Wed, 10 Sep 2014 16:50:57 +0000 (16:50 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Wed, 10 Sep 2014 16:50:57 +0000 (16:50 +0000)
opendaylight/config/config-util/pom.xml
opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/AttributeEntryTest.java [new file with mode: 0644]
opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/ConfigRegistryClientsTest.java
opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/ConfigTransactionClientsTest.java
opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/TestingConfigRegistry.java
opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/TestingConfigTransactionController.java

index fd9c1b9..29a5526 100644 (file)
       <artifactId>guava</artifactId>
       <scope>test</scope>
     </dependency>
+  <dependency>
+    <groupId>org.opendaylight.yangtools</groupId>
+    <artifactId>mockito-configuration</artifactId>
+  </dependency>
   </dependencies>
 
   <build>
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 (file)
index 0000000..b2afd35
--- /dev/null
@@ -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());
+    }
+}
index 1304345..0524f00 100644 (file)
@@ -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<String, ObjectName> 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<ObjectName> son = jmxRegistryClient.lookupConfigBeans();
+        assertEquals(3, son.size());
+    }
+
+    @Test
+    public void testLookupConfigBeans2() throws Exception{
+        Set<ObjectName> son = jmxRegistryClient.lookupConfigBeans(TestingConfigRegistry.moduleName1);
+        assertEquals(2, son.size());
+    }
+
+    @Test
+    public void testLookupConfigBeans() throws Exception{
+        Set<ObjectName> son = jmxRegistryClient.lookupConfigBeans(TestingConfigRegistry.moduleName1, TestingConfigRegistry.instName1);
+        Set<ObjectName> 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<ObjectName> 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<String> 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);
+    }
 }
index 5ce6d46..2f50513 100644 (file)
@@ -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<ObjectName> jmxLookup = testClientLookupConfigBeans(jmxTransactionClient);
         assertEquals(Sets.newHashSet(transactionController.conf1,
-                transactionController.conf2, transactionController.conf3), jmxLookup);
+                transactionController.conf2, transactionController.conf3),
+                jmxLookup);
     }
 
     private Set<ObjectName> 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<String> jmxMN = testClientGetAvailableModuleNames(jmxTransactionClient);
+        assertNull(jmxMN);
+    }
+
+    private Set<String> 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<ObjectName> jmxLookup = testClientLookupConfigBeans2(
+                jmxTransactionClient, "moduleB");
+        assertEquals(Sets.newHashSet(transactionController.conf3), jmxLookup);
+    }
+
+    private Set<ObjectName> testClientLookupConfigBeans2(
+            ConfigTransactionClient client, String moduleName) {
+        Set<ObjectName> beans = client.lookupConfigBeans(moduleName);
+        assertEquals(1, beans.size());
+        return beans;
+    }
+
+    @Test
+    public void testLookupConfigBean() throws Exception {
+        Set<ObjectName> jmxLookup = testClientLookupConfigBean(
+                jmxTransactionClient, "moduleB", "instB");
+        assertEquals(Sets.newHashSet(transactionController.conf3), jmxLookup);
+    }
+
+    private Set<ObjectName> testClientLookupConfigBean(
+            ConfigTransactionClient client, String moduleName,
+            String instanceName) {
+        Set<ObjectName> beans = client.lookupConfigBeans(moduleName,
+                instanceName);
+        assertEquals(1, beans.size());
+        return beans;
+    }
+
+    @Test
+    public void testLookupConfigBeans3() throws Exception {
+        Set<ObjectName> jmxLookup = testClientLookupConfigBeans3(
+                jmxTransactionClient, "moduleB", "instB");
+        assertEquals(Sets.newHashSet(transactionController.conf3), jmxLookup);
+    }
+
+    private Set<ObjectName> testClientLookupConfigBeans3(
+            ConfigTransactionClient client, String moduleName,
+            String instanceName) {
+        Set<ObjectName> 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.<String, Map<String, ExceptionMessageWithStackTrace>>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());
+    }
 }
index e0d4c85..ab6cda9 100644 (file)
@@ -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<String, ObjectName> 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<ObjectName> configBeans = Sets.<ObjectName> 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<String, Map<String, ObjectName>> getServiceMapping() {
-        throw new UnsupportedOperationException();
+        return null;
     }
 
     @Override
     public Map<String, ObjectName> 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<String> lookupServiceInterfaceNames(ObjectName objectName) throws InstanceNotFoundException {
-        throw new UnsupportedOperationException();
+        return Sets.<String> newHashSet(serviceQName1, serviceQName2);
     }
 
     @Override
     public String getServiceInterfaceName(String namespace, String localName) {
-        throw new UnsupportedOperationException();
+        return null;
     }
 
     @Override
     public Set<String> getAvailableModuleFactoryQNames() {
-        throw new UnsupportedOperationException();
+        return Sets.<String> newHashSet(moduleName1, moduleName2);
     }
 
     @Override
     public ObjectName getServiceReference(String serviceInterfaceQName, String refName) throws InstanceNotFoundException {
-        throw new UnsupportedOperationException();
+        return conf1;
     }
 
     @Override
index 4d16f51..ee1e619 100644 (file)
@@ -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<String, ObjectName> mapSub;
+    Map<String, Map<String, ObjectName>> 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<String, ObjectName>();
+        map = new HashMap<String, Map<String,ObjectName>>();
     }
 
     @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<String, Map<String, ObjectName>> getServiceMapping() {
-        throw new UnsupportedOperationException();
+        mapSub.put("A",conf2);
+        map.put("AA", mapSub);
+        return map;
     }
 
     @Override
     public Map<String, ObjectName> lookupServiceReferencesByServiceInterfaceName(String serviceInterfaceQName) {
-        throw new UnsupportedOperationException();
+        mapSub.put("A",conf2);
+        return mapSub;
     }
 
     @Override
     public Set<String> 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<String> 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";
     }
 }