From 53c8c9b758936d393940684afe854673e95833cd Mon Sep 17 00:00:00 2001 From: Michael Vorburger Date: Wed, 5 Oct 2016 18:22:25 +0200 Subject: [PATCH] AbstractDataBrokerTestTest which actually does something 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 Signed-off-by: Robert Varga (cherry picked from commit 4a461d624f03984047b593c823112feac729aceb) --- .../tests/AbstractDataBrokerTestTest.java | 52 ++++++++++++++++++- .../testutils/DataBrokerTestModuleTest.java | 5 ++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/test/tests/AbstractDataBrokerTestTest.java b/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/test/tests/AbstractDataBrokerTestTest.java index e777bd3d5f..6181c4ce43 100644 --- a/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/test/tests/AbstractDataBrokerTestTest.java +++ b/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/test/tests/AbstractDataBrokerTestTest.java @@ -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_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(); + } + } } diff --git a/binding/mdsal-binding-test-utils/src/test/java/org/opendaylight/mdsal/binding/testutils/DataBrokerTestModuleTest.java b/binding/mdsal-binding-test-utils/src/test/java/org/opendaylight/mdsal/binding/testutils/DataBrokerTestModuleTest.java index 44c5dc9c0d..bf191be37e 100644 --- a/binding/mdsal-binding-test-utils/src/test/java/org/opendaylight/mdsal/binding/testutils/DataBrokerTestModuleTest.java +++ b/binding/mdsal-binding-test-utils/src/test/java/org/opendaylight/mdsal/binding/testutils/DataBrokerTestModuleTest.java @@ -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 -- 2.36.6