Fix netconf-connector-config groupId
[netconf.git] / opendaylight / restconf / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / test / JSONRestconfServiceImplTest.java
1 /*
2  * Copyright (c) 2015 Brocade Communications Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.sal.restconf.impl.test;
9
10 import static org.hamcrest.CoreMatchers.containsString;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertThat;
14 import static org.junit.Assert.assertTrue;
15 import static org.mockito.Matchers.any;
16 import static org.mockito.Matchers.eq;
17 import static org.mockito.Matchers.isNull;
18 import static org.mockito.Matchers.notNull;
19 import static org.mockito.Matchers.same;
20 import static org.mockito.Mockito.doReturn;
21 import static org.mockito.Mockito.mock;
22 import static org.mockito.Mockito.reset;
23 import static org.mockito.Mockito.verify;
24 import com.google.common.base.Optional;
25 import com.google.common.io.Resources;
26 import com.google.common.util.concurrent.Futures;
27 import java.io.FileNotFoundException;
28 import java.io.IOException;
29 import java.nio.charset.StandardCharsets;
30 import java.util.List;
31 import java.util.Map;
32 import org.junit.Before;
33 import org.junit.BeforeClass;
34 import org.junit.Test;
35 import org.mockito.ArgumentCaptor;
36 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
37 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
38 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
39 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
40 import org.opendaylight.controller.md.sal.dom.api.DOMRpcException;
41 import org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementationNotAvailableException;
42 import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
43 import org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult;
44 import org.opendaylight.netconf.sal.restconf.impl.BrokerFacade;
45 import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
46 import org.opendaylight.netconf.sal.restconf.impl.JSONRestconfServiceImpl;
47 import org.opendaylight.netconf.sal.restconf.impl.RestconfImpl;
48 import org.opendaylight.yangtools.yang.common.OperationFailedException;
49 import org.opendaylight.yangtools.yang.common.QName;
50 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
51 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
52 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
53 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
54 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
55 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
56 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
57 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
58 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
59 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
60 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
61 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
62 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
63 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
64
65 /**
66  * Unit tests for JSONRestconfServiceImpl.
67  *
68  * @author Thomas Pantelis
69  */
70 public class JSONRestconfServiceImplTest {
71     static final String IETF_INTERFACES_NS = "urn:ietf:params:xml:ns:yang:ietf-interfaces";
72     static final String IETF_INTERFACES_VERSION = "2013-07-04";
73     static final QName INTERFACES_QNAME = QName.create(IETF_INTERFACES_NS, IETF_INTERFACES_VERSION, "interfaces");
74     static final QName INTERFACE_QNAME = QName.create(IETF_INTERFACES_NS, IETF_INTERFACES_VERSION, "interface");
75     static final QName NAME_QNAME = QName.create(IETF_INTERFACES_NS, IETF_INTERFACES_VERSION, "name");
76     static final QName TYPE_QNAME = QName.create(IETF_INTERFACES_NS, IETF_INTERFACES_VERSION, "type");
77     static final QName ENABLED_QNAME = QName.create(IETF_INTERFACES_NS, IETF_INTERFACES_VERSION, "enabled");
78     static final QName DESC_QNAME = QName.create(IETF_INTERFACES_NS, IETF_INTERFACES_VERSION, "description");
79
80     static final String TEST_MODULE_NS = "test:module";
81     static final String TEST_MODULE_VERSION = "2014-01-09";
82     static final QName TEST_CONT_QNAME = QName.create(TEST_MODULE_NS, TEST_MODULE_VERSION, "cont");
83     static final QName TEST_CONT1_QNAME = QName.create(TEST_MODULE_NS, TEST_MODULE_VERSION, "cont1");
84     static final QName TEST_LF11_QNAME = QName.create(TEST_MODULE_NS, TEST_MODULE_VERSION, "lf11");
85     static final QName TEST_LF12_QNAME = QName.create(TEST_MODULE_NS, TEST_MODULE_VERSION, "lf12");
86
87     static final String TOASTER_MODULE_NS = "http://netconfcentral.org/ns/toaster";
88     static final String TOASTER_MODULE_VERSION = "2009-11-20";
89     static final QName TOASTER_DONENESS_QNAME = QName.create(TOASTER_MODULE_NS, TOASTER_MODULE_VERSION, "toasterDoneness");
90     static final QName TOASTER_TYPE_QNAME = QName.create(TOASTER_MODULE_NS, TOASTER_MODULE_VERSION, "toasterToastType");
91     static final QName WHEAT_BREAD_QNAME = QName.create(TOASTER_MODULE_NS, TOASTER_MODULE_VERSION, "wheat-bread");
92     static final QName MAKE_TOAST_QNAME = QName.create(TOASTER_MODULE_NS, TOASTER_MODULE_VERSION, "make-toast");
93     static final QName CANCEL_TOAST_QNAME = QName.create(TOASTER_MODULE_NS, TOASTER_MODULE_VERSION, "cancel-toast");
94     static final QName TEST_OUTPUT_QNAME = QName.create(TOASTER_MODULE_NS, TOASTER_MODULE_VERSION, "testOutput");
95     static final QName TEXT_OUT_QNAME = QName.create(TOASTER_MODULE_NS, TOASTER_MODULE_VERSION, "textOut");
96
97     private static BrokerFacade brokerFacade;
98
99     private final JSONRestconfServiceImpl service = new JSONRestconfServiceImpl();
100
101     @BeforeClass
102     public static void init() throws IOException {
103         ControllerContext.getInstance().setSchemas(TestUtils.loadSchemaContext("/full-versions/yangs"));
104         brokerFacade = mock(BrokerFacade.class);
105         RestconfImpl.getInstance().setBroker(brokerFacade);
106         RestconfImpl.getInstance().setControllerContext(ControllerContext.getInstance());
107     }
108
109     @Before
110     public void setup() {
111         reset(brokerFacade);
112     }
113
114     private static String loadData(final String path) throws IOException {
115         return Resources.asCharSource(JSONRestconfServiceImplTest.class.getResource(path), StandardCharsets.UTF_8).read();
116     }
117
118     @SuppressWarnings("rawtypes")
119     @Test
120     public void testPut() throws Exception {
121         doReturn(Futures.immediateCheckedFuture(null)).when(brokerFacade).commitConfigurationDataPut(
122                 notNull(SchemaContext.class), notNull(YangInstanceIdentifier.class), notNull(NormalizedNode.class));
123
124         String uriPath = "ietf-interfaces:interfaces/interface/eth0";
125         String payload = loadData("/parts/ietf-interfaces_interfaces.json");
126
127         service.put(uriPath, payload);
128
129         ArgumentCaptor<YangInstanceIdentifier> capturedPath = ArgumentCaptor.forClass(YangInstanceIdentifier.class);
130         ArgumentCaptor<NormalizedNode> capturedNode = ArgumentCaptor.forClass(NormalizedNode.class);
131         verify(brokerFacade).commitConfigurationDataPut(notNull(SchemaContext.class), capturedPath.capture(),
132                 capturedNode.capture());
133
134         verifyPath(capturedPath.getValue(), INTERFACES_QNAME, INTERFACE_QNAME,
135                 new Object[]{INTERFACE_QNAME, NAME_QNAME, "eth0"});
136
137         assertTrue("Expected MapEntryNode. Actual " + capturedNode.getValue().getClass(),
138                 capturedNode.getValue() instanceof MapEntryNode);
139         MapEntryNode actualNode = (MapEntryNode) capturedNode.getValue();
140         assertEquals("MapEntryNode node type", INTERFACE_QNAME, actualNode.getNodeType());
141         verifyLeafNode(actualNode, NAME_QNAME, "eth0");
142         verifyLeafNode(actualNode, TYPE_QNAME, "ethernetCsmacd");
143         verifyLeafNode(actualNode, ENABLED_QNAME, Boolean.FALSE);
144         verifyLeafNode(actualNode, DESC_QNAME, "some interface");
145     }
146
147     @SuppressWarnings("rawtypes")
148     @Test
149     public void testPutBehindMountPoint() throws Exception {
150         DOMMountPoint mockMountPoint = setupTestMountPoint();
151
152         doReturn(Futures.immediateCheckedFuture(null)).when(brokerFacade).commitConfigurationDataPut(
153                 notNull(DOMMountPoint.class), notNull(YangInstanceIdentifier.class), notNull(NormalizedNode.class));
154
155         String uriPath = "ietf-interfaces:interfaces/yang-ext:mount/test-module:cont/cont1";
156         String payload = loadData("/full-versions/testCont1Data.json");
157
158         service.put(uriPath, payload);
159
160         ArgumentCaptor<YangInstanceIdentifier> capturedPath = ArgumentCaptor.forClass(YangInstanceIdentifier.class);
161         ArgumentCaptor<NormalizedNode> capturedNode = ArgumentCaptor.forClass(NormalizedNode.class);
162         verify(brokerFacade).commitConfigurationDataPut(same(mockMountPoint), capturedPath.capture(),
163                 capturedNode.capture());
164
165         verifyPath(capturedPath.getValue(), TEST_CONT_QNAME, TEST_CONT1_QNAME);
166
167         assertTrue("Expected ContainerNode", capturedNode.getValue() instanceof ContainerNode);
168         ContainerNode actualNode = (ContainerNode) capturedNode.getValue();
169         assertEquals("ContainerNode node type", TEST_CONT1_QNAME, actualNode.getNodeType());
170         verifyLeafNode(actualNode, TEST_LF11_QNAME, "lf11 data");
171         verifyLeafNode(actualNode, TEST_LF12_QNAME, "lf12 data");
172     }
173
174     @Test(expected=TransactionCommitFailedException.class)
175     public void testPutFailure() throws Throwable {
176         doReturn(Futures.immediateFailedCheckedFuture(new TransactionCommitFailedException("mock")))
177                 .when(brokerFacade).commitConfigurationDataPut(notNull(SchemaContext.class),
178                         notNull(YangInstanceIdentifier.class), notNull(NormalizedNode.class));
179
180         String uriPath = "ietf-interfaces:interfaces/interface/eth0";
181         String payload = loadData("/parts/ietf-interfaces_interfaces.json");
182
183         try {
184             service.put(uriPath, payload);
185         } catch (OperationFailedException e) {
186             assertNotNull(e.getCause());
187             throw e.getCause();
188         }
189     }
190
191     @SuppressWarnings("rawtypes")
192     @Test
193     public void testPost() throws Exception {
194         doReturn(Futures.immediateCheckedFuture(null)).when(brokerFacade).commitConfigurationDataPost(
195                 any(SchemaContext.class), any(YangInstanceIdentifier.class), any(NormalizedNode.class));
196
197         String uriPath = null;
198         String payload = loadData("/parts/ietf-interfaces_interfaces_absolute_path.json");
199
200         service.post(uriPath, payload);
201
202         ArgumentCaptor<YangInstanceIdentifier> capturedPath = ArgumentCaptor.forClass(YangInstanceIdentifier.class);
203         ArgumentCaptor<NormalizedNode> capturedNode = ArgumentCaptor.forClass(NormalizedNode.class);
204         verify(brokerFacade).commitConfigurationDataPost(notNull(SchemaContext.class), capturedPath.capture(),
205                 capturedNode.capture());
206
207         verifyPath(capturedPath.getValue(), INTERFACES_QNAME);
208
209         assertTrue("Expected ContainerNode", capturedNode.getValue() instanceof ContainerNode);
210         ContainerNode actualNode = (ContainerNode) capturedNode.getValue();
211         assertEquals("ContainerNode node type", INTERFACES_QNAME, actualNode.getNodeType());
212
213         Optional<DataContainerChild<?, ?>> mapChild = actualNode.getChild(new NodeIdentifier(INTERFACE_QNAME));
214         assertEquals(INTERFACE_QNAME.toString() + " present", true, mapChild.isPresent());
215         assertTrue("Expected MapNode. Actual " + mapChild.get().getClass(), mapChild.get() instanceof MapNode);
216         MapNode mapNode = (MapNode)mapChild.get();
217
218         NodeIdentifierWithPredicates entryNodeID = new NodeIdentifierWithPredicates(
219                 INTERFACE_QNAME, NAME_QNAME, "eth0");
220         Optional<MapEntryNode> entryChild = mapNode.getChild(entryNodeID);
221         assertEquals(entryNodeID.toString() + " present", true, entryChild.isPresent());
222         MapEntryNode entryNode = entryChild.get();
223         verifyLeafNode(entryNode, NAME_QNAME, "eth0");
224         verifyLeafNode(entryNode, TYPE_QNAME, "ethernetCsmacd");
225         verifyLeafNode(entryNode, ENABLED_QNAME, Boolean.FALSE);
226         verifyLeafNode(entryNode, DESC_QNAME, "some interface");
227     }
228
229     @SuppressWarnings("rawtypes")
230     @Test
231     public void testPostBehindMountPoint() throws Exception {
232         DOMMountPoint mockMountPoint = setupTestMountPoint();
233
234         doReturn(Futures.immediateCheckedFuture(null)).when(brokerFacade).commitConfigurationDataPost(
235                 notNull(DOMMountPoint.class), notNull(YangInstanceIdentifier.class), notNull(NormalizedNode.class));
236
237         String uriPath = "ietf-interfaces:interfaces/yang-ext:mount/test-module:cont";
238         String payload = loadData("/full-versions/testCont1Data.json");
239
240         service.post(uriPath, payload);
241
242         ArgumentCaptor<YangInstanceIdentifier> capturedPath = ArgumentCaptor.forClass(YangInstanceIdentifier.class);
243         ArgumentCaptor<NormalizedNode> capturedNode = ArgumentCaptor.forClass(NormalizedNode.class);
244         verify(brokerFacade).commitConfigurationDataPost(same(mockMountPoint), capturedPath.capture(),
245                 capturedNode.capture());
246
247         verifyPath(capturedPath.getValue(), TEST_CONT_QNAME, TEST_CONT1_QNAME);
248
249         assertTrue("Expected ContainerNode", capturedNode.getValue() instanceof ContainerNode);
250         ContainerNode actualNode = (ContainerNode) capturedNode.getValue();
251         assertEquals("ContainerNode node type", TEST_CONT1_QNAME, actualNode.getNodeType());
252         verifyLeafNode(actualNode, TEST_LF11_QNAME, "lf11 data");
253         verifyLeafNode(actualNode, TEST_LF12_QNAME, "lf12 data");
254     }
255
256     @Test(expected=TransactionCommitFailedException.class)
257     public void testPostFailure() throws Throwable {
258         doReturn(Futures.immediateFailedCheckedFuture(new TransactionCommitFailedException("mock")))
259                 .when(brokerFacade).commitConfigurationDataPost(any(SchemaContext.class),
260                         any(YangInstanceIdentifier.class), any(NormalizedNode.class));
261
262         String uriPath = null;
263         String payload = loadData("/parts/ietf-interfaces_interfaces_absolute_path.json");
264
265         try {
266             service.post(uriPath, payload);
267         } catch (OperationFailedException e) {
268             assertNotNull(e.getCause());
269             throw e.getCause();
270         }
271     }
272
273     @Test
274     public void testDelete() throws Exception {
275         doReturn(Futures.immediateCheckedFuture(null)).when(brokerFacade).commitConfigurationDataDelete(
276                 notNull(YangInstanceIdentifier.class));
277
278         String uriPath = "ietf-interfaces:interfaces/interface/eth0";
279
280         service.delete(uriPath);
281
282         ArgumentCaptor<YangInstanceIdentifier> capturedPath = ArgumentCaptor.forClass(YangInstanceIdentifier.class);
283         verify(brokerFacade).commitConfigurationDataDelete(capturedPath.capture());
284
285         verifyPath(capturedPath.getValue(), INTERFACES_QNAME, INTERFACE_QNAME,
286                 new Object[]{INTERFACE_QNAME, NAME_QNAME, "eth0"});
287     }
288
289     @Test(expected=OperationFailedException.class)
290     public void testDeleteFailure() throws Exception {
291         String invalidUriPath = "ietf-interfaces:interfaces/invalid";
292
293         service.delete(invalidUriPath);
294     }
295
296     @Test
297     public void testGetConfig() throws Exception {
298         testGet(LogicalDatastoreType.CONFIGURATION);
299     }
300
301     @Test
302     public void testGetOperational() throws Exception {
303         testGet(LogicalDatastoreType.OPERATIONAL);
304     }
305
306     @Test
307     public void testGetWithNoData() throws Exception {
308         doReturn(null).when(brokerFacade).readConfigurationData(notNull(YangInstanceIdentifier.class));
309
310         String uriPath = "ietf-interfaces:interfaces";
311
312         Optional<String> optionalResp = service.get(uriPath, LogicalDatastoreType.CONFIGURATION);
313
314         assertEquals("Response present", false, optionalResp.isPresent());
315     }
316
317     @Test(expected=OperationFailedException.class)
318     public void testGetFailure() throws Exception {
319         String invalidUriPath = "/ietf-interfaces:interfaces/invalid";
320
321         service.get(invalidUriPath, LogicalDatastoreType.CONFIGURATION);
322     }
323
324     @SuppressWarnings("rawtypes")
325     @Test
326     public void testInvokeRpcWithInput() throws Exception {
327         SchemaPath path = SchemaPath.create(true, MAKE_TOAST_QNAME);
328
329         DOMRpcResult expResult = new DefaultDOMRpcResult((NormalizedNode<?, ?>)null);
330         doReturn(Futures.immediateCheckedFuture(expResult)).when(brokerFacade).invokeRpc(eq(path),
331                 any(NormalizedNode.class));
332
333         String uriPath = "toaster:make-toast";
334         String input = loadData("/full-versions/make-toast-rpc-input.json");
335
336         Optional<String> output = service.invokeRpc(uriPath, Optional.of(input));
337
338         assertEquals("Output present", false, output.isPresent());
339
340         ArgumentCaptor<NormalizedNode> capturedNode = ArgumentCaptor.forClass(NormalizedNode.class);
341         verify(brokerFacade).invokeRpc(eq(path), capturedNode.capture());
342
343         assertTrue("Expected ContainerNode. Actual " + capturedNode.getValue().getClass(),
344                 capturedNode.getValue() instanceof ContainerNode);
345         ContainerNode actualNode = (ContainerNode) capturedNode.getValue();
346         verifyLeafNode(actualNode, TOASTER_DONENESS_QNAME, Long.valueOf(10));
347         verifyLeafNode(actualNode, TOASTER_TYPE_QNAME, WHEAT_BREAD_QNAME);
348     }
349
350     @Test
351     public void testInvokeRpcWithNoInput() throws Exception {
352         SchemaPath path = SchemaPath.create(true, CANCEL_TOAST_QNAME);
353
354         DOMRpcResult expResult = new DefaultDOMRpcResult((NormalizedNode<?, ?>)null);
355         doReturn(Futures.immediateCheckedFuture(expResult)).when(brokerFacade).invokeRpc(any(SchemaPath.class),
356                 any(NormalizedNode.class));
357
358         String uriPath = "toaster:cancel-toast";
359
360         Optional<String> output = service.invokeRpc(uriPath, Optional.<String>absent());
361
362         assertEquals("Output present", false, output.isPresent());
363
364         verify(brokerFacade).invokeRpc(eq(path), isNull(NormalizedNode.class));
365     }
366
367     @Test
368     public void testInvokeRpcWithOutput() throws Exception {
369         SchemaPath path = SchemaPath.create(true, TEST_OUTPUT_QNAME);
370
371         NormalizedNode<?, ?> outputNode = ImmutableContainerNodeBuilder.create()
372                 .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TEST_OUTPUT_QNAME))
373                 .withChild(ImmutableNodes.leafNode(TEXT_OUT_QNAME, "foo")).build();
374         DOMRpcResult expResult = new DefaultDOMRpcResult(outputNode);
375         doReturn(Futures.immediateCheckedFuture(expResult)).when(brokerFacade).invokeRpc(any(SchemaPath.class),
376                 any(NormalizedNode.class));
377
378         String uriPath = "toaster:testOutput";
379
380         Optional<String> output = service.invokeRpc(uriPath, Optional.<String>absent());
381
382         assertEquals("Output present", true, output.isPresent());
383         assertNotNull("Returned null response", output.get());
384         assertThat("Missing \"textOut\"", output.get(), containsString("\"textOut\":\"foo\""));
385
386         verify(brokerFacade).invokeRpc(eq(path), isNull(NormalizedNode.class));
387     }
388
389     @Test(expected=OperationFailedException.class)
390     public void testInvokeRpcFailure() throws Exception {
391         DOMRpcException exception = new DOMRpcImplementationNotAvailableException("testExeption");
392         doReturn(Futures.immediateFailedCheckedFuture(exception)).when(brokerFacade).invokeRpc(any(SchemaPath.class),
393                 any(NormalizedNode.class));
394
395         String uriPath = "toaster:cancel-toast";
396
397         service.invokeRpc(uriPath, Optional.<String>absent());
398     }
399
400     void testGet(final LogicalDatastoreType datastoreType) throws OperationFailedException {
401         MapEntryNode entryNode = ImmutableNodes.mapEntryBuilder(INTERFACE_QNAME, NAME_QNAME, "eth0")
402                 .withChild(ImmutableNodes.leafNode(NAME_QNAME, "eth0"))
403                 .withChild(ImmutableNodes.leafNode(TYPE_QNAME, "ethernetCsmacd"))
404                 .withChild(ImmutableNodes.leafNode(ENABLED_QNAME, Boolean.TRUE))
405                 .withChild(ImmutableNodes.leafNode(DESC_QNAME, "eth interface"))
406                 .build();
407
408         if(datastoreType == LogicalDatastoreType.CONFIGURATION) {
409             doReturn(entryNode).when(brokerFacade).readConfigurationData(notNull(YangInstanceIdentifier.class));
410         } else {
411             doReturn(entryNode).when(brokerFacade).readOperationalData(notNull(YangInstanceIdentifier.class));
412         }
413
414         String uriPath = "/ietf-interfaces:interfaces/interface/eth0";
415
416         Optional<String> optionalResp = service.get(uriPath, datastoreType);
417         assertEquals("Response present", true, optionalResp.isPresent());
418         String jsonResp = optionalResp.get();
419
420         assertNotNull("Returned null response", jsonResp);
421         assertThat("Missing \"name\"", jsonResp, containsString("\"name\":\"eth0\""));
422         assertThat("Missing \"type\"", jsonResp, containsString("\"type\":\"ethernetCsmacd\""));
423         assertThat("Missing \"enabled\"", jsonResp, containsString("\"enabled\":true"));
424         assertThat("Missing \"description\"", jsonResp, containsString("\"description\":\"eth interface\""));
425
426         ArgumentCaptor<YangInstanceIdentifier> capturedPath = ArgumentCaptor.forClass(YangInstanceIdentifier.class);
427         if (datastoreType == LogicalDatastoreType.CONFIGURATION) {
428             verify(brokerFacade).readConfigurationData(capturedPath.capture());
429         } else {
430             verify(brokerFacade).readOperationalData(capturedPath.capture());
431         }
432
433         verifyPath(capturedPath.getValue(), INTERFACES_QNAME, INTERFACE_QNAME,
434                 new Object[]{INTERFACE_QNAME, NAME_QNAME, "eth0"});
435     }
436
437     DOMMountPoint setupTestMountPoint() throws FileNotFoundException {
438         SchemaContext schemaContextTestModule = TestUtils.loadSchemaContext("/full-versions/test-module");
439         DOMMountPoint mockMountPoint = mock(DOMMountPoint.class);
440         doReturn(schemaContextTestModule).when(mockMountPoint).getSchemaContext();
441
442         DOMMountPointService mockMountService = mock(DOMMountPointService.class);
443         doReturn(Optional.of(mockMountPoint)).when(mockMountService).getMountPoint(notNull(YangInstanceIdentifier.class));
444
445         ControllerContext.getInstance().setMountService(mockMountService);
446         return mockMountPoint;
447     }
448
449     void verifyLeafNode(final DataContainerNode<?> parent, final QName leafType, final Object leafValue) {
450         Optional<DataContainerChild<?, ?>> leafChild = parent.getChild(new NodeIdentifier(leafType));
451         assertEquals(leafType.toString() + " present", true, leafChild.isPresent());
452         assertEquals(leafType.toString() + " value", leafValue, leafChild.get().getValue());
453     }
454
455     void verifyPath(final YangInstanceIdentifier path, final Object... expArgs) {
456         List<PathArgument> pathArgs = path.getPathArguments();
457         assertEquals("Arg count for actual path " + path, expArgs.length, pathArgs.size());
458         int i = 0;
459         for(PathArgument actual: pathArgs) {
460             QName expNodeType;
461             if(expArgs[i] instanceof Object[]) {
462                 Object[] listEntry = (Object[]) expArgs[i];
463                 expNodeType = (QName) listEntry[0];
464
465                 assertTrue(actual instanceof NodeIdentifierWithPredicates);
466                 Map<QName, Object> keyValues = ((NodeIdentifierWithPredicates)actual).getKeyValues();
467                 assertEquals(String.format("Path arg %d keyValues size", i + 1), 1, keyValues.size());
468                 QName expKey = (QName) listEntry[1];
469                 assertEquals(String.format("Path arg %d keyValue for %s", i + 1, expKey), listEntry[2],
470                         keyValues.get(expKey));
471             } else {
472                 expNodeType = (QName) expArgs[i];
473             }
474
475             assertEquals(String.format("Path arg %d node type", i + 1), expNodeType, actual.getNodeType());
476             i++;
477         }
478
479     }
480 }