2 * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.sal.restconf.impl.test;
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;
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 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
67 * Unit tests for JSONRestconfServiceImpl.
69 * @author Thomas Pantelis
71 public class JSONRestconfServiceImplTest {
72 static final String IETF_INTERFACES_NS = "urn:ietf:params:xml:ns:yang:ietf-interfaces";
73 static final String IETF_INTERFACES_VERSION = "2013-07-04";
74 static final QName INTERFACES_QNAME = QName.create(IETF_INTERFACES_NS, IETF_INTERFACES_VERSION, "interfaces");
75 static final QName INTERFACE_QNAME = QName.create(IETF_INTERFACES_NS, IETF_INTERFACES_VERSION, "interface");
76 static final QName NAME_QNAME = QName.create(IETF_INTERFACES_NS, IETF_INTERFACES_VERSION, "name");
77 static final QName TYPE_QNAME = QName.create(IETF_INTERFACES_NS, IETF_INTERFACES_VERSION, "type");
78 static final QName ENABLED_QNAME = QName.create(IETF_INTERFACES_NS, IETF_INTERFACES_VERSION, "enabled");
79 static final QName DESC_QNAME = QName.create(IETF_INTERFACES_NS, IETF_INTERFACES_VERSION, "description");
81 static final String TEST_MODULE_NS = "test:module";
82 static final String TEST_MODULE_VERSION = "2014-01-09";
83 static final QName TEST_CONT_QNAME = QName.create(TEST_MODULE_NS, TEST_MODULE_VERSION, "cont");
84 static final QName TEST_CONT1_QNAME = QName.create(TEST_MODULE_NS, TEST_MODULE_VERSION, "cont1");
85 static final QName TEST_LF11_QNAME = QName.create(TEST_MODULE_NS, TEST_MODULE_VERSION, "lf11");
86 static final QName TEST_LF12_QNAME = QName.create(TEST_MODULE_NS, TEST_MODULE_VERSION, "lf12");
88 static final String TOASTER_MODULE_NS = "http://netconfcentral.org/ns/toaster";
89 static final String TOASTER_MODULE_VERSION = "2009-11-20";
90 static final QName TOASTER_DONENESS_QNAME = QName.create(TOASTER_MODULE_NS, TOASTER_MODULE_VERSION, "toasterDoneness");
91 static final QName TOASTER_TYPE_QNAME = QName.create(TOASTER_MODULE_NS, TOASTER_MODULE_VERSION, "toasterToastType");
92 static final QName WHEAT_BREAD_QNAME = QName.create(TOASTER_MODULE_NS, TOASTER_MODULE_VERSION, "wheat-bread");
93 static final QName MAKE_TOAST_QNAME = QName.create(TOASTER_MODULE_NS, TOASTER_MODULE_VERSION, "make-toast");
94 static final QName CANCEL_TOAST_QNAME = QName.create(TOASTER_MODULE_NS, TOASTER_MODULE_VERSION, "cancel-toast");
95 static final QName TEST_OUTPUT_QNAME = QName.create(TOASTER_MODULE_NS, TOASTER_MODULE_VERSION, "testOutput");
96 static final QName TEXT_OUT_QNAME = QName.create(TOASTER_MODULE_NS, TOASTER_MODULE_VERSION, "textOut");
98 private static BrokerFacade brokerFacade;
100 private final JSONRestconfServiceImpl service = new JSONRestconfServiceImpl();
103 public static void init() throws IOException, ReactorException {
104 ControllerContext.getInstance().setSchemas(TestUtils.loadSchemaContext("/full-versions/yangs"));
105 brokerFacade = mock(BrokerFacade.class);
106 RestconfImpl.getInstance().setBroker(brokerFacade);
107 RestconfImpl.getInstance().setControllerContext(ControllerContext.getInstance());
111 public void setup() {
115 private static String loadData(final String path) throws IOException {
116 return Resources.asCharSource(JSONRestconfServiceImplTest.class.getResource(path), StandardCharsets.UTF_8).read();
119 @SuppressWarnings("rawtypes")
121 public void testPut() throws Exception {
122 doReturn(Futures.immediateCheckedFuture(null)).when(brokerFacade).commitConfigurationDataPut(
123 notNull(SchemaContext.class), notNull(YangInstanceIdentifier.class), notNull(NormalizedNode.class));
125 final String uriPath = "ietf-interfaces:interfaces/interface/eth0";
126 final String payload = loadData("/parts/ietf-interfaces_interfaces.json");
128 this.service.put(uriPath, payload);
130 final ArgumentCaptor<YangInstanceIdentifier> capturedPath = ArgumentCaptor.forClass(YangInstanceIdentifier.class);
131 final ArgumentCaptor<NormalizedNode> capturedNode = ArgumentCaptor.forClass(NormalizedNode.class);
132 verify(brokerFacade).commitConfigurationDataPut(notNull(SchemaContext.class), capturedPath.capture(),
133 capturedNode.capture());
135 verifyPath(capturedPath.getValue(), INTERFACES_QNAME, INTERFACE_QNAME,
136 new Object[]{INTERFACE_QNAME, NAME_QNAME, "eth0"});
138 assertTrue("Expected MapEntryNode. Actual " + capturedNode.getValue().getClass(),
139 capturedNode.getValue() instanceof MapEntryNode);
140 final MapEntryNode actualNode = (MapEntryNode) capturedNode.getValue();
141 assertEquals("MapEntryNode node type", INTERFACE_QNAME, actualNode.getNodeType());
142 verifyLeafNode(actualNode, NAME_QNAME, "eth0");
143 verifyLeafNode(actualNode, TYPE_QNAME, "ethernetCsmacd");
144 verifyLeafNode(actualNode, ENABLED_QNAME, Boolean.FALSE);
145 verifyLeafNode(actualNode, DESC_QNAME, "some interface");
148 @SuppressWarnings("rawtypes")
150 public void testPutBehindMountPoint() throws Exception {
151 final DOMMountPoint mockMountPoint = setupTestMountPoint();
153 doReturn(Futures.immediateCheckedFuture(null)).when(brokerFacade).commitConfigurationDataPut(
154 notNull(DOMMountPoint.class), notNull(YangInstanceIdentifier.class), notNull(NormalizedNode.class));
156 final String uriPath = "ietf-interfaces:interfaces/yang-ext:mount/test-module:cont/cont1";
157 final String payload = loadData("/full-versions/testCont1Data.json");
159 this.service.put(uriPath, payload);
161 final ArgumentCaptor<YangInstanceIdentifier> capturedPath = ArgumentCaptor.forClass(YangInstanceIdentifier.class);
162 final ArgumentCaptor<NormalizedNode> capturedNode = ArgumentCaptor.forClass(NormalizedNode.class);
163 verify(brokerFacade).commitConfigurationDataPut(same(mockMountPoint), capturedPath.capture(),
164 capturedNode.capture());
166 verifyPath(capturedPath.getValue(), TEST_CONT_QNAME, TEST_CONT1_QNAME);
168 assertTrue("Expected ContainerNode", capturedNode.getValue() instanceof ContainerNode);
169 final ContainerNode actualNode = (ContainerNode) capturedNode.getValue();
170 assertEquals("ContainerNode node type", TEST_CONT1_QNAME, actualNode.getNodeType());
171 verifyLeafNode(actualNode, TEST_LF11_QNAME, "lf11 data");
172 verifyLeafNode(actualNode, TEST_LF12_QNAME, "lf12 data");
175 @Test(expected=TransactionCommitFailedException.class)
176 public void testPutFailure() throws Throwable {
177 doReturn(Futures.immediateFailedCheckedFuture(new TransactionCommitFailedException("mock")))
178 .when(brokerFacade).commitConfigurationDataPut(notNull(SchemaContext.class),
179 notNull(YangInstanceIdentifier.class), notNull(NormalizedNode.class));
181 final String uriPath = "ietf-interfaces:interfaces/interface/eth0";
182 final String payload = loadData("/parts/ietf-interfaces_interfaces.json");
185 this.service.put(uriPath, payload);
186 } catch (final OperationFailedException e) {
187 assertNotNull(e.getCause());
192 @SuppressWarnings("rawtypes")
194 public void testPost() throws Exception {
195 doReturn(Futures.immediateCheckedFuture(null)).when(brokerFacade).commitConfigurationDataPost(
196 any(SchemaContext.class), any(YangInstanceIdentifier.class), any(NormalizedNode.class));
198 final String uriPath = null;
199 final String payload = loadData("/parts/ietf-interfaces_interfaces_absolute_path.json");
201 this.service.post(uriPath, payload);
203 final ArgumentCaptor<YangInstanceIdentifier> capturedPath = ArgumentCaptor.forClass(YangInstanceIdentifier.class);
204 final ArgumentCaptor<NormalizedNode> capturedNode = ArgumentCaptor.forClass(NormalizedNode.class);
205 verify(brokerFacade).commitConfigurationDataPost(notNull(SchemaContext.class), capturedPath.capture(),
206 capturedNode.capture());
208 verifyPath(capturedPath.getValue(), INTERFACES_QNAME);
210 assertTrue("Expected ContainerNode", capturedNode.getValue() instanceof ContainerNode);
211 final ContainerNode actualNode = (ContainerNode) capturedNode.getValue();
212 assertEquals("ContainerNode node type", INTERFACES_QNAME, actualNode.getNodeType());
214 final Optional<DataContainerChild<?, ?>> mapChild = actualNode.getChild(new NodeIdentifier(INTERFACE_QNAME));
215 assertEquals(INTERFACE_QNAME.toString() + " present", true, mapChild.isPresent());
216 assertTrue("Expected MapNode. Actual " + mapChild.get().getClass(), mapChild.get() instanceof MapNode);
217 final MapNode mapNode = (MapNode)mapChild.get();
219 final NodeIdentifierWithPredicates entryNodeID = new NodeIdentifierWithPredicates(
220 INTERFACE_QNAME, NAME_QNAME, "eth0");
221 final Optional<MapEntryNode> entryChild = mapNode.getChild(entryNodeID);
222 assertEquals(entryNodeID.toString() + " present", true, entryChild.isPresent());
223 final MapEntryNode entryNode = entryChild.get();
224 verifyLeafNode(entryNode, NAME_QNAME, "eth0");
225 verifyLeafNode(entryNode, TYPE_QNAME, "ethernetCsmacd");
226 verifyLeafNode(entryNode, ENABLED_QNAME, Boolean.FALSE);
227 verifyLeafNode(entryNode, DESC_QNAME, "some interface");
230 @SuppressWarnings("rawtypes")
232 public void testPostBehindMountPoint() throws Exception {
233 final DOMMountPoint mockMountPoint = setupTestMountPoint();
235 doReturn(Futures.immediateCheckedFuture(null)).when(brokerFacade).commitConfigurationDataPost(
236 notNull(DOMMountPoint.class), notNull(YangInstanceIdentifier.class), notNull(NormalizedNode.class));
238 final String uriPath = "ietf-interfaces:interfaces/yang-ext:mount/test-module:cont";
239 final String payload = loadData("/full-versions/testCont1Data.json");
241 this.service.post(uriPath, payload);
243 final ArgumentCaptor<YangInstanceIdentifier> capturedPath = ArgumentCaptor.forClass(YangInstanceIdentifier.class);
244 final ArgumentCaptor<NormalizedNode> capturedNode = ArgumentCaptor.forClass(NormalizedNode.class);
245 verify(brokerFacade).commitConfigurationDataPost(same(mockMountPoint), capturedPath.capture(),
246 capturedNode.capture());
248 verifyPath(capturedPath.getValue(), TEST_CONT_QNAME, TEST_CONT1_QNAME);
250 assertTrue("Expected ContainerNode", capturedNode.getValue() instanceof ContainerNode);
251 final ContainerNode actualNode = (ContainerNode) capturedNode.getValue();
252 assertEquals("ContainerNode node type", TEST_CONT1_QNAME, actualNode.getNodeType());
253 verifyLeafNode(actualNode, TEST_LF11_QNAME, "lf11 data");
254 verifyLeafNode(actualNode, TEST_LF12_QNAME, "lf12 data");
257 @Test(expected=TransactionCommitFailedException.class)
258 public void testPostFailure() throws Throwable {
259 doReturn(Futures.immediateFailedCheckedFuture(new TransactionCommitFailedException("mock")))
260 .when(brokerFacade).commitConfigurationDataPost(any(SchemaContext.class),
261 any(YangInstanceIdentifier.class), any(NormalizedNode.class));
263 final String uriPath = null;
264 final String payload = loadData("/parts/ietf-interfaces_interfaces_absolute_path.json");
267 this.service.post(uriPath, payload);
268 } catch (final OperationFailedException e) {
269 assertNotNull(e.getCause());
275 public void testDelete() throws Exception {
276 doReturn(Futures.immediateCheckedFuture(null)).when(brokerFacade).commitConfigurationDataDelete(
277 notNull(YangInstanceIdentifier.class));
279 final String uriPath = "ietf-interfaces:interfaces/interface/eth0";
281 this.service.delete(uriPath);
283 final ArgumentCaptor<YangInstanceIdentifier> capturedPath = ArgumentCaptor.forClass(YangInstanceIdentifier.class);
284 verify(brokerFacade).commitConfigurationDataDelete(capturedPath.capture());
286 verifyPath(capturedPath.getValue(), INTERFACES_QNAME, INTERFACE_QNAME,
287 new Object[]{INTERFACE_QNAME, NAME_QNAME, "eth0"});
290 @Test(expected=OperationFailedException.class)
291 public void testDeleteFailure() throws Exception {
292 final String invalidUriPath = "ietf-interfaces:interfaces/invalid";
294 this.service.delete(invalidUriPath);
298 public void testGetConfig() throws Exception {
299 testGet(LogicalDatastoreType.CONFIGURATION);
303 public void testGetOperational() throws Exception {
304 testGet(LogicalDatastoreType.OPERATIONAL);
308 public void testGetWithNoData() throws Exception {
309 doReturn(null).when(brokerFacade).readConfigurationData(notNull(YangInstanceIdentifier.class));
311 final String uriPath = "ietf-interfaces:interfaces";
313 final Optional<String> optionalResp = this.service.get(uriPath, LogicalDatastoreType.CONFIGURATION);
315 assertEquals("Response present", false, optionalResp.isPresent());
318 @Test(expected=OperationFailedException.class)
319 public void testGetFailure() throws Exception {
320 final String invalidUriPath = "/ietf-interfaces:interfaces/invalid";
322 this.service.get(invalidUriPath, LogicalDatastoreType.CONFIGURATION);
325 @SuppressWarnings("rawtypes")
327 public void testInvokeRpcWithInput() throws Exception {
328 final SchemaPath path = SchemaPath.create(true, MAKE_TOAST_QNAME);
330 final DOMRpcResult expResult = new DefaultDOMRpcResult((NormalizedNode<?, ?>)null);
331 doReturn(Futures.immediateCheckedFuture(expResult)).when(brokerFacade).invokeRpc(eq(path),
332 any(NormalizedNode.class));
334 final String uriPath = "toaster:make-toast";
335 final String input = loadData("/full-versions/make-toast-rpc-input.json");
337 final Optional<String> output = this.service.invokeRpc(uriPath, Optional.of(input));
339 assertEquals("Output present", false, output.isPresent());
341 final ArgumentCaptor<NormalizedNode> capturedNode = ArgumentCaptor.forClass(NormalizedNode.class);
342 verify(brokerFacade).invokeRpc(eq(path), capturedNode.capture());
344 assertTrue("Expected ContainerNode. Actual " + capturedNode.getValue().getClass(),
345 capturedNode.getValue() instanceof ContainerNode);
346 final ContainerNode actualNode = (ContainerNode) capturedNode.getValue();
347 verifyLeafNode(actualNode, TOASTER_DONENESS_QNAME, Long.valueOf(10));
348 verifyLeafNode(actualNode, TOASTER_TYPE_QNAME, WHEAT_BREAD_QNAME);
352 public void testInvokeRpcWithNoInput() throws Exception {
353 final SchemaPath path = SchemaPath.create(true, CANCEL_TOAST_QNAME);
355 final DOMRpcResult expResult = new DefaultDOMRpcResult((NormalizedNode<?, ?>)null);
356 doReturn(Futures.immediateCheckedFuture(expResult)).when(brokerFacade).invokeRpc(any(SchemaPath.class),
357 any(NormalizedNode.class));
359 final String uriPath = "toaster:cancel-toast";
361 final Optional<String> output = this.service.invokeRpc(uriPath, Optional.<String>absent());
363 assertEquals("Output present", false, output.isPresent());
365 verify(brokerFacade).invokeRpc(eq(path), isNull(NormalizedNode.class));
369 public void testInvokeRpcWithOutput() throws Exception {
370 final SchemaPath path = SchemaPath.create(true, TEST_OUTPUT_QNAME);
372 final NormalizedNode<?, ?> outputNode = ImmutableContainerNodeBuilder.create()
373 .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TEST_OUTPUT_QNAME))
374 .withChild(ImmutableNodes.leafNode(TEXT_OUT_QNAME, "foo")).build();
375 final DOMRpcResult expResult = new DefaultDOMRpcResult(outputNode);
376 doReturn(Futures.immediateCheckedFuture(expResult)).when(brokerFacade).invokeRpc(any(SchemaPath.class),
377 any(NormalizedNode.class));
379 final String uriPath = "toaster:testOutput";
381 final Optional<String> output = this.service.invokeRpc(uriPath, Optional.<String>absent());
383 assertEquals("Output present", true, output.isPresent());
384 assertNotNull("Returned null response", output.get());
385 assertThat("Missing \"textOut\"", output.get(), containsString("\"textOut\":\"foo\""));
387 verify(brokerFacade).invokeRpc(eq(path), isNull(NormalizedNode.class));
390 @Test(expected=OperationFailedException.class)
391 public void testInvokeRpcFailure() throws Exception {
392 final DOMRpcException exception = new DOMRpcImplementationNotAvailableException("testExeption");
393 doReturn(Futures.immediateFailedCheckedFuture(exception)).when(brokerFacade).invokeRpc(any(SchemaPath.class),
394 any(NormalizedNode.class));
396 final String uriPath = "toaster:cancel-toast";
398 this.service.invokeRpc(uriPath, Optional.<String>absent());
401 void testGet(final LogicalDatastoreType datastoreType) throws OperationFailedException {
402 final MapEntryNode entryNode = ImmutableNodes.mapEntryBuilder(INTERFACE_QNAME, NAME_QNAME, "eth0")
403 .withChild(ImmutableNodes.leafNode(NAME_QNAME, "eth0"))
404 .withChild(ImmutableNodes.leafNode(TYPE_QNAME, "ethernetCsmacd"))
405 .withChild(ImmutableNodes.leafNode(ENABLED_QNAME, Boolean.TRUE))
406 .withChild(ImmutableNodes.leafNode(DESC_QNAME, "eth interface"))
409 if(datastoreType == LogicalDatastoreType.CONFIGURATION) {
410 doReturn(entryNode).when(brokerFacade).readConfigurationData(notNull(YangInstanceIdentifier.class));
412 doReturn(entryNode).when(brokerFacade).readOperationalData(notNull(YangInstanceIdentifier.class));
415 final String uriPath = "/ietf-interfaces:interfaces/interface/eth0";
417 final Optional<String> optionalResp = this.service.get(uriPath, datastoreType);
418 assertEquals("Response present", true, optionalResp.isPresent());
419 final String jsonResp = optionalResp.get();
421 assertNotNull("Returned null response", jsonResp);
422 assertThat("Missing \"name\"", jsonResp, containsString("\"name\":\"eth0\""));
423 assertThat("Missing \"type\"", jsonResp, containsString("\"type\":\"ethernetCsmacd\""));
424 assertThat("Missing \"enabled\"", jsonResp, containsString("\"enabled\":true"));
425 assertThat("Missing \"description\"", jsonResp, containsString("\"description\":\"eth interface\""));
427 final ArgumentCaptor<YangInstanceIdentifier> capturedPath = ArgumentCaptor.forClass(YangInstanceIdentifier.class);
428 if (datastoreType == LogicalDatastoreType.CONFIGURATION) {
429 verify(brokerFacade).readConfigurationData(capturedPath.capture());
431 verify(brokerFacade).readOperationalData(capturedPath.capture());
434 verifyPath(capturedPath.getValue(), INTERFACES_QNAME, INTERFACE_QNAME,
435 new Object[]{INTERFACE_QNAME, NAME_QNAME, "eth0"});
438 DOMMountPoint setupTestMountPoint() throws FileNotFoundException, ReactorException {
439 final SchemaContext schemaContextTestModule = TestUtils.loadSchemaContext("/full-versions/test-module");
440 final DOMMountPoint mockMountPoint = mock(DOMMountPoint.class);
441 doReturn(schemaContextTestModule).when(mockMountPoint).getSchemaContext();
443 final DOMMountPointService mockMountService = mock(DOMMountPointService.class);
444 doReturn(Optional.of(mockMountPoint)).when(mockMountService).getMountPoint(notNull(YangInstanceIdentifier.class));
446 ControllerContext.getInstance().setMountService(mockMountService);
447 return mockMountPoint;
450 void verifyLeafNode(final DataContainerNode<?> parent, final QName leafType, final Object leafValue) {
451 final Optional<DataContainerChild<?, ?>> leafChild = parent.getChild(new NodeIdentifier(leafType));
452 assertEquals(leafType.toString() + " present", true, leafChild.isPresent());
453 assertEquals(leafType.toString() + " value", leafValue, leafChild.get().getValue());
456 void verifyPath(final YangInstanceIdentifier path, final Object... expArgs) {
457 final List<PathArgument> pathArgs = path.getPathArguments();
458 assertEquals("Arg count for actual path " + path, expArgs.length, pathArgs.size());
460 for(final PathArgument actual: pathArgs) {
462 if(expArgs[i] instanceof Object[]) {
463 final Object[] listEntry = (Object[]) expArgs[i];
464 expNodeType = (QName) listEntry[0];
466 assertTrue(actual instanceof NodeIdentifierWithPredicates);
467 final Map<QName, Object> keyValues = ((NodeIdentifierWithPredicates)actual).getKeyValues();
468 assertEquals(String.format("Path arg %d keyValues size", i + 1), 1, keyValues.size());
469 final QName expKey = (QName) listEntry[1];
470 assertEquals(String.format("Path arg %d keyValue for %s", i + 1, expKey), listEntry[2],
471 keyValues.get(expKey));
473 expNodeType = (QName) expArgs[i];
476 assertEquals(String.format("Path arg %d node type", i + 1), expNodeType, actual.getNodeType());