ClusteredDataStore integration testing 27/2627/2
authorLakshman Mukkamalla <lmukkama@cisco.com>
Mon, 11 Nov 2013 19:48:11 +0000 (11:48 -0800)
committerLakshman Mukkamalla <lmukkama@cisco.com>
Mon, 11 Nov 2013 22:22:03 +0000 (14:22 -0800)
Change-Id: I9803592c84011aef924c55fe681b415889d73427
Signed-off-by: Lakshman Mukkamalla <lmukkama@cisco.com>
opendaylight/md-sal/clustered-data-store/implementation/pom.xml
opendaylight/md-sal/clustered-data-store/implementation/src/test/java/org/opendaylight/controller/datastore/internal/ClusteredDataStoreManagerTest.java
opendaylight/md-sal/clustered-data-store/integrationtest/pom.xml
opendaylight/md-sal/clustered-data-store/integrationtest/src/test/java/org/opendaylight/controller/datastore/ClusteredDataStoreIT.java

index bb43809a5c63c4bdb08d8bc6cf2e2ca2a3a492f3..a3d11d0374cade2eec78f10440700d3b262754dd 100644 (file)
@@ -29,6 +29,7 @@
         <configuration>
           <instructions>
             <Export-Package>
+              org.opendaylight.controller.datastore
             </Export-Package>
             <Import-Package>
               javax.xml.bind.annotation,
@@ -38,6 +39,7 @@
               org.opendaylight.controller.sal.topology,
               org.opendaylight.controller.clustering.services,
               org.opendaylight.controller.md.sal.common.api.data,
+              org.opendaylight.controller.sal.common.util,
               org.opendaylight.yangtools.yang.binding,
               org.osgi.service.component,
               org.slf4j,
@@ -45,7 +47,8 @@
               org.apache.commons.lang3.builder,
               org.apache.commons.lang3.tuple,
               org.eclipse.osgi.framework.console,
-              org.osgi.framework
+              org.osgi.framework,
+              com.google.common.base
             </Import-Package>
             <Bundle-Activator>
               org.opendaylight.controller.datastore.internal.Activator
index 84b07e7cd4dfd971d3e53ee938333e33e7913004..5609134a1a672c4c7eda1e3e3928ab1ca4af75da 100644 (file)
@@ -1,3 +1,12 @@
+
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
 package org.opendaylight.controller.datastore.internal;
 
 import org.apache.felix.dm.Component;
index 407b46bed1641d5b6b59f2675620d49a79bee5a9..9615decbe9fed710acc0c6674ec0eff3d020ee9d 100644 (file)
   <artifactId>clustered-datastore.integrationtest</artifactId>
   <version>0.4.0-SNAPSHOT</version>
   <dependencies>
+
+      <dependency>
+        <groupId>com.google.guava</groupId>
+        <artifactId>guava</artifactId>
+      </dependency>
+      <dependency>
+          <groupId>org.opendaylight.controller</groupId>
+          <artifactId>sal-common-api</artifactId>
+          <version>1.0-SNAPSHOT</version>
+      </dependency>
+      <dependency>
+        <groupId>org.opendaylight.controller</groupId>
+        <artifactId>sal-common-util</artifactId>
+        <version>1.0-SNAPSHOT</version>
+      </dependency>
+      <dependency>
+        <groupId>org.opendaylight.controller</groupId>
+        <artifactId>sal-common-impl</artifactId>
+        <version>1.0-SNAPSHOT</version>
+      </dependency>
+      <dependency>
+        <groupId>org.opendaylight.controller</groupId>
+        <artifactId>sal-binding-broker-impl</artifactId>
+        <version>1.0-SNAPSHOT</version>
+      </dependency>
+      <dependency>
+        <groupId>org.opendaylight.controller</groupId>
+        <artifactId>sal</artifactId>
+        <version>0.5.1-SNAPSHOT</version>
+      </dependency>
+      <dependency>
+        <groupId>org.opendaylight.controller</groupId>
+        <artifactId>clustering.services</artifactId>
+        <version>0.4.1-SNAPSHOT</version>
+      </dependency>
+      <dependency>
+        <groupId>org.opendaylight.yangtools</groupId>
+        <artifactId>yang-binding</artifactId>
+      </dependency>
+
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>protocol_plugins.stub</artifactId>
       <version>0.4.1-SNAPSHOT</version>
