<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>
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;
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 {
// get the OSGI bundle context
@Inject
private BundleContext bc;
-
+ @Inject
+ private ClusteredDataStore clusteredDS;
// Configure the OSGi container
@Configuration
public Option[] config() {
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(),
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(),
}
}
+ @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);
+ }
}