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;
66 * Unit tests for JSONRestconfServiceImpl.
68 * @author Thomas Pantelis
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");
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");
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");
97 private static BrokerFacade brokerFacade;
99 private final JSONRestconfServiceImpl service = new JSONRestconfServiceImpl();
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());
110 public void setup() {
114 private static String loadData(final String path) throws IOException {
115 return Resources.asCharSource(JSONRestconfServiceImplTest.class.getResource(path), StandardCharsets.UTF_8).read();
118 @SuppressWarnings("rawtypes")
120 public void testPut() throws Exception {
121 doReturn(Futures.immediateCheckedFuture(null)).when(brokerFacade).commitConfigurationDataPut(
122 notNull(SchemaContext.class), notNull(YangInstanceIdentifier.class), notNull(NormalizedNode.class));
124 String uriPath = "ietf-interfaces:interfaces/interface/eth0";
125 String payload = loadData("/parts/ietf-interfaces_interfaces.json");
127 service.put(uriPath, payload);
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());
134 verifyPath(capturedPath.getValue(), INTERFACES_QNAME, INTERFACE_QNAME,
135 new Object[]{INTERFACE_QNAME, NAME_QNAME, "eth0"});
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");
147 @SuppressWarnings("rawtypes")
149 public void testPutBehindMountPoint() throws Exception {
150 DOMMountPoint mockMountPoint = setupTestMountPoint();
152 doReturn(Futures.immediateCheckedFuture(null)).when(brokerFacade).commitConfigurationDataPut(
153 notNull(DOMMountPoint.class), notNull(YangInstanceIdentifier.class), notNull(NormalizedNode.class));
155 String uriPath = "ietf-interfaces:interfaces/yang-ext:mount/test-module:cont/cont1";
156 String payload = loadData("/full-versions/testCont1Data.json");
158 service.put(uriPath, payload);
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());
165 verifyPath(capturedPath.getValue(), TEST_CONT_QNAME, TEST_CONT1_QNAME);
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");
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));
180 String uriPath = "ietf-interfaces:interfaces/interface/eth0";
181 String payload = loadData("/parts/ietf-interfaces_interfaces.json");
184 service.put(uriPath, payload);
185 } catch (OperationFailedException e) {
186 assertNotNull(e.getCause());
191 @SuppressWarnings("rawtypes")
193 public void testPost() throws Exception {
194 doReturn(Futures.immediateCheckedFuture(null)).when(brokerFacade).commitConfigurationDataPost(
195 any(SchemaContext.class), any(YangInstanceIdentifier.class), any(NormalizedNode.class));
197 String uriPath = null;
198 String payload = loadData("/parts/ietf-interfaces_interfaces_absolute_path.json");
200 service.post(uriPath, payload);
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());
207 verifyPath(capturedPath.getValue(), INTERFACES_QNAME);
209 assertTrue("Expected ContainerNode", capturedNode.getValue() instanceof ContainerNode);
210 ContainerNode actualNode = (ContainerNode) capturedNode.getValue();
211 assertEquals("ContainerNode node type", INTERFACES_QNAME, actualNode.getNodeType());
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();
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");
229 @SuppressWarnings("rawtypes")
231 public void testPostBehindMountPoint() throws Exception {
232 DOMMountPoint mockMountPoint = setupTestMountPoint();
234 doReturn(Futures.immediateCheckedFuture(null)).when(brokerFacade).commitConfigurationDataPost(
235 notNull(DOMMountPoint.class), notNull(YangInstanceIdentifier.class), notNull(NormalizedNode.class));
237 String uriPath = "ietf-interfaces:interfaces/yang-ext:mount/test-module:cont";
238 String payload = loadData("/full-versions/testCont1Data.json");
240 service.post(uriPath, payload);
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());
247 verifyPath(capturedPath.getValue(), TEST_CONT_QNAME, TEST_CONT1_QNAME);
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");
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));
262 String uriPath = null;
263 String payload = loadData("/parts/ietf-interfaces_interfaces_absolute_path.json");
266 service.post(uriPath, payload);
267 } catch (OperationFailedException e) {
268 assertNotNull(e.getCause());
274 public void testDelete() throws Exception {
275 doReturn(Futures.immediateCheckedFuture(null)).when(brokerFacade).commitConfigurationDataDelete(
276 notNull(YangInstanceIdentifier.class));
278 String uriPath = "ietf-interfaces:interfaces/interface/eth0";
280 service.delete(uriPath);
282 ArgumentCaptor<YangInstanceIdentifier> capturedPath = ArgumentCaptor.forClass(YangInstanceIdentifier.class);
283 verify(brokerFacade).commitConfigurationDataDelete(capturedPath.capture());
285 verifyPath(capturedPath.getValue(), INTERFACES_QNAME, INTERFACE_QNAME,
286 new Object[]{INTERFACE_QNAME, NAME_QNAME, "eth0"});
289 @Test(expected=OperationFailedException.class)
290 public void testDeleteFailure() throws Exception {
291 String invalidUriPath = "ietf-interfaces:interfaces/invalid";
293 service.delete(invalidUriPath);
297 public void testGetConfig() throws Exception {
298 testGet(LogicalDatastoreType.CONFIGURATION);
302 public void testGetOperational() throws Exception {
303 testGet(LogicalDatastoreType.OPERATIONAL);
307 public void testGetWithNoData() throws Exception {
308 doReturn(null).when(brokerFacade).readConfigurationData(notNull(YangInstanceIdentifier.class));
310 String uriPath = "ietf-interfaces:interfaces";
312 Optional<String> optionalResp = service.get(uriPath, LogicalDatastoreType.CONFIGURATION);
314 assertEquals("Response present", false, optionalResp.isPresent());
317 @Test(expected=OperationFailedException.class)
318 public void testGetFailure() throws Exception {
319 String invalidUriPath = "/ietf-interfaces:interfaces/invalid";
321 service.get(invalidUriPath, LogicalDatastoreType.CONFIGURATION);
324 @SuppressWarnings("rawtypes")
326 public void testInvokeRpcWithInput() throws Exception {
327 SchemaPath path = SchemaPath.create(true, MAKE_TOAST_QNAME);
329 DOMRpcResult expResult = new DefaultDOMRpcResult((NormalizedNode<?, ?>)null);
330 doReturn(Futures.immediateCheckedFuture(expResult)).when(brokerFacade).invokeRpc(eq(path),
331 any(NormalizedNode.class));
333 String uriPath = "toaster:make-toast";
334 String input = loadData("/full-versions/make-toast-rpc-input.json");
336 Optional<String> output = service.invokeRpc(uriPath, Optional.of(input));
338 assertEquals("Output present", false, output.isPresent());
340 ArgumentCaptor<NormalizedNode> capturedNode = ArgumentCaptor.forClass(NormalizedNode.class);
341 verify(brokerFacade).invokeRpc(eq(path), capturedNode.capture());
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);
351 public void testInvokeRpcWithNoInput() throws Exception {
352 SchemaPath path = SchemaPath.create(true, CANCEL_TOAST_QNAME);
354 DOMRpcResult expResult = new DefaultDOMRpcResult((NormalizedNode<?, ?>)null);
355 doReturn(Futures.immediateCheckedFuture(expResult)).when(brokerFacade).invokeRpc(any(SchemaPath.class),
356 any(NormalizedNode.class));
358 String uriPath = "toaster:cancel-toast";
360 Optional<String> output = service.invokeRpc(uriPath, Optional.<String>absent());
362 assertEquals("Output present", false, output.isPresent());
364 verify(brokerFacade).invokeRpc(eq(path), isNull(NormalizedNode.class));
368 public void testInvokeRpcWithOutput() throws Exception {
369 SchemaPath path = SchemaPath.create(true, TEST_OUTPUT_QNAME);
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));
378 String uriPath = "toaster:testOutput";
380 Optional<String> output = service.invokeRpc(uriPath, Optional.<String>absent());
382 assertEquals("Output present", true, output.isPresent());
383 assertNotNull("Returned null response", output.get());
384 assertThat("Missing \"textOut\"", output.get(), containsString("\"textOut\":\"foo\""));
386 verify(brokerFacade).invokeRpc(eq(path), isNull(NormalizedNode.class));
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));
395 String uriPath = "toaster:cancel-toast";
397 service.invokeRpc(uriPath, Optional.<String>absent());
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"))
408 if(datastoreType == LogicalDatastoreType.CONFIGURATION) {
409 doReturn(entryNode).when(brokerFacade).readConfigurationData(notNull(YangInstanceIdentifier.class));
411 doReturn(entryNode).when(brokerFacade).readOperationalData(notNull(YangInstanceIdentifier.class));
414 String uriPath = "/ietf-interfaces:interfaces/interface/eth0";
416 Optional<String> optionalResp = service.get(uriPath, datastoreType);
417 assertEquals("Response present", true, optionalResp.isPresent());
418 String jsonResp = optionalResp.get();
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\""));
426 ArgumentCaptor<YangInstanceIdentifier> capturedPath = ArgumentCaptor.forClass(YangInstanceIdentifier.class);
427 if (datastoreType == LogicalDatastoreType.CONFIGURATION) {
428 verify(brokerFacade).readConfigurationData(capturedPath.capture());
430 verify(brokerFacade).readOperationalData(capturedPath.capture());
433 verifyPath(capturedPath.getValue(), INTERFACES_QNAME, INTERFACE_QNAME,
434 new Object[]{INTERFACE_QNAME, NAME_QNAME, "eth0"});
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();
442 DOMMountPointService mockMountService = mock(DOMMountPointService.class);
443 doReturn(Optional.of(mockMountPoint)).when(mockMountService).getMountPoint(notNull(YangInstanceIdentifier.class));
445 ControllerContext.getInstance().setMountService(mockMountService);
446 return mockMountPoint;
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());
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());
459 for(PathArgument actual: pathArgs) {
461 if(expArgs[i] instanceof Object[]) {
462 Object[] listEntry = (Object[]) expArgs[i];
463 expNodeType = (QName) listEntry[0];
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));
472 expNodeType = (QName) expArgs[i];
475 assertEquals(String.format("Path arg %d node type", i + 1), expNodeType, actual.getNodeType());