AbstractDataBrokerTestTest which actually does something 64/46564/4
authorMichael Vorburger <vorburger@redhat.com>
Wed, 5 Oct 2016 16:22:25 +0000 (18:22 +0200)
committerTom Pantelis <tpanteli@brocade.com>
Tue, 11 Oct 2016 12:31:17 +0000 (12:31 +0000)
Incl. verification that each @Test cleans up after itself.  We had a
suspicion that this didn't work; it turns out that it actually does and
we had another problem somewhere else.  Contributing this test still
seems useful for future non-regression.

Change-Id: I295ebde45a0c030ab74852788b45203cdf6639e0
Signed-off-by: Michael Vorburger <vorburger@redhat.com>
opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/test/tests/AbstractDataBrokerTestTest.java
opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/test/tests/DataBrokerTestModuleTest.java

index e46d442..5383a3e 100644 (file)
@@ -8,15 +8,69 @@
 package org.opendaylight.controller.md.sal.binding.test.tests;
 
 import static com.google.common.truth.Truth.assertThat;
 package org.opendaylight.controller.md.sal.binding.test.tests;
 
 import static com.google.common.truth.Truth.assertThat;
+import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.TOP_FOO_KEY;
+import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.path;
+import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.topLevelList;
 
 
+import org.junit.FixMethodOrder;
 import org.junit.Test;
 import org.junit.Test;
+import org.junit.runners.MethodSorters;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
 import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugment;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugmentBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.complex.from.grouping.ContainerWithUsesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.TopBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
 
+/**
+ * Integration tests the AbstractDataBrokerTest.
+ *
+ * @author Michael Vorburger
+ */
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
 public class AbstractDataBrokerTestTest extends AbstractDataBrokerTest {
 
 public class AbstractDataBrokerTestTest extends AbstractDataBrokerTest {
 
+    private static final InstanceIdentifier<Top> TOP_PATH = InstanceIdentifier.create(Top.class);
+
     @Test
     @Test
-    public void ensureDataBrokerTestModuleWorksWithoutException() {
+    public void aEnsureDataBrokerIsNotNull() {
         assertThat(getDataBroker()).isNotNull();
     }
 
         assertThat(getDataBroker()).isNotNull();
     }
 
+    @Test
+    public void bPutSomethingIntoDataStore() throws Exception {
+        writeInitialState();
+        assertThat(isTopInDataStore()).isTrue();
+    }
+
+    @Test
+    public void cEnsureDataStoreIsEmptyAgainInNewTest() throws ReadFailedException {
+        assertThat(isTopInDataStore()).isFalse();
+    }
+
+    // copy/pasted from Bug1125RegressionTest.writeInitialState()
+    private void writeInitialState() throws TransactionCommitFailedException {
+        WriteTransaction initialTx = getDataBroker().newWriteOnlyTransaction();
+        initialTx.put(LogicalDatastoreType.OPERATIONAL, TOP_PATH, new TopBuilder().build());
+        TreeComplexUsesAugment fooAugment = new TreeComplexUsesAugmentBuilder()
+                .setContainerWithUses(new ContainerWithUsesBuilder().setLeafFromGrouping("foo").build()).build();
+        initialTx.put(LogicalDatastoreType.OPERATIONAL, path(TOP_FOO_KEY), topLevelList(TOP_FOO_KEY, fooAugment));
+        initialTx.submit().checkedGet();
+    }
+
+    private boolean isTopInDataStore() throws ReadFailedException {
+        ReadOnlyTransaction readTx = getDataBroker().newReadOnlyTransaction();
+        try {
+            return readTx.read(LogicalDatastoreType.OPERATIONAL, TOP_PATH).checkedGet().isPresent();
+        } finally {
+            readTx.close();
+        }
+    }
+
 }
 }
index 2016013..30ea7f8 100644 (file)
@@ -12,6 +12,11 @@ import static com.google.common.truth.Truth.assertThat;
 import org.junit.Test;
 import org.opendaylight.controller.md.sal.binding.test.DataBrokerTestModule;
 
 import org.junit.Test;
 import org.opendaylight.controller.md.sal.binding.test.DataBrokerTestModule;
 
+/**
+ * Integration tests the DataBrokerTestModule.
+ *
+ * @author Michael Vorburger
+ */
 public class DataBrokerTestModuleTest {
 
     @Test
 public class DataBrokerTestModuleTest {
 
     @Test

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.