-    </dependency>
-    <dependency>
-      <groupId>org.opendaylight.controller</groupId>
-      <artifactId>sal</artifactId>
-      <version>0.5.0-SNAPSHOT</version>
     </dependency>
      <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>containermanager.it.implementation</artifactId>
       <version>0.5.0-SNAPSHOT</version>
     </dependency>
-    <dependency>
-      <groupId>org.opendaylight.controller</groupId>
-      <artifactId>clustering.services</artifactId>
-      <version>0.4.0-SNAPSHOT</version>
-    </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>clustering.stub</artifactId>
       <version>0.4.1-SNAPSHOT</version>
     </dependency>
 
-  </dependencies>
+      <dependency>
+          <groupId>org.opendaylight.controller</groupId>
+          <artifactId>sal-common</artifactId>
+          <version>1.0-SNAPSHOT</version>
+      </dependency>
+      <dependency>
+          <groupId>org.opendaylight.yangtools</groupId>
+          <artifactId>yang-common</artifactId>
+      </dependency>
+      <dependency>
+          <groupId>org.opendaylight.yangtools</groupId>
+          <artifactId>concepts</artifactId>
+          <version>0.1.1-SNAPSHOT</version>
+      </dependency>
+      <dependency>
+       <groupId>org.mockito</groupId>
+       <artifactId>mockito-all</artifactId>
+       <version>1.9.5</version>
+       <scope>test</scope>
+      </dependency>
+      <dependency>
+          <groupId>org.osgi</groupId>
+          <artifactId>org.osgi.core</artifactId>
+          <version>5.0.0</version>
+      </dependency>
+
+</dependencies>
   <properties>
     <!-- Sonar jacoco plugin to get integration test coverage info -->
     <sonar.jacoco.reportPath>../implementation/target/jacoco.exec</sonar.jacoco.reportPath>
index ddf275ec14897d9059cd2fc61236418fa06b694d..e5861ab3c0af825806bd8951684dcf4f1a7a0250 100644 (file)
@@ -8,6 +8,11 @@
 
 package org.opendaylight.controller.datastore;
 
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.Configuration;
@@ -16,18 +21,26 @@ import org.ops4j.pax.exam.junit.PaxExam;
 import org.ops4j.pax.exam.util.PathUtils;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import javax.inject.Inject;
 
-import static junit.framework.Assert.assertTrue;
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertNull;
 import static org.ops4j.pax.exam.CoreOptions.junitBundles;
 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
 import static org.ops4j.pax.exam.CoreOptions.options;
 import static org.ops4j.pax.exam.CoreOptions.systemPackages;
 import static org.ops4j.pax.exam.CoreOptions.systemProperty;
 
+import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler.DataCommitTransaction;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.controller.md.sal.common.api.data.DataModification;
+import static org.mockito.Mockito.mock;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.when;
 
 @RunWith(PaxExam.class)
 public class ClusteredDataStoreIT {
@@ -36,7 +49,8 @@ public class ClusteredDataStoreIT {
     // get the OSGI bundle context
     @Inject
     private BundleContext bc;
-
+    @Inject
+    private ClusteredDataStore clusteredDS;
     // Configure the OSGi container
     @Configuration
     public Option[] config() {
@@ -49,6 +63,7 @@ public class ClusteredDataStoreIT {
                 systemProperty("osgi.console").value("2401"),
                 // Set the systemPackages (used by clustering)
                 systemPackages("sun.reflect", "sun.reflect.misc", "sun.misc"),
+                systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("DEBUG"),
                 // List framework bundles
                 mavenBundle("equinoxSDK381", "org.eclipse.equinox.console").versionAsInProject(),
                 mavenBundle("equinoxSDK381", "org.eclipse.equinox.util").versionAsInProject(),
@@ -83,6 +98,32 @@ public class ClusteredDataStoreIT {
                 mavenBundle("org.opendaylight.controller", "protocol_plugins.stub")
                     .versionAsInProject(),
 
+                //clustered-data-store-implementation dependencies
+                mavenBundle("com.google.guava", "guava")
+                    .versionAsInProject(),
+                mavenBundle("org.opendaylight.controller", "sal-common-api")
+                    .versionAsInProject(),
+                mavenBundle("org.opendaylight.controller", "sal-common-util")
+                    .versionAsInProject(),
+                mavenBundle("org.opendaylight.controller", "sal-common-impl")
+                    .versionAsInProject(),
+                mavenBundle("org.opendaylight.yangtools", "yang-binding")
+                    .versionAsInProject(),
+
+
+                //sal-common-api dependencies
+                mavenBundle("org.opendaylight.controller", "sal-common")
+                    .versionAsInProject(),
+                mavenBundle("org.opendaylight.yangtools", "yang-common")
+                    .versionAsInProject(),
+                mavenBundle("org.opendaylight.yangtools", "concepts")
+                    .versionAsInProject(),
+                mavenBundle("org.osgi", "org.osgi.core")
+                    .versionAsInProject(),
+                //adding new maven bundles
+                mavenBundle("org.mockito", "mockito-all")
+                    .versionAsInProject(),
+
                 // needed by hosttracker
                 mavenBundle("org.opendaylight.controller", "clustered-datastore-implementation")
                         .versionAsInProject(),
@@ -110,9 +151,137 @@ public class ClusteredDataStoreIT {
         }
     }
 
+    @Before
+    public void areWeReady() {
+        assertNotNull(bc);
+        boolean debugit = false;
+        Bundle b[] = bc.getBundles();
+        for (int i = 0; i < b.length; i++) {
+            int state = b[i].getState();
+            if (state != Bundle.ACTIVE && state != Bundle.RESOLVED) {
+                log.debug("Bundle:" + b[i].getSymbolicName() + " state:"
+                          + stateToString(state));
+                debugit = true;
+            }
+        }
+        if (debugit) {
+            log.debug("Do some debugging because some bundle is "
+                      + "unresolved");
+        }
+    }
+
+    @Test
+    public void testBundleContextClusteredDS_NotNull() throws Exception{
+        ServiceReference serviceReference = bc.getServiceReference(ClusteredDataStore.class);
+        ClusteredDataStore store = ClusteredDataStore.class.cast(bc.getService(serviceReference));
+        assertNotNull(store);
+    }
+
+    @Test
+    public void testInjected_ClusteredDS_NotNull(){
+        assertNotNull(clusteredDS);
+    }
+
     @Test
-    public void testDoNothing() throws Exception{
-        assertTrue(true);
+    public void requestCommit_readConfigurationData_ShouldVerifyDataAndNoException(){
+        DataModification dataModification = mock(DataModification.class);
+        HashMap map = new HashMap();
+        List list = new ArrayList();
+        list.add("key");
+        InstanceIdentifier key = new InstanceIdentifier(list,String.class);
+        map.put(key, "value");
+        when(dataModification.getUpdatedConfigurationData()).thenReturn(map);
+        DataCommitTransaction dataCommitTrans = clusteredDS.requestCommit(dataModification);
+        dataCommitTrans.finish();
+        String value = (String)clusteredDS.readConfigurationData(key);
+        assertEquals("value",value);
     }
 
+    @Test(expected = NullPointerException.class)
+    public void requestCommit_ShouldThrowException(){
+        DataModification dataModification = null;
+        DataCommitTransaction dataCommitTrans = clusteredDS.requestCommit(dataModification);
+        dataCommitTrans.finish();
+    }
+
+    @Test
+    public void requestCommit_readOperationalData_ShouldVerifyDataAndNoException(){
+        DataModification dataModification = mock(DataModification.class);
+        HashMap map = new HashMap();
+        List list = new ArrayList();
+        list.add("key");
+        InstanceIdentifier key = new InstanceIdentifier(list,String.class);
+        map.put(key, "value");
+        when(dataModification.getUpdatedOperationalData()).thenReturn(map);
+        DataCommitTransaction dataCommitTrans = clusteredDS.requestCommit(dataModification);
+        dataCommitTrans.finish();
+        String value = (String)clusteredDS.readOperationalData(key);
+        assertEquals("value",value);
+    }
+
+    @Test
+    public void requestCommit_readConfigurationData_NonExistingKey_ShouldVerifyNoMappedValueAndNoException(){
+        DataModification dataModification = mock(DataModification.class);
+        HashMap map = new HashMap();
+        List list = new ArrayList();
+        list.add("key");
+        InstanceIdentifier key = new InstanceIdentifier(list,String.class);
+        map.put(key, "value");
+        when(dataModification.getUpdatedConfigurationData()).thenReturn(map);
+        DataCommitTransaction dataCommitTrans = clusteredDS.requestCommit(dataModification);
+        dataCommitTrans.finish();
+        list = new ArrayList();
+        list.add("key1");
+        InstanceIdentifier key1 = new InstanceIdentifier(list,String.class);
+
+        String value = (String)clusteredDS.readConfigurationData(key1);
+        assertNull(value);
+    }
+
+    @Test
+    public void requestCommit_readOperationalData_NonExistingKey_ShouldVerifyNoMappedValueAndNoException(){
+        DataModification dataModification = mock(DataModification.class);
+        HashMap map = new HashMap();
+        List list = new ArrayList();
+        list.add("key");
+        InstanceIdentifier key = new InstanceIdentifier(list,String.class);
+        map.put(key, "value");
+        when(dataModification.getUpdatedOperationalData()).thenReturn(map);
+        DataCommitTransaction dataCommitTrans = clusteredDS.requestCommit(dataModification);
+        dataCommitTrans.finish();
+        list = new ArrayList();
+        list.add("key1");
+        InstanceIdentifier key1 = new InstanceIdentifier(list,String.class);
+
+        String value = (String)clusteredDS.readOperationalData(key1);
+        assertNull(value);
+    }
+
+    @Test(expected = NullPointerException.class)
+    public void requestCommit_readConfigurationData_WithNullPathShouldThrowException(){
+        DataModification dataModification = mock(DataModification.class);
+        HashMap map = new HashMap();
+        List list = new ArrayList();
+        list.add("key");
+        InstanceIdentifier key = new InstanceIdentifier(list,String.class);
+        map.put(key, "value");
+        when(dataModification.getUpdatedConfigurationData()).thenReturn(map);
+        DataCommitTransaction dataCommitTrans = clusteredDS.requestCommit(dataModification);
+        dataCommitTrans.finish();
+        String value = (String)clusteredDS.readConfigurationData(null);
+    }
+
+    @Test(expected = NullPointerException.class)
+    public void requestCommit_readOperationalData_WithNullPathShouldThrowException(){
+        DataModification dataModification = mock(DataModification.class);
+        HashMap map = new HashMap();
+        List list = new ArrayList();
+        list.add("key");
+        InstanceIdentifier key = new InstanceIdentifier(list,String.class);
+        map.put(key, "value");
+        when(dataModification.getOriginalOperationalData()).thenReturn(map);
+        DataCommitTransaction dataCommitTrans = clusteredDS.requestCommit(dataModification);
+        dataCommitTrans.finish();
+        String value = (String)clusteredDS.readOperationalData(null);
+    }
 }