Merge "Migrate restconf to MD-SAL APIs"
[netconf.git] / restconf / restconf-nb-rfc8040 / src / test / java / org / opendaylight / restconf / nb / rfc8040 / rests / utils / PutDataTransactionUtilTest.java
index 9c9bdbe860481c24429956cbec118c8f837ce03a..dfb3ad4e32b2086dd07e3fe14408fb5aa58192e3 100644 (file)
@@ -5,28 +5,30 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.restconf.nb.rfc8040.rests.utils;
 
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.verify;
+import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateFalseFluentFuture;
 
-import com.google.common.base.Optional;
-import com.google.common.util.concurrent.Futures;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mock;
+import org.mockito.Mockito;
 import org.mockito.MockitoAnnotations;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
-import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
+import org.opendaylight.mdsal.common.api.CommitInfo;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.mdsal.dom.api.DOMDataBroker;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
+import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
+import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
 import org.opendaylight.restconf.nb.rfc8040.references.SchemaContextRef;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.TransactionVarsWrapper;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -48,13 +50,15 @@ public class PutDataTransactionUtilTest {
     @Mock
     private DOMTransactionChain transactionChain;
     @Mock
-    private DOMDataReadWriteTransaction readWrite;
+    private DOMDataTreeReadWriteTransaction readWrite;
     @Mock
-    private DOMDataReadOnlyTransaction read;
+    private DOMDataTreeReadTransaction read;
     @Mock
-    private DOMDataWriteTransaction write;
-
+    private DOMDataTreeWriteTransaction write;
+    @Mock
+    private DOMDataBroker mockDataBroker;
 
+    private TransactionChainHandler transactionChainHandler;
     private SchemaContextRef refSchemaCtx;
     private LeafNode buildLeaf;
     private ContainerNode buildBaseCont;
@@ -153,6 +157,8 @@ public class PutDataTransactionUtilTest {
                 .withChild(buildList)
                 .build();
 
+        Mockito.doReturn(transactionChain).when(mockDataBroker).createTransactionChain(Mockito.any());
+        transactionChainHandler = new TransactionChainHandler(mockDataBroker);
     }
 
     @Test
@@ -208,16 +214,16 @@ public class PutDataTransactionUtilTest {
         doReturn(this.readWrite).when(this.transactionChain).newReadWriteTransaction();
         doReturn(this.read).when(this.transactionChain).newReadOnlyTransaction();
         doReturn(this.write).when(this.transactionChain).newWriteOnlyTransaction();
-        doReturn(Futures.immediateCheckedFuture(Optional.absent()))
-                .when(this.read).read(LogicalDatastoreType.CONFIGURATION, this.iid2);
-        doNothing().when(this.write).put(LogicalDatastoreType.CONFIGURATION,
+        doReturn(immediateFalseFluentFuture())
+                .when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, this.iid2);
+        doNothing().when(this.readWrite).put(LogicalDatastoreType.CONFIGURATION,
                 payload.getInstanceIdentifierContext().getInstanceIdentifier(), payload.getData());
-        doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
+        doReturn(CommitInfo.emptyFluentFuture()).when(this.readWrite).commit();
 
         PutDataTransactionUtil.putData(payload, this.refSchemaCtx,
-                new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, this.transactionChain), null,
+                new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, transactionChainHandler), null,
                 null);
-        verify(this.read).read(LogicalDatastoreType.CONFIGURATION,
+        verify(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION,
                 payload.getInstanceIdentifierContext().getInstanceIdentifier());
         verify(this.readWrite).put(LogicalDatastoreType.CONFIGURATION,
                 payload.getInstanceIdentifierContext().getInstanceIdentifier(), payload.getData());
@@ -232,16 +238,16 @@ public class PutDataTransactionUtilTest {
         doReturn(this.readWrite).when(this.transactionChain).newReadWriteTransaction();
         doReturn(this.read).when(this.transactionChain).newReadOnlyTransaction();
         doReturn(this.write).when(this.transactionChain).newWriteOnlyTransaction();
-        doReturn(Futures.immediateCheckedFuture(Optional.absent()))
-                .when(this.read).read(LogicalDatastoreType.CONFIGURATION, this.iid);
-        doNothing().when(this.write).put(LogicalDatastoreType.CONFIGURATION,
+        doReturn(immediateFalseFluentFuture())
+                .when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, this.iid);
+        doNothing().when(this.readWrite).put(LogicalDatastoreType.CONFIGURATION,
                 payload.getInstanceIdentifierContext().getInstanceIdentifier(), payload.getData());
-        doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
+        doReturn(CommitInfo.emptyFluentFuture()).when(this.readWrite).commit();
 
         PutDataTransactionUtil.putData(payload, this.refSchemaCtx,
-                new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, this.transactionChain), null,
+                new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, transactionChainHandler), null,
                 null);
-        verify(this.read).read(LogicalDatastoreType.CONFIGURATION,
+        verify(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION,
                 payload.getInstanceIdentifierContext().getInstanceIdentifier());
         verify(this.readWrite).put(LogicalDatastoreType.CONFIGURATION,
                 payload.getInstanceIdentifierContext().getInstanceIdentifier(), payload.getData());
@@ -256,17 +262,15 @@ public class PutDataTransactionUtilTest {
         doReturn(this.readWrite).when(this.transactionChain).newReadWriteTransaction();
         doReturn(this.read).when(this.transactionChain).newReadOnlyTransaction();
         doReturn(this.write).when(this.transactionChain).newWriteOnlyTransaction();
-        doReturn(Futures.immediateCheckedFuture(Optional.absent()))
-                .when(this.read).read(LogicalDatastoreType.CONFIGURATION, this.iid2);
-        doNothing().when(this.write).put(LogicalDatastoreType.CONFIGURATION,
+        doReturn(immediateFalseFluentFuture())
+                .when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, this.iid2);
+        doNothing().when(this.readWrite).put(LogicalDatastoreType.CONFIGURATION,
                 payload.getInstanceIdentifierContext().getInstanceIdentifier(), payload.getData());
-        doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
+        doReturn(CommitInfo.emptyFluentFuture()).when(this.readWrite).commit();
         PutDataTransactionUtil.putData(payload, this.refSchemaCtx,
-                new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, this.transactionChain), null,
+                new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, transactionChainHandler), null,
                 null);
-        verify(this.read).read(LogicalDatastoreType.CONFIGURATION, this.iid2);
+        verify(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, this.iid2);
         verify(this.readWrite).put(LogicalDatastoreType.CONFIGURATION, this.iid2, payload.getData());
     }
-
 }
-