X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fclustered-data-store%2Fintegrationtest%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fdatastore%2FClusteredDataStoreIT.java;h=a1fa9e31b8b2ad3b6c3c4fc9f712ef8227e4bec9;hb=8baeda4ab8d240f847cd530ef6af7c7c1c2d4d13;hp=e5861ab3c0af825806bd8951684dcf4f1a7a0250;hpb=a6c01f7c1524818828a334813f80186119e9b7ea;p=controller.git diff --git a/opendaylight/md-sal/clustered-data-store/integrationtest/src/test/java/org/opendaylight/controller/datastore/ClusteredDataStoreIT.java b/opendaylight/md-sal/clustered-data-store/integrationtest/src/test/java/org/opendaylight/controller/datastore/ClusteredDataStoreIT.java index e5861ab3c0..a1fa9e31b8 100644 --- a/opendaylight/md-sal/clustered-data-store/integrationtest/src/test/java/org/opendaylight/controller/datastore/ClusteredDataStoreIT.java +++ b/opendaylight/md-sal/clustered-data-store/integrationtest/src/test/java/org/opendaylight/controller/datastore/ClusteredDataStoreIT.java @@ -8,16 +8,34 @@ package org.opendaylight.controller.datastore; +import static junit.framework.Assert.assertNotNull; +import static junit.framework.Assert.assertNull; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +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 java.util.ArrayList; import java.util.HashMap; import java.util.List; -import org.junit.Before; +import javax.inject.Inject; + +import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; +import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler.DataCommitTransaction; +import org.opendaylight.controller.md.sal.common.api.data.DataModification; +import org.opendaylight.controller.test.sal.binding.it.TestHelper; +import org.opendaylight.yangtools.yang.data.api.CompositeNode; +import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; import org.ops4j.pax.exam.Configuration; import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.junit.PaxExam; +import org.ops4j.pax.exam.util.Filter; import org.ops4j.pax.exam.util.PathUtils; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; @@ -25,40 +43,24 @@ import org.osgi.framework.ServiceReference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.inject.Inject; - -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) +//@ExamReactorStrategy(PerClass.class) public class ClusteredDataStoreIT { - private Logger log = LoggerFactory - .getLogger(ClusteredDataStoreIT.class); + private Logger log = LoggerFactory.getLogger(ClusteredDataStoreIT.class); // get the OSGI bundle context @Inject private BundleContext bc; @Inject + @Filter(timeout=60*1000) private ClusteredDataStore clusteredDS; + // Configure the OSGi container @Configuration public Option[] config() { return options( // systemProperty("logback.configurationFile").value( - "file:" + PathUtils.getBaseDir() - + "/src/test/resources/logback.xml"), + "file:" + PathUtils.getBaseDir() + "/src/test/resources/logback.xml"), // To start OSGi console for inspection remotely systemProperty("osgi.console").value("2401"), // Set the systemPackages (used by clustering) @@ -74,66 +76,36 @@ public class ClusteredDataStoreIT { mavenBundle("equinoxSDK381", "org.apache.felix.gogo.shell").versionAsInProject(), // List logger bundles mavenBundle("org.slf4j", "slf4j-api").versionAsInProject(), - mavenBundle("org.slf4j", "log4j-over-slf4j") - .versionAsInProject(), - mavenBundle("ch.qos.logback", "logback-core") - .versionAsInProject(), - mavenBundle("ch.qos.logback", "logback-classic") - .versionAsInProject(), + mavenBundle("org.slf4j", "log4j-over-slf4j").versionAsInProject(), + mavenBundle("ch.qos.logback", "logback-core").versionAsInProject(), + mavenBundle("ch.qos.logback", "logback-classic").versionAsInProject(), // needed by statisticsmanager - mavenBundle("org.opendaylight.controller", "containermanager") - .versionAsInProject(), - mavenBundle("org.opendaylight.controller", "containermanager.it.implementation") - .versionAsInProject(), - mavenBundle("org.opendaylight.controller", "clustering.services") - .versionAsInProject(), - mavenBundle("org.opendaylight.controller", "clustering.stub") - .versionAsInProject(), + mavenBundle("org.opendaylight.controller", "containermanager").versionAsInProject(), + mavenBundle("org.opendaylight.controller", "containermanager.it.implementation").versionAsInProject(), + mavenBundle("org.opendaylight.controller", "clustering.services").versionAsInProject(), + mavenBundle("org.opendaylight.controller", "clustering.stub").versionAsInProject(), // List all the bundles on which the test case depends - mavenBundle("org.opendaylight.controller", "sal") - .versionAsInProject(), - mavenBundle("org.opendaylight.controller", "sal.implementation") - .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(), + mavenBundle("org.opendaylight.controller", "sal").versionAsInProject(), + TestHelper.baseModelBundles(), + TestHelper.configMinumumBundles(), + TestHelper.bindingIndependentSalBundles(), + TestHelper.bindingAwareSalBundles(), + TestHelper.mdSalCoreBundles(), + mavenBundle("org.opendaylight.controller", "config-api").versionAsInProject(), + mavenBundle("org.opendaylight.controller", "sal.implementation").versionAsInProject(), + mavenBundle("org.opendaylight.controller", "protocol_plugins.stub").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(), - mavenBundle("org.jboss.spec.javax.transaction", - "jboss-transaction-api_1.1_spec").versionAsInProject(), - mavenBundle("org.apache.commons", "commons-lang3") - .versionAsInProject(), - mavenBundle("org.apache.felix", - "org.apache.felix.dependencymanager") - .versionAsInProject(), junitBundles()); + mavenBundle("org.opendaylight.controller", "clustered-datastore-implementation").versionAsInProject(), + mavenBundle("org.jboss.spec.javax.transaction", "jboss-transaction-api_1.1_spec").versionAsInProject(), + mavenBundle("org.apache.commons", "commons-lang3").versionAsInProject(), + mavenBundle("org.apache.felix", "org.apache.felix.dependencymanager").versionAsInProject(), + junitBundles()); } private String stateToString(int state) { @@ -151,137 +123,119 @@ 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{ + 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(){ + public void testInjected_ClusteredDS_NotNull() { assertNotNull(clusteredDS); } @Test - public void requestCommit_readConfigurationData_ShouldVerifyDataAndNoException(){ + 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"); + InstanceIdentifier key = new InstanceIdentifier(list); + map.put(key, mock(CompositeNode.class)); when(dataModification.getUpdatedConfigurationData()).thenReturn(map); DataCommitTransaction dataCommitTrans = clusteredDS.requestCommit(dataModification); dataCommitTrans.finish(); - String value = (String)clusteredDS.readConfigurationData(key); - assertEquals("value",value); + Object value = clusteredDS.readConfigurationData(key); + Assert.assertNotNull(value); } @Test(expected = NullPointerException.class) - public void requestCommit_ShouldThrowException(){ + public void requestCommit_ShouldThrowException() { DataModification dataModification = null; DataCommitTransaction dataCommitTrans = clusteredDS.requestCommit(dataModification); dataCommitTrans.finish(); } @Test - public void requestCommit_readOperationalData_ShouldVerifyDataAndNoException(){ + 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"); + InstanceIdentifier key = new InstanceIdentifier(list); + map.put(key, mock(CompositeNode.class)); when(dataModification.getUpdatedOperationalData()).thenReturn(map); DataCommitTransaction dataCommitTrans = clusteredDS.requestCommit(dataModification); dataCommitTrans.finish(); - String value = (String)clusteredDS.readOperationalData(key); - assertEquals("value",value); + Object value = clusteredDS.readOperationalData(key); + Assert.assertNotNull(value); } @Test - public void requestCommit_readConfigurationData_NonExistingKey_ShouldVerifyNoMappedValueAndNoException(){ + 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); + InstanceIdentifier key = new InstanceIdentifier(list); 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); + InstanceIdentifier key1 = new InstanceIdentifier(list); - String value = (String)clusteredDS.readConfigurationData(key1); + Object value = clusteredDS.readConfigurationData(key1); assertNull(value); } @Test - public void requestCommit_readOperationalData_NonExistingKey_ShouldVerifyNoMappedValueAndNoException(){ + 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"); + InstanceIdentifier key = new InstanceIdentifier(list); + map.put(key, mock(CompositeNode.class)); 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); + InstanceIdentifier key1 = new InstanceIdentifier(list); - String value = (String)clusteredDS.readOperationalData(key1); + Object value = clusteredDS.readOperationalData(key1); assertNull(value); } @Test(expected = NullPointerException.class) - public void requestCommit_readConfigurationData_WithNullPathShouldThrowException(){ + 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); + InstanceIdentifier key = new InstanceIdentifier(list); map.put(key, "value"); when(dataModification.getUpdatedConfigurationData()).thenReturn(map); DataCommitTransaction dataCommitTrans = clusteredDS.requestCommit(dataModification); dataCommitTrans.finish(); - String value = (String)clusteredDS.readConfigurationData(null); + Object value = clusteredDS.readConfigurationData(null); } @Test(expected = NullPointerException.class) - public void requestCommit_readOperationalData_WithNullPathShouldThrowException(){ + 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); + InstanceIdentifier key = new InstanceIdentifier(list); map.put(key, "value"); when(dataModification.getOriginalOperationalData()).thenReturn(map); DataCommitTransaction dataCommitTrans = clusteredDS.requestCommit(dataModification); dataCommitTrans.finish(); - String value = (String)clusteredDS.readOperationalData(null); + Object value = clusteredDS.readOperationalData(null); } + }