Split transaction lifecycle
[netconf.git] / restconf / restconf-nb-rfc8040 / src / test / java / org / opendaylight / restconf / nb / rfc8040 / rests / services / impl / RestconfDataServiceImplTest.java
index d11b10f0e88bf532c26f822a1f2b03a83f0e1a01..d68b9905330c4ec4d63837ba1b2c556dbe53d0f0 100644 (file)
@@ -19,13 +19,16 @@ import static org.opendaylight.restconf.common.patch.PatchEditOperation.CREATE;
 import static org.opendaylight.restconf.common.patch.PatchEditOperation.DELETE;
 import static org.opendaylight.restconf.common.patch.PatchEditOperation.REMOVE;
 import static org.opendaylight.restconf.common.patch.PatchEditOperation.REPLACE;
+import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateFalseFluentFuture;
+import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateFluentFuture;
+import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateTrueFluentFuture;
 
-import com.google.common.base.Optional;
-import com.google.common.util.concurrent.Futures;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Optional;
 import javax.ws.rs.core.MultivaluedHashMap;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
@@ -33,19 +36,23 @@ import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.core.UriInfo;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 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.common.api.data.TransactionChainListener;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
-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.DOMMountPoint;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
-import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
+import org.mockito.junit.MockitoJUnitRunner;
+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.DOMMountPoint;
+import org.opendaylight.mdsal.dom.api.DOMMountPointService;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
+import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
+import org.opendaylight.mdsal.dom.api.DOMTransactionChainListener;
+import org.opendaylight.mdsal.dom.spi.FixedDOMSchemaService;
+import org.opendaylight.netconf.dom.api.NetconfDataTreeService;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
@@ -53,24 +60,36 @@ import org.opendaylight.restconf.common.patch.PatchContext;
 import org.opendaylight.restconf.common.patch.PatchEntity;
 import org.opendaylight.restconf.common.patch.PatchStatusContext;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
+import org.opendaylight.restconf.nb.rfc8040.handlers.ActionServiceHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
-import org.opendaylight.restconf.nb.rfc8040.references.SchemaContextRef;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfStreamsSubscriptionService;
+import org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy;
+import org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy;
+import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy;
+import org.opendaylight.restconf.nb.rfc8040.streams.Configuration;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
 import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class RestconfDataServiceImplTest {
 
     private static final String PATH_FOR_NEW_SCHEMA_CONTEXT = "/jukebox";
@@ -78,7 +97,7 @@ public class RestconfDataServiceImplTest {
     private ContainerNode buildBaseCont;
     private ContainerNode buildBaseContConfig;
     private ContainerNode buildBaseContOperational;
-    private SchemaContextRef contextRef;
+    private EffectiveModelContext contextRef;
     private YangInstanceIdentifier iidBase;
     private DataSchemaNode schemaNode;
     private RestconfDataServiceImpl dataService;
@@ -95,11 +114,11 @@ public class RestconfDataServiceImplTest {
     @Mock
     private UriInfo uriInfo;
     @Mock
-    private DOMDataReadWriteTransaction readWrite;
+    private DOMDataTreeReadWriteTransaction readWrite;
     @Mock
-    private DOMDataReadOnlyTransaction read;
+    private DOMDataTreeReadTransaction read;
     @Mock
-    private DOMDataWriteTransaction write;
+    private DOMDataTreeWriteTransaction write;
     @Mock
     private DOMMountPointService mountPointService;
     @Mock
@@ -107,14 +126,18 @@ public class RestconfDataServiceImplTest {
     @Mock
     private DOMDataBroker mountDataBroker;
     @Mock
+    private NetconfDataTreeService netconfService;
+    @Mock
+    private ActionServiceHandler actionServiceHandler;
+    @Mock
     private DOMTransactionChain mountTransactionChain;
     @Mock
     private RestconfStreamsSubscriptionService delegRestconfSubscrService;
+    @Mock
+    private Configuration configuration;
 
     @Before
     public void setUp() throws Exception {
-        MockitoAnnotations.initMocks(this);
-
         final MultivaluedMap<String, String> value = Mockito.mock(MultivaluedMap.class);
         Mockito.when(value.entrySet()).thenReturn(new HashSet<>());
         Mockito.when(this.uriInfo.getQueryParameters()).thenReturn(value);
@@ -126,39 +149,39 @@ public class RestconfDataServiceImplTest {
         final QName containerLibraryQName = QName.create(this.baseQName, "library");
         final QName listPlaylistQName = QName.create(this.baseQName, "playlist");
 
-        final LeafNode buildLeaf = Builders.leafBuilder()
-                .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(this.leafQname))
+        final LeafNode<?> buildLeaf = Builders.leafBuilder()
+                .withNodeIdentifier(new NodeIdentifier(this.leafQname))
                 .withValue(0.2)
                 .build();
 
         this.buildPlayerCont = Builders.containerBuilder()
-                .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(this.containerPlayerQname))
+                .withNodeIdentifier(new NodeIdentifier(this.containerPlayerQname))
                 .withChild(buildLeaf)
                 .build();
 
         this.buildLibraryCont = Builders.containerBuilder()
-                .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(containerLibraryQName))
+                .withNodeIdentifier(new NodeIdentifier(containerLibraryQName))
                 .build();
 
         this.buildPlaylistList = Builders.mapBuilder()
-                .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(listPlaylistQName))
+                .withNodeIdentifier(new NodeIdentifier(listPlaylistQName))
                 .build();
 
         this.buildBaseCont = Builders.containerBuilder()
-                .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(this.baseQName))
+                .withNodeIdentifier(new NodeIdentifier(this.baseQName))
                 .withChild(this.buildPlayerCont)
                 .build();
 
         // config contains one child the same as in operational and one additional
         this.buildBaseContConfig = Builders.containerBuilder()
-                .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(this.baseQName))
+                .withNodeIdentifier(new NodeIdentifier(this.baseQName))
                 .withChild(this.buildPlayerCont)
                 .withChild(this.buildLibraryCont)
                 .build();
 
         // operational contains one child the same as in config and one additional
         this.buildBaseContOperational = Builders.containerBuilder()
-                .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(this.baseQName))
+                .withNodeIdentifier(new NodeIdentifier(this.baseQName))
                 .withChild(this.buildPlayerCont)
                 .withChild(this.buildPlaylistList)
                 .build();
@@ -167,12 +190,13 @@ public class RestconfDataServiceImplTest {
                 .node(this.baseQName)
                 .build();
 
-        this.contextRef = new SchemaContextRef(
-                YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles(PATH_FOR_NEW_SCHEMA_CONTEXT)));
-        this.schemaNode = DataSchemaContextTree.from(this.contextRef.get()).getChild(this.iidBase).getDataSchemaNode();
+        this.contextRef =
+                YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles(PATH_FOR_NEW_SCHEMA_CONTEXT));
+        this.schemaNode = DataSchemaContextTree.from(this.contextRef).findChild(this.iidBase).orElseThrow(
+            ).getDataSchemaNode();
 
-        doReturn(Futures.immediateCheckedFuture(null)).when(this.write).submit();
-        doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
+        doReturn(CommitInfo.emptyFluentFuture()).when(this.write).commit();
+        doReturn(CommitInfo.emptyFluentFuture()).when(this.readWrite).commit();
 
         doReturn(this.read).when(domTransactionChain).newReadOnlyTransaction();
         doReturn(this.readWrite).when(domTransactionChain).newReadWriteTransaction();
@@ -183,18 +207,21 @@ public class RestconfDataServiceImplTest {
 
         transactionChainHandler = new TransactionChainHandler(mockDataBroker);
 
-        final SchemaContextHandler schemaContextHandler = SchemaContextHandler.newInstance(transactionChainHandler,
+        final SchemaContextHandler schemaContextHandler = new SchemaContextHandler(transactionChainHandler,
                 Mockito.mock(DOMSchemaService.class));
 
-        schemaContextHandler.onGlobalContextUpdated(this.contextRef.get());
+        schemaContextHandler.onModelContextUpdated(this.contextRef);
         this.dataService = new RestconfDataServiceImpl(schemaContextHandler, this.transactionChainHandler,
-                DOMMountPointServiceHandler.newInstance(mountPointService), this.delegRestconfSubscrService);
+                new DOMMountPointServiceHandler(mountPointService), this.delegRestconfSubscrService,
+                this.actionServiceHandler, configuration);
         doReturn(Optional.of(this.mountPoint)).when(this.mountPointService)
                 .getMountPoint(any(YangInstanceIdentifier.class));
-        doReturn(this.contextRef.get()).when(this.mountPoint).getSchemaContext();
+        doReturn(Optional.of(FixedDOMSchemaService.of(this.contextRef))).when(this.mountPoint)
+                .getService(DOMSchemaService.class);
         doReturn(Optional.of(this.mountDataBroker)).when(this.mountPoint).getService(DOMDataBroker.class);
+        doReturn(Optional.empty()).when(this.mountPoint).getService(NetconfDataTreeService.class);
         doReturn(this.mountTransactionChain).when(this.mountDataBroker)
-                .createTransactionChain(any(TransactionChainListener.class));
+                .createTransactionChain(any(DOMTransactionChainListener.class));
         doReturn(this.read).when(this.mountTransactionChain).newReadOnlyTransaction();
         doReturn(this.readWrite).when(this.mountTransactionChain).newReadWriteTransaction();
     }
@@ -202,9 +229,9 @@ public class RestconfDataServiceImplTest {
     @Test
     public void testReadData() {
         doReturn(new MultivaluedHashMap<String, String>()).when(this.uriInfo).getQueryParameters();
-        doReturn(Futures.immediateCheckedFuture(Optional.of(this.buildBaseCont))).when(this.read)
+        doReturn(immediateFluentFuture(Optional.of(this.buildBaseCont))).when(this.read)
                 .read(LogicalDatastoreType.CONFIGURATION, this.iidBase);
-        doReturn(Futures.immediateCheckedFuture(Optional.absent()))
+        doReturn(immediateFluentFuture(Optional.empty()))
                 .when(this.read).read(LogicalDatastoreType.OPERATIONAL, this.iidBase);
         final Response response = this.dataService.readData("example-jukebox:jukebox", this.uriInfo);
         assertNotNull(response);
@@ -212,6 +239,35 @@ public class RestconfDataServiceImplTest {
         assertEquals(this.buildBaseCont, ((NormalizedNodeContext) response.getEntity()).getData());
     }
 
+    @Test
+    public void testReadRootData() {
+        doReturn(new MultivaluedHashMap<String, String>()).when(this.uriInfo).getQueryParameters();
+        doReturn(immediateFluentFuture(Optional.of(wrapNodeByDataRootContainer(this.buildBaseContConfig))))
+                .when(this.read)
+                .read(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.empty());
+        doReturn(immediateFluentFuture(Optional.of(wrapNodeByDataRootContainer(this.buildBaseContOperational))))
+                .when(this.read)
+                .read(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.empty());
+        final Response response = this.dataService.readData(this.uriInfo);
+        assertNotNull(response);
+        assertEquals(200, response.getStatus());
+
+        final NormalizedNode<?, ?> data = ((NormalizedNodeContext) response.getEntity()).getData();
+        assertTrue(data instanceof ContainerNode);
+        final Collection<DataContainerChild<? extends PathArgument, ?>> rootNodes = ((ContainerNode) data).getValue();
+        assertEquals(1, rootNodes.size());
+        final Collection<DataContainerChild<? extends PathArgument, ?>> allDataChildren
+                = ((ContainerNode) rootNodes.iterator().next()).getValue();
+        assertEquals(3, allDataChildren.size());
+    }
+
+    private static ContainerNode wrapNodeByDataRootContainer(final DataContainerChild<?, ?> data) {
+        return ImmutableContainerNodeBuilder.create()
+                .withNodeIdentifier(NodeIdentifier.create(SchemaContext.NAME))
+                .withChild(data)
+                .build();
+    }
+
     /**
      * Test read data from mount point when both {@link LogicalDatastoreType#CONFIGURATION} and
      * {@link LogicalDatastoreType#OPERATIONAL} contains the same data and some additional data to be merged.
@@ -219,9 +275,9 @@ public class RestconfDataServiceImplTest {
     @Test
     public void testReadDataMountPoint() {
         doReturn(new MultivaluedHashMap<String, String>()).when(this.uriInfo).getQueryParameters();
-        doReturn(Futures.immediateCheckedFuture(Optional.of(this.buildBaseContConfig))).when(this.read)
+        doReturn(immediateFluentFuture(Optional.of(this.buildBaseContConfig))).when(this.read)
                 .read(LogicalDatastoreType.CONFIGURATION, this.iidBase);
-        doReturn(Futures.immediateCheckedFuture(Optional.of(this.buildBaseContOperational))).when(this.read)
+        doReturn(immediateFluentFuture(Optional.of(this.buildBaseContOperational))).when(this.read)
                 .read(LogicalDatastoreType.OPERATIONAL, this.iidBase);
 
         final Response response = this.dataService.readData(
@@ -242,9 +298,9 @@ public class RestconfDataServiceImplTest {
     @Test(expected = RestconfDocumentedException.class)
     public void testReadDataNoData() {
         doReturn(new MultivaluedHashMap<String, String>()).when(this.uriInfo).getQueryParameters();
-        doReturn(Futures.immediateCheckedFuture(Optional.absent()))
+        doReturn(immediateFluentFuture(Optional.empty()))
                 .when(this.read).read(LogicalDatastoreType.CONFIGURATION, this.iidBase);
-        doReturn(Futures.immediateCheckedFuture(Optional.absent()))
+        doReturn(immediateFluentFuture(Optional.empty()))
                 .when(this.read).read(LogicalDatastoreType.OPERATIONAL, this.iidBase);
         this.dataService.readData("example-jukebox:jukebox", this.uriInfo);
     }
@@ -258,10 +314,8 @@ public class RestconfDataServiceImplTest {
         parameters.put("content", Collections.singletonList("config"));
 
         doReturn(parameters).when(this.uriInfo).getQueryParameters();
-        doReturn(Futures.immediateCheckedFuture(Optional.of(this.buildBaseContConfig))).when(this.read)
+        doReturn(immediateFluentFuture(Optional.of(this.buildBaseContConfig))).when(this.read)
                 .read(LogicalDatastoreType.CONFIGURATION, this.iidBase);
-        doReturn(Futures.immediateCheckedFuture(Optional.of(this.buildBaseContOperational))).when(this.read)
-                .read(LogicalDatastoreType.OPERATIONAL, this.iidBase);
 
         final Response response = this.dataService.readData("example-jukebox:jukebox", this.uriInfo);
 
@@ -288,9 +342,7 @@ public class RestconfDataServiceImplTest {
         parameters.put("content", Collections.singletonList("nonconfig"));
 
         doReturn(parameters).when(this.uriInfo).getQueryParameters();
-        doReturn(Futures.immediateCheckedFuture(Optional.of(this.buildBaseContConfig))).when(this.read)
-                .read(LogicalDatastoreType.CONFIGURATION, this.iidBase);
-        doReturn(Futures.immediateCheckedFuture(Optional.of(this.buildBaseContOperational))).when(this.read)
+        doReturn(immediateFluentFuture(Optional.of(this.buildBaseContOperational))).when(this.read)
                 .read(LogicalDatastoreType.OPERATIONAL, this.iidBase);
 
         final Response response = this.dataService.readData("example-jukebox:jukebox", this.uriInfo);
@@ -312,10 +364,10 @@ public class RestconfDataServiceImplTest {
     @Test
     public void testPutData() {
         final InstanceIdentifierContext<DataSchemaNode> iidContext =
-                new InstanceIdentifierContext<>(this.iidBase, this.schemaNode, null, this.contextRef.get());
+                new InstanceIdentifierContext<>(this.iidBase, this.schemaNode, null, this.contextRef);
         final NormalizedNodeContext payload = new NormalizedNodeContext(iidContext, this.buildBaseCont);
 
-        doReturn(Futures.immediateCheckedFuture(Boolean.TRUE)).when(this.readWrite)
+        doReturn(immediateTrueFluentFuture()).when(this.read)
                 .exists(LogicalDatastoreType.CONFIGURATION, this.iidBase);
         doNothing().when(this.readWrite).put(LogicalDatastoreType.CONFIGURATION, this.iidBase, payload.getData());
         final Response response = this.dataService.putData(null, payload, this.uriInfo);
@@ -330,10 +382,10 @@ public class RestconfDataServiceImplTest {
 //        doReturn(this.transactionChainHandler.get()).when(dataBroker)
 //                .createTransactionChain(RestConnectorProvider.TRANSACTION_CHAIN_LISTENER);
         final InstanceIdentifierContext<DataSchemaNode> iidContext =
-                new InstanceIdentifierContext<>(this.iidBase, this.schemaNode, mountPoint, this.contextRef.get());
+                new InstanceIdentifierContext<>(this.iidBase, this.schemaNode, mountPoint, this.contextRef);
         final NormalizedNodeContext payload = new NormalizedNodeContext(iidContext, this.buildBaseCont);
 
-        doReturn(Futures.immediateCheckedFuture(Boolean.TRUE)).when(this.readWrite)
+        doReturn(immediateTrueFluentFuture()).when(this.read)
                 .exists(LogicalDatastoreType.CONFIGURATION, this.iidBase);
         doNothing().when(this.readWrite).put(LogicalDatastoreType.CONFIGURATION, this.iidBase, payload.getData());
         final Response response = this.dataService.putData(null, payload, this.uriInfo);
@@ -345,14 +397,14 @@ public class RestconfDataServiceImplTest {
     public void testPostData() {
         final QName listQname = QName.create(this.baseQName, "playlist");
         final QName listKeyQname = QName.create(this.baseQName, "name");
-        final YangInstanceIdentifier.NodeIdentifierWithPredicates nodeWithKey =
-                new YangInstanceIdentifier.NodeIdentifierWithPredicates(listQname, listKeyQname, "name of band");
+        final NodeIdentifierWithPredicates nodeWithKey =
+                NodeIdentifierWithPredicates.of(listQname, listKeyQname, "name of band");
         final LeafNode<Object> content = Builders.leafBuilder()
-                .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(QName.create(this.baseQName, "name")))
+                .withNodeIdentifier(new NodeIdentifier(QName.create(this.baseQName, "name")))
                 .withValue("name of band")
                 .build();
         final LeafNode<Object> content2 = Builders.leafBuilder()
-            .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(QName.create(this.baseQName, "description")))
+            .withNodeIdentifier(new NodeIdentifier(QName.create(this.baseQName, "description")))
             .withValue("band description")
             .build();
         final MapEntryNode mapEntryNode = Builders.mapEntryBuilder()
@@ -361,24 +413,22 @@ public class RestconfDataServiceImplTest {
                 .withChild(content2)
                 .build();
         final MapNode buildList = Builders.mapBuilder()
-                .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(listQname))
+                .withNodeIdentifier(new NodeIdentifier(listQname))
                 .withChild(mapEntryNode)
                 .build();
 
         doReturn(new MultivaluedHashMap<String, String>()).when(this.uriInfo).getQueryParameters();
         final InstanceIdentifierContext<? extends SchemaNode> iidContext =
-                new InstanceIdentifierContext<>(this.iidBase, null, null, this.contextRef.get());
+                new InstanceIdentifierContext<>(this.iidBase, null, null, this.contextRef);
         final NormalizedNodeContext payload = new NormalizedNodeContext(iidContext, buildList);
-        doReturn(Futures.immediateCheckedFuture(Optional.absent()))
-                .when(this.read).read(LogicalDatastoreType.CONFIGURATION, this.iidBase);
         final MapNode data = (MapNode) payload.getData();
-        final YangInstanceIdentifier.NodeIdentifierWithPredicates identifier =
-                data.getValue().iterator().next().getIdentifier();
+        final MapEntryNode entryNode = data.getValue().iterator().next();
+        final NodeIdentifierWithPredicates identifier = entryNode.getIdentifier();
         final YangInstanceIdentifier node =
                 payload.getInstanceIdentifierContext().getInstanceIdentifier().node(identifier);
-        doReturn(Futures.immediateCheckedFuture(false))
-                .when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, node);
-        doNothing().when(this.readWrite).put(LogicalDatastoreType.CONFIGURATION, node, payload.getData());
+        doReturn(immediateFalseFluentFuture())
+                .when(this.read).exists(LogicalDatastoreType.CONFIGURATION, node);
+        doNothing().when(this.readWrite).put(LogicalDatastoreType.CONFIGURATION, node, entryNode);
         doReturn(UriBuilder.fromUri("http://localhost:8181/restconf/15/")).when(this.uriInfo).getBaseUriBuilder();
 
         final Response response = this.dataService.postData(null, payload, this.uriInfo);
@@ -388,7 +438,7 @@ public class RestconfDataServiceImplTest {
     @Test
     public void testDeleteData() {
         doNothing().when(this.readWrite).delete(LogicalDatastoreType.CONFIGURATION, this.iidBase);
-        doReturn(Futures.immediateCheckedFuture(true))
+        doReturn(immediateTrueFluentFuture())
                 .when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, this.iidBase);
         final Response response = this.dataService.deleteData("example-jukebox:jukebox");
         assertNotNull(response);
@@ -401,7 +451,7 @@ public class RestconfDataServiceImplTest {
     @Test
     public void testDeleteDataMountPoint() {
         doNothing().when(this.readWrite).delete(LogicalDatastoreType.CONFIGURATION, this.iidBase);
-        doReturn(Futures.immediateCheckedFuture(true))
+        doReturn(immediateTrueFluentFuture())
                 .when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, this.iidBase);
         final Response response =
                 this.dataService.deleteData("example-jukebox:jukebox/yang-ext:mount/example-jukebox:jukebox");
@@ -410,9 +460,9 @@ public class RestconfDataServiceImplTest {
     }
 
     @Test
-    public void testPatchData() throws Exception {
+    public void testPatchData() {
         final InstanceIdentifierContext<? extends SchemaNode> iidContext =
-                new InstanceIdentifierContext<>(this.iidBase, this.schemaNode, null, this.contextRef.get());
+                new InstanceIdentifierContext<>(this.iidBase, this.schemaNode, null, this.contextRef);
         final List<PatchEntity> entity = new ArrayList<>();
         final YangInstanceIdentifier iidleaf = YangInstanceIdentifier.builder(this.iidBase)
                 .node(this.containerPlayerQname)
@@ -423,13 +473,10 @@ public class RestconfDataServiceImplTest {
         entity.add(new PatchEntity("delete data", DELETE, iidleaf));
         final PatchContext patch = new PatchContext(iidContext, entity, "test patch id");
 
-        doReturn(Futures.immediateCheckedFuture(Optional.of(this.buildBaseCont))).when(this.read)
-                .read(LogicalDatastoreType.CONFIGURATION, this.iidBase);
-        doNothing().when(this.write).put(LogicalDatastoreType.CONFIGURATION, this.iidBase, this.buildBaseCont);
         doNothing().when(this.readWrite).delete(LogicalDatastoreType.CONFIGURATION, iidleaf);
-        doReturn(Futures.immediateCheckedFuture(false))
+        doReturn(immediateFalseFluentFuture())
                 .when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, this.iidBase);
-        doReturn(Futures.immediateCheckedFuture(true))
+        doReturn(immediateTrueFluentFuture())
                 .when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, iidleaf);
         final PatchStatusContext status = this.dataService.patchData(patch, this.uriInfo);
         assertTrue(status.isOk());
@@ -440,7 +487,7 @@ public class RestconfDataServiceImplTest {
     @Test
     public void testPatchDataMountPoint() throws Exception {
         final InstanceIdentifierContext<? extends SchemaNode> iidContext = new InstanceIdentifierContext<>(
-                this.iidBase, this.schemaNode, this.mountPoint, this.contextRef.get());
+                this.iidBase, this.schemaNode, this.mountPoint, this.contextRef);
         final List<PatchEntity> entity = new ArrayList<>();
         final YangInstanceIdentifier iidleaf = YangInstanceIdentifier.builder(this.iidBase)
                 .node(this.containerPlayerQname)
@@ -451,14 +498,10 @@ public class RestconfDataServiceImplTest {
         entity.add(new PatchEntity("delete data", DELETE, iidleaf));
         final PatchContext patch = new PatchContext(iidContext, entity, "test patch id");
 
-        doReturn(Futures.immediateCheckedFuture(Optional.of(this.buildBaseCont))).when(this.read)
-                .read(LogicalDatastoreType.CONFIGURATION, this.iidBase);
-        doNothing().when(this.write).put(LogicalDatastoreType.CONFIGURATION, this.iidBase, this.buildBaseCont);
         doNothing().when(this.readWrite).delete(LogicalDatastoreType.CONFIGURATION, iidleaf);
-        doReturn(Futures.immediateCheckedFuture(false))
+        doReturn(immediateFalseFluentFuture())
                 .when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, this.iidBase);
-        doReturn(Futures.immediateCheckedFuture(true))
-                .when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, iidleaf);
+        doReturn(immediateTrueFluentFuture()).when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, iidleaf);
 
         final PatchStatusContext status = this.dataService.patchData(patch, this.uriInfo);
         assertTrue(status.isOk());
@@ -467,9 +510,9 @@ public class RestconfDataServiceImplTest {
     }
 
     @Test
-    public void testPatchDataDeleteNotExist() throws Exception {
+    public void testPatchDataDeleteNotExist() {
         final InstanceIdentifierContext<? extends SchemaNode> iidContext =
-                new InstanceIdentifierContext<>(this.iidBase, this.schemaNode, null, this.contextRef.get());
+                new InstanceIdentifierContext<>(this.iidBase, this.schemaNode, null, this.contextRef);
         final List<PatchEntity> entity = new ArrayList<>();
         final YangInstanceIdentifier iidleaf = YangInstanceIdentifier.builder(this.iidBase)
                 .node(this.containerPlayerQname)
@@ -480,13 +523,10 @@ public class RestconfDataServiceImplTest {
         entity.add(new PatchEntity("delete data", DELETE, iidleaf));
         final PatchContext patch = new PatchContext(iidContext, entity, "test patch id");
 
-        doReturn(Futures.immediateCheckedFuture(Optional.of(this.buildBaseCont))).when(this.read)
-                .read(LogicalDatastoreType.CONFIGURATION, this.iidBase);
-        doNothing().when(this.write).put(LogicalDatastoreType.CONFIGURATION, this.iidBase, this.buildBaseCont);
         doNothing().when(this.readWrite).delete(LogicalDatastoreType.CONFIGURATION, iidleaf);
-        doReturn(Futures.immediateCheckedFuture(false))
+        doReturn(immediateFalseFluentFuture())
                 .when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, this.iidBase);
-        doReturn(Futures.immediateCheckedFuture(false))
+        doReturn(immediateFalseFluentFuture())
                 .when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, iidleaf);
         doReturn(true).when(this.readWrite).cancel();
         final PatchStatusContext status = this.dataService.patchData(patch, this.uriInfo);
@@ -500,4 +540,17 @@ public class RestconfDataServiceImplTest {
         final String errorMessage = status.getEditCollection().get(2).getEditErrors().get(0).getErrorMessage();
         assertEquals("Data does not exist", errorMessage);
     }
+
+    @Test
+    public void testGetRestconfStrategy() {
+        final InstanceIdentifierContext<? extends SchemaNode> iidContext = new InstanceIdentifierContext<>(
+                this.iidBase, this.schemaNode, this.mountPoint, this.contextRef);
+
+        RestconfStrategy restconfStrategy = this.dataService.getRestconfStrategy(this.mountPoint);
+        assertTrue(restconfStrategy instanceof MdsalRestconfStrategy);
+
+        doReturn(Optional.of(this.netconfService)).when(this.mountPoint).getService(NetconfDataTreeService.class);
+        restconfStrategy = this.dataService.getRestconfStrategy(this.mountPoint);
+        assertTrue(restconfStrategy instanceof NetconfRestconfStrategy);
+    }
 }