X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-binding-broker%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fbinding%2Fimpl%2Ftest%2FWriteTransactionTest.java;h=b504837d6780aa344eb706a786733b321a2fa65e;hb=56f33d52dd1de461e54f718960c43d96d37a963a;hp=43e951423c0a2bfdecef87969abd01c51816d28e;hpb=79202e1fd05d2606b35e163f608fad9cce84b5d4;p=controller.git diff --git a/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/impl/test/WriteTransactionTest.java b/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/impl/test/WriteTransactionTest.java index 43e951423c..b504837d67 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/impl/test/WriteTransactionTest.java +++ b/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/impl/test/WriteTransactionTest.java @@ -7,15 +7,16 @@ */ package org.opendaylight.controller.md.sal.binding.impl.test; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.util.concurrent.ExecutionException; import org.junit.Test; +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.common.api.TransactionStatus; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +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.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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList; @@ -23,19 +24,49 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controll import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import com.google.common.base.Optional; + public class WriteTransactionTest extends AbstractDataBrokerTest { private static final InstanceIdentifier TOP_PATH = InstanceIdentifier.create(Top.class); private static final TopLevelListKey TOP_LIST_KEY = new TopLevelListKey("foo"); private static final InstanceIdentifier NODE_PATH = TOP_PATH.child(TopLevelList.class, TOP_LIST_KEY); - + private static final TopLevelList NODE = new TopLevelListBuilder().setKey(TOP_LIST_KEY).build(); @Test public void test() throws InterruptedException, ExecutionException { WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction(); writeTx.put(LogicalDatastoreType.OPERATIONAL, TOP_PATH, new TopBuilder().build()); - writeTx.put(LogicalDatastoreType.OPERATIONAL, NODE_PATH, new TopLevelListBuilder().setKey(TOP_LIST_KEY).build()); - assertEquals(TransactionStatus.COMMITED, writeTx.commit().get().getResult()); + writeTx.put(LogicalDatastoreType.OPERATIONAL, NODE_PATH, NODE); + writeTx.submit().get(); + } + + @Test + public void testPutCreateParentsSuccess() throws TransactionCommitFailedException, InterruptedException, ExecutionException { + + WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction(); + writeTx.put(LogicalDatastoreType.OPERATIONAL, NODE_PATH, NODE,true); + writeTx.submit().checkedGet(); + + ReadOnlyTransaction readTx = getDataBroker().newReadOnlyTransaction(); + Optional topNode = readTx.read(LogicalDatastoreType.OPERATIONAL, TOP_PATH).get(); + assertTrue("Top node must exists after commit",topNode.isPresent()); + Optional listNode = readTx.read(LogicalDatastoreType.OPERATIONAL, NODE_PATH).get(); + assertTrue("List node must exists after commit",listNode.isPresent()); + } + + @Test + public void testMergeCreateParentsSuccess() throws TransactionCommitFailedException, InterruptedException, ExecutionException { + + WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction(); + writeTx.merge(LogicalDatastoreType.OPERATIONAL, NODE_PATH, NODE,true); + writeTx.submit().checkedGet(); + + ReadOnlyTransaction readTx = getDataBroker().newReadOnlyTransaction(); + Optional topNode = readTx.read(LogicalDatastoreType.OPERATIONAL, TOP_PATH).get(); + assertTrue("Top node must exists after commit",topNode.isPresent()); + Optional listNode = readTx.read(LogicalDatastoreType.OPERATIONAL, NODE_PATH).get(); + assertTrue("List node must exists after commit",listNode.isPresent()); } }