Fix logic ensuring parent presence
[mdsal.git] / binding / mdsal-binding-dom-adapter / src / test / java / org / opendaylight / mdsal / binding / dom / adapter / test / WriteTransactionTest.java
index 9c4277390fc1c5bdc20e49e16113772eb726c574..55f26a098e22978b89d928357899758c2d47dd3d 100644 (file)
@@ -9,7 +9,7 @@ package org.opendaylight.mdsal.binding.dom.adapter.test;
 
 import static org.junit.Assert.assertTrue;
 
-import com.google.common.base.Optional;
+import java.util.Optional;
 import java.util.concurrent.ExecutionException;
 import org.junit.Test;
 import org.opendaylight.mdsal.binding.api.ReadTransaction;
@@ -23,11 +23,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.te
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
 public class WriteTransactionTest extends AbstractDataBrokerTest {
-
     private static final InstanceIdentifier<Top> TOP_PATH = InstanceIdentifier.create(Top.class);
     private static final TopLevelListKey TOP_LIST_KEY = new TopLevelListKey("foo");
     private static final InstanceIdentifier<TopLevelList> NODE_PATH = TOP_PATH.child(TopLevelList.class, TOP_LIST_KEY);
-    private static final TopLevelList NODE = new TopLevelListBuilder().setKey(TOP_LIST_KEY).build();
+    private static final TopLevelList NODE = new TopLevelListBuilder().withKey(TOP_LIST_KEY).build();
 
     @Test
     public void test() throws InterruptedException, ExecutionException {
@@ -39,9 +38,8 @@ public class WriteTransactionTest extends AbstractDataBrokerTest {
 
     @Test
     public void testPutCreateParentsSuccess() throws InterruptedException, ExecutionException {
-
         final WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
-        writeTx.put(LogicalDatastoreType.OPERATIONAL, NODE_PATH, NODE,true);
+        writeTx.mergeParentStructurePut(LogicalDatastoreType.OPERATIONAL, NODE_PATH, NODE);
         writeTx.commit().get();
 
         final ReadTransaction readTx = getDataBroker().newReadOnlyTransaction();
@@ -52,10 +50,16 @@ public class WriteTransactionTest extends AbstractDataBrokerTest {
     }
 
     @Test
-    public void testMergeCreateParentsSuccess() throws InterruptedException, ExecutionException {
+    public void testPutCreateParentsSuperfluous() throws InterruptedException, ExecutionException {
+        final WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
+        writeTx.mergeParentStructurePut(LogicalDatastoreType.OPERATIONAL, TOP_PATH, new TopBuilder().build());
+        writeTx.commit().get();
+    }
 
+    @Test
+    public void testMergeCreateParentsSuccess() throws InterruptedException, ExecutionException {
         final WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
-        writeTx.merge(LogicalDatastoreType.OPERATIONAL, NODE_PATH, NODE,true);
+        writeTx.mergeParentStructureMerge(LogicalDatastoreType.OPERATIONAL, NODE_PATH, NODE);
         writeTx.commit().get();
 
         final ReadTransaction readTx = getDataBroker().newReadOnlyTransaction();
@@ -65,4 +69,10 @@ public class WriteTransactionTest extends AbstractDataBrokerTest {
         assertTrue("List node must exists after commit",listNode.isPresent());
     }
 
+    @Test
+    public void testMergeCreateParentsSuperfluous() throws InterruptedException, ExecutionException {
+        final WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
+        writeTx.mergeParentStructurePut(LogicalDatastoreType.OPERATIONAL, TOP_PATH, new TopBuilder().build());
+        writeTx.commit().get();
+    }
 }