AbstractDataBrokerTestTest which actually does something 80/90080/1
authorMichael Vorburger <vorburger@redhat.com>
Wed, 5 Oct 2016 16:22:25 +0000 (18:22 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 29 May 2020 11:59:00 +0000 (13:59 +0200)
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.

JIRA: MDSAL-556
Change-Id: I295ebde45a0c030ab74852788b45203cdf6639e0
Signed-off-by: Michael Vorburger <vorburger@redhat.com>
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 4a461d624f03984047b593c823112feac729aceb)

binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/test/tests/AbstractDataBrokerTestTest.java
binding/mdsal-binding-test-utils/src/test/java/org/opendaylight/mdsal/binding/testutils/DataBrokerTestModuleTest.java

index e777bd3d5fbe902544ffe65705ff8073ff030f33..6181c4ce43be630b8314c880d351917fdf14419e 100644 (file)
@@ -7,16 +7,66 @@
  */
 package org.opendaylight.mdsal.binding.dom.adapter.test.tests;
 
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.opendaylight.mdsal.binding.test.model.util.ListsBindingUtils.TOP_FOO_KEY;
+import static org.opendaylight.mdsal.binding.test.model.util.ListsBindingUtils.path;
+import static org.opendaylight.mdsal.binding.test.model.util.ListsBindingUtils.topLevelList;
 
+import java.util.concurrent.ExecutionException;
+import org.junit.FixMethodOrder;
 import org.junit.Test;
+import org.junit.runners.MethodSorters;
+import org.opendaylight.mdsal.binding.api.ReadTransaction;
+import org.opendaylight.mdsal.binding.api.WriteTransaction;
 import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractDataBrokerTest;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.TreeComplexUsesAugment;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.TreeComplexUsesAugmentBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.complex.from.grouping.ContainerWithUsesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.Top;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.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 {
+    private static final InstanceIdentifier<Top> TOP_PATH = InstanceIdentifier.create(Top.class);
 
     @Test
-    public void ensureDataBrokerTestModuleWorksWithoutException() {
+    public void aEnsureDataBrokerIsNotNull() {
         assertNotNull(getDataBroker());
     }
 
+    @Test
+    public void bPutSomethingIntoDataStore() throws Exception {
+        writeInitialState();
+        assertTrue(isTopInDataStore());
+    }
+
+    @Test
+    public void cEnsureDataStoreIsEmptyAgainInNewTest() throws Exception {
+        assertFalse(isTopInDataStore());
+    }
+
+    // copy/pasted from Bug1125RegressionTest.writeInitialState()
+    private void writeInitialState() throws InterruptedException, ExecutionException {
+        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.commit().get();
+    }
+
+    private boolean isTopInDataStore() throws InterruptedException, ExecutionException {
+        try (ReadTransaction readTx = getDataBroker().newReadOnlyTransaction()) {
+            return readTx.exists(LogicalDatastoreType.OPERATIONAL, TOP_PATH).get();
+        }
+    }
 }
index 44c5dc9c0df6cb3cb90d5b99464ae5bb76e1f033..bf191be37eda1351672e912a6e89457ebfbe9b96 100644 (file)
@@ -11,6 +11,11 @@ import static com.google.common.truth.Truth.assertThat;
 
 import org.junit.Test;
 
+/**
+ * Integration tests the DataBrokerTestModule.
+ *
+ * @author Michael Vorburger
+ */
 public class DataBrokerTestModuleTest {
 
     @Test