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 static org.mockito.Mockito.when;
25 import com.google.common.base.Optional;
26 import com.google.common.io.Resources;
27 import com.google.common.util.concurrent.Futures;
28 import java.io.FileNotFoundException;
29 import java.io.IOException;
30 import java.nio.charset.StandardCharsets;
31 import java.util.List;
33 import javax.ws.rs.core.Response.Status;
34 import org.junit.Before;
35 import org.junit.BeforeClass;
36 import org.junit.Test;
37 import org.mockito.ArgumentCaptor;
38 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
39 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
40 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
41 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
42 import org.opendaylight.controller.md.sal.dom.api.DOMRpcException;
43 import org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementationNotAvailableException;
44 import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
45 import org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult;
46 import org.opendaylight.netconf.sal.restconf.impl.BrokerFacade;
47 import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
48 import org.opendaylight.netconf.sal.restconf.impl.JSONRestconfServiceImpl;
49 import org.opendaylight.netconf.sal.restconf.impl.PutResult;
50 import org.opendaylight.netconf.sal.restconf.impl.RestconfImpl;
51 import org.opendaylight.yangtools.yang.common.OperationFailedException;
52 import org.opendaylight.yangtools.yang.common.QName;
53 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
54 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
55 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
56 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
57 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
58 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
59 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
60 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
61 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
62 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
63 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
64 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
65 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
66 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
67 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
70 * Unit tests for JSONRestconfServiceImpl.
72 * @author Thomas Pantelis
74 public class JSONRestconfServiceImplTest {
75 static final String IETF_INTERFACES_NS = "urn:ietf:params:xml:ns:yang:ietf-interfaces";
76 static final String IETF_INTERFACES_VERSION = "2013-07-04";
77 static final QName INTERFACES_QNAME = QName.create(IETF_INTERFACES_NS, IETF_INTERFACES_VERSION, "interfaces");
78 static final QName INTERFACE_QNAME = QName.create(IETF_INTERFACES_NS, IETF_INTERFACES_VERSION, "interface");
79 static final QName NAME_QNAME = QName.create(IETF_INTERFACES_NS, IETF_INTERFACES_VERSION, "name");
80 static final QName TYPE_QNAME = QName.create(IETF_INTERFACES_NS, IETF_INTERFACES_VERSION, "type");
81 static final QName ENABLED_QNAME = QName.create(IETF_INTERFACES_NS, IETF_INTERFACES_VERSION, "enabled");
82 static final QName DESC_QNAME = QName.create(IETF_INTERFACES_NS, IETF_INTERFACES_VERSION, "description");
84 static final String TEST_MODULE_NS = "test:module";
85 static final String TEST_MODULE_VERSION = "2014-01-09";
86 static final QName TEST_CONT_QNAME = QName.create(TEST_MODULE_NS, TEST_MODULE_VERSION, "cont");
87 static final QName TEST_CONT1_QNAME = QName.create(TEST_MODULE_NS, TEST_MODULE_VERSION, "cont1");
88 static final QName TEST_LF11_QNAME = QName.create(TEST_MODULE_NS, TEST_MODULE_VERSION, "lf11");
89 static final QName TEST_LF12_QNAME = QName.create(TEST_MODULE_NS, TEST_MODULE_VERSION, "lf12");
91 static final String TOASTER_MODULE_NS = "http://netconfcentral.org/ns/toaster";
92 static final String TOASTER_MODULE_VERSION = "2009-11-20";
93 static final QName TOASTER_DONENESS_QNAME = QName.create(TOASTER_MODULE_NS, TOASTER_MODULE_VERSION, "toasterDoneness");
94 static final QName TOASTER_TYPE_QNAME = QName.create(TOASTER_MODULE_NS, TOASTER_MODULE_VERSION, "toasterToastType");
95 static final QName WHEAT_BREAD_QNAME = QName.create(TOASTER_MODULE_NS, TOASTER_MODULE_VERSION, "wheat-bread");
96 static final QName MAKE_TOAST_QNAME = QName.create(TOASTER_MODULE_NS, TOASTER_MODULE_VERSION, "make-toast");
97 static final QName CANCEL_TOAST_QNAME = QName.create(TOASTER_MODULE_NS, TOASTER_MODULE_VERSION, "cancel-toast");
98 static final QName TEST_OUTPUT_QNAME = QName.create(TOASTER_MODULE_NS, TOASTER_MODULE_VERSION, "testOutput");
99 static final QName TEXT_OUT_QNAME = QName.create(TOASTER_MODULE_NS, TOASTER_MODULE_VERSION, "textOut");
101 private static BrokerFacade brokerFacade;
103 private final JSONRestconfServiceImpl service = new JSONRestconfServiceImpl();
106 public static void init() throws IOException, ReactorException {
107 ControllerContext.getInstance().setSchemas(TestUtils.loadSchemaContext("/full-versions/yangs"));
108 brokerFacade = mock(BrokerFacade.class);
109 RestconfImpl.getInstance().setBroker(brokerFacade);
110 RestconfImpl.getInstance().setControllerContext(ControllerContext.getInstance());
114 public void setup() {
118 private static String loadData(final String path) throws IOException {
119 return Resources.asCharSource(JSONRestconfServiceImplTest.class.getResource(path), StandardCharsets.UTF_8).read();
122 @SuppressWarnings("rawtypes")
124 public void testPut() throws Exception {
125 final PutResult result = mock(PutResult.class);
126 when(brokerFacade.commitConfigurationDataPut(notNull(SchemaContext.class),
127 notNull(YangInstanceIdentifier.class), notNull(NormalizedNode.class))).thenReturn(result);
128 when(result.getFutureOfPutData())
129 .thenReturn(Futures.immediateCheckedFuture(null));
130 when(result.getStatus()).thenReturn(Status.OK);
131 final String uriPath = "ietf-interfaces:interfaces/interface/eth0";
132 final String payload = loadData("/parts/ietf-interfaces_interfaces.json");
134 this.service.put(uriPath, payload);
136 final ArgumentCaptor<YangInstanceIdentifier> capturedPath = ArgumentCaptor.forClass(YangInstanceIdentifier.class);
137 final ArgumentCaptor<NormalizedNode> capturedNode = ArgumentCaptor.forClass(NormalizedNode.class);
138 verify(brokerFacade).commitConfigurationDataPut(notNull(SchemaContext.class), capturedPath.capture(),
139 capturedNode.capture());
141 verifyPath(capturedPath.getValue(), INTERFACES_QNAME, INTERFACE_QNAME,
142 new Object[]{INTERFACE_QNAME, NAME_QNAME, "eth0"});
144 assertTrue("Expected MapEntryNode. Actual " + capturedNode.getValue().getClass(),
145 capturedNode.getValue() instanceof MapEntryNode);
146 final MapEntryNode actualNode = (MapEntryNode) capturedNode.getValue();
147 assertEquals("MapEntryNode node type", INTERFACE_QNAME, actualNode.getNodeType());
148 verifyLeafNode(actualNode, NAME_QNAME, "eth0");
149 verifyLeafNode(actualNode, TYPE_QNAME, "ethernetCsmacd");
150 verifyLeafNode(actualNode, ENABLED_QNAME, Boolean.FALSE);
151 verifyLeafNode(actualNode, DESC_QNAME, "some interface");
154 @SuppressWarnings("rawtypes")
156 public void testPutBehindMountPoint() throws Exception {
157 final DOMMountPoint mockMountPoint = setupTestMountPoint();
158 final PutResult result = mock(PutResult.class);
159 when(brokerFacade.commitMountPointDataPut(notNull(DOMMountPoint.class),
160 notNull(YangInstanceIdentifier.class), notNull(NormalizedNode.class))).thenReturn(result);
161 when(result.getFutureOfPutData()).thenReturn(Futures.immediateCheckedFuture(null));
162 when(result.getStatus()).thenReturn(Status.OK);
163 final String uriPath = "ietf-interfaces:interfaces/yang-ext:mount/test-module:cont/cont1";
164 final String payload = loadData("/full-versions/testCont1Data.json");
166 this.service.put(uriPath, payload);
168 final ArgumentCaptor<YangInstanceIdentifier> capturedPath = ArgumentCaptor.forClass(YangInstanceIdentifier.class);
169 final ArgumentCaptor<NormalizedNode> capturedNode = ArgumentCaptor.forClass(NormalizedNode.class);
170 verify(brokerFacade).commitMountPointDataPut(same(mockMountPoint), capturedPath.capture(),
171 capturedNode.capture());
173 verifyPath(capturedPath.getValue(), TEST_CONT_QNAME, TEST_CONT1_QNAME);
175 assertTrue("Expected ContainerNode", capturedNode.getValue() instanceof ContainerNode);
176 final ContainerNode actualNode = (ContainerNode) capturedNode.getValue();
177 assertEquals("ContainerNode node type", TEST_CONT1_QNAME, actualNode.getNodeType());
178 verifyLeafNode(actualNode, TEST_LF11_QNAME, "lf11 data");
179 verifyLeafNode(actualNode, TEST_LF12_QNAME, "lf12 data");
182 @Test(expected = OperationFailedException.class)
183 public void testPutFailure() throws Throwable {
184 final PutResult result = mock(PutResult.class);
185 when(result.getFutureOfPutData())
186 .thenReturn(Futures.immediateFailedCheckedFuture(new TransactionCommitFailedException("mock")));
187 when(result.getStatus()).thenReturn(Status.OK);
188 when(brokerFacade.commitConfigurationDataPut(notNull(SchemaContext.class),
189 notNull(YangInstanceIdentifier.class), notNull(NormalizedNode.class))).thenReturn(result);
191 final String uriPath = "ietf-interfaces:interfaces/interface/eth0";
192 final String payload = loadData("/parts/ietf-interfaces_interfaces.json");
194 this.service.put(uriPath, payload);
197 @SuppressWarnings("rawtypes")
199 public void testPost() throws Exception {
200 doReturn(Futures.immediateCheckedFuture(null)).when(brokerFacade).commitConfigurationDataPost(
201 any(SchemaContext.class), any(YangInstanceIdentifier.class), any(NormalizedNode.class));
203 final String uriPath = null;
204 final String payload = loadData("/parts/ietf-interfaces_interfaces_absolute_path.json");
206 this.service.post(uriPath, payload);
208 final ArgumentCaptor<YangInstanceIdentifier> capturedPath = ArgumentCaptor.forClass(YangInstanceIdentifier.class);
209 final ArgumentCaptor<NormalizedNode> capturedNode = ArgumentCaptor.forClass(NormalizedNode.class);
210 verify(brokerFacade).commitConfigurationDataPost(notNull(SchemaContext.class), capturedPath.capture(),
211 capturedNode.capture());
213 verifyPath(capturedPath.getValue(), INTERFACES_QNAME);
215 assertTrue("Expected ContainerNode", capturedNode.getValue() instanceof ContainerNode);
216 final ContainerNode actualNode = (ContainerNode) capturedNode.getValue();
217 assertEquals("ContainerNode node type", INTERFACES_QNAME, actualNode.getNodeType());
219 final Optional<DataContainerChild<?, ?>> mapChild = actualNode.getChild(new NodeIdentifier(INTERFACE_QNAME));
220 assertEquals(INTERFACE_QNAME.toString() + " present", true, mapChild.isPresent());
221 assertTrue("Expected MapNode. Actual " + mapChild.get().getClass(), mapChild.get() instanceof MapNode);
222 final MapNode mapNode = (MapNode)mapChild.get();
224 final NodeIdentifierWithPredicates entryNodeID = new NodeIdentifierWithPredicates(
225 INTERFACE_QNAME, NAME_QNAME, "eth0");
226 final Optional<MapEntryNode> entryChild = mapNode.getChild(entryNodeID);
227 assertEquals(entryNodeID.toString() + " present", true, entryChild.isPresent());
228 final MapEntryNode entryNode = entryChild.get();
229 verifyLeafNode(entryNode, NAME_QNAME, "eth0");
230 verifyLeafNode(entryNode, TYPE_QNAME, "ethernetCsmacd");
231 verifyLeafNode(entryNode, ENABLED_QNAME, Boolean.FALSE);
232 verifyLeafNode(entryNode, DESC_QNAME, "some interface");
235 @SuppressWarnings("rawtypes")
237 public void testPostBehindMountPoint() throws Exception {
238 final DOMMountPoint mockMountPoint = setupTestMountPoint();
239 doReturn(Futures.immediateCheckedFuture(null)).when(brokerFacade).commitConfigurationDataPost(
240 notNull(DOMMountPoint.class), notNull(YangInstanceIdentifier.class), notNull(NormalizedNode.class));
242 final String uriPath = "ietf-interfaces:interfaces/yang-ext:mount/test-module:cont";
243 final String payload = loadData("/full-versions/testCont1Data.json");
245 this.service.post(uriPath, payload);
247 final ArgumentCaptor<YangInstanceIdentifier> capturedPath = ArgumentCaptor.forClass(YangInstanceIdentifier.class);
248 final ArgumentCaptor<NormalizedNode> capturedNode = ArgumentCaptor.forClass(NormalizedNode.class);
249 verify(brokerFacade).commitConfigurationDataPost(same(mockMountPoint), capturedPath.capture(),
250 capturedNode.capture());
252 verifyPath(capturedPath.getValue(), TEST_CONT_QNAME, TEST_CONT1_QNAME);
254 assertTrue("Expected ContainerNode", capturedNode.getValue() instanceof ContainerNode);
255 final ContainerNode actualNode = (ContainerNode) capturedNode.getValue();
256 assertEquals("ContainerNode node type", TEST_CONT1_QNAME, actualNode.getNodeType());
257 verifyLeafNode(actualNode, TEST_LF11_QNAME, "lf11 data");
258 verifyLeafNode(actualNode, TEST_LF12_QNAME, "lf12 data");
262 public void testPostFailure() throws Throwable {
263 doReturn(Futures.immediateFailedCheckedFuture(new TransactionCommitFailedException("mock"))).when(brokerFacade)
264 .commitConfigurationDataPost(any(SchemaContext.class), any(YangInstanceIdentifier.class),
265 any(NormalizedNode.class));
267 final String uriPath = null;
268 final String payload = loadData("/parts/ietf-interfaces_interfaces_absolute_path.json");
270 this.service.post(uriPath, payload);
274 public void testDelete() throws Exception {
275 doReturn(Futures.immediateCheckedFuture(null)).when(brokerFacade)
276 .commitConfigurationDataDelete(notNull(YangInstanceIdentifier.class));
278 final String uriPath = "ietf-interfaces:interfaces/interface/eth0";
280 this.service.delete(uriPath);
282 final 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 final String invalidUriPath = "ietf-interfaces:interfaces/invalid";
293 this.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 OperationFailedException {
308 doReturn(null).when(brokerFacade).readConfigurationData(notNull(YangInstanceIdentifier.class));
309 final String uriPath = "ietf-interfaces:interfaces";
310 this.service.get(uriPath, LogicalDatastoreType.CONFIGURATION);
313 @Test(expected=OperationFailedException.class)
314 public void testGetFailure() throws Exception {
315 final String invalidUriPath = "/ietf-interfaces:interfaces/invalid";
317 this.service.get(invalidUriPath, LogicalDatastoreType.CONFIGURATION);
320 @SuppressWarnings("rawtypes")
322 public void testInvokeRpcWithInput() throws Exception {
323 final SchemaPath path = SchemaPath.create(true, MAKE_TOAST_QNAME);
325 final DOMRpcResult expResult = new DefaultDOMRpcResult((NormalizedNode<?, ?>)null);
326 doReturn(Futures.immediateCheckedFuture(expResult)).when(brokerFacade).invokeRpc(eq(path),
327 any(NormalizedNode.class));
329 final String uriPath = "toaster:make-toast";
330 final String input = loadData("/full-versions/make-toast-rpc-input.json");
332 final Optional<String> output = this.service.invokeRpc(uriPath, Optional.of(input));
334 assertEquals("Output present", false, output.isPresent());
336 final ArgumentCaptor<NormalizedNode> capturedNode = ArgumentCaptor.forClass(NormalizedNode.class);
337 verify(brokerFacade).invokeRpc(eq(path), capturedNode.capture());
339 assertTrue("Expected ContainerNode. Actual " + capturedNode.getValue().getClass(),
340 capturedNode.getValue() instanceof ContainerNode);
341 final ContainerNode actualNode = (ContainerNode) capturedNode.getValue();
342 verifyLeafNode(actualNode, TOASTER_DONENESS_QNAME, Long.valueOf(10));
343 verifyLeafNode(actualNode, TOASTER_TYPE_QNAME, WHEAT_BREAD_QNAME);
347 public void testInvokeRpcWithNoInput() throws Exception {
348 final SchemaPath path = SchemaPath.create(true, CANCEL_TOAST_QNAME);
350 final DOMRpcResult expResult = new DefaultDOMRpcResult((NormalizedNode<?, ?>)null);
351 doReturn(Futures.immediateCheckedFuture(expResult)).when(brokerFacade).invokeRpc(any(SchemaPath.class),
352 any(NormalizedNode.class));
354 final String uriPath = "toaster:cancel-toast";
356 final Optional<String> output = this.service.invokeRpc(uriPath, Optional.<String>absent());
358 assertEquals("Output present", false, output.isPresent());
360 verify(brokerFacade).invokeRpc(eq(path), isNull(NormalizedNode.class));
364 public void testInvokeRpcWithOutput() throws Exception {
365 final SchemaPath path = SchemaPath.create(true, TEST_OUTPUT_QNAME);
367 final NormalizedNode<?, ?> outputNode = ImmutableContainerNodeBuilder.create()
368 .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TEST_OUTPUT_QNAME))
369 .withChild(ImmutableNodes.leafNode(TEXT_OUT_QNAME, "foo")).build();
370 final DOMRpcResult expResult = new DefaultDOMRpcResult(outputNode);
371 doReturn(Futures.immediateCheckedFuture(expResult)).when(brokerFacade).invokeRpc(any(SchemaPath.class),
372 any(NormalizedNode.class));
374 final String uriPath = "toaster:testOutput";
376 final Optional<String> output = this.service.invokeRpc(uriPath, Optional.<String>absent());
378 assertEquals("Output present", true, output.isPresent());
379 assertNotNull("Returned null response", output.get());
380 assertThat("Missing \"textOut\"", output.get(), containsString("\"textOut\":\"foo\""));
382 verify(brokerFacade).invokeRpc(eq(path), isNull(NormalizedNode.class));
385 @Test(expected=OperationFailedException.class)
386 public void testInvokeRpcFailure() throws Exception {
387 final DOMRpcException exception = new DOMRpcImplementationNotAvailableException("testExeption");
388 doReturn(Futures.immediateFailedCheckedFuture(exception)).when(brokerFacade).invokeRpc(any(SchemaPath.class),
389 any(NormalizedNode.class));
391 final String uriPath = "toaster:cancel-toast";
393 this.service.invokeRpc(uriPath, Optional.<String>absent());
396 void testGet(final LogicalDatastoreType datastoreType) throws OperationFailedException {
397 final MapEntryNode entryNode = ImmutableNodes.mapEntryBuilder(INTERFACE_QNAME, NAME_QNAME, "eth0")
398 .withChild(ImmutableNodes.leafNode(NAME_QNAME, "eth0"))
399 .withChild(ImmutableNodes.leafNode(TYPE_QNAME, "ethernetCsmacd"))
400 .withChild(ImmutableNodes.leafNode(ENABLED_QNAME, Boolean.TRUE))
401 .withChild(ImmutableNodes.leafNode(DESC_QNAME, "eth interface"))
404 if(datastoreType == LogicalDatastoreType.CONFIGURATION) {
405 doReturn(entryNode).when(brokerFacade).readConfigurationData(notNull(YangInstanceIdentifier.class));
407 doReturn(entryNode).when(brokerFacade).readOperationalData(notNull(YangInstanceIdentifier.class));
410 final String uriPath = "/ietf-interfaces:interfaces/interface/eth0";
412 final Optional<String> optionalResp = this.service.get(uriPath, datastoreType);
413 assertEquals("Response present", true, optionalResp.isPresent());
414 final String jsonResp = optionalResp.get();
416 assertNotNull("Returned null response", jsonResp);
417 assertThat("Missing \"name\"", jsonResp, containsString("\"name\":\"eth0\""));
418 assertThat("Missing \"type\"", jsonResp, containsString("\"type\":\"ethernetCsmacd\""));
419 assertThat("Missing \"enabled\"", jsonResp, containsString("\"enabled\":true"));
420 assertThat("Missing \"description\"", jsonResp, containsString("\"description\":\"eth interface\""));
422 final ArgumentCaptor<YangInstanceIdentifier> capturedPath = ArgumentCaptor.forClass(YangInstanceIdentifier.class);
423 if (datastoreType == LogicalDatastoreType.CONFIGURATION) {
424 verify(brokerFacade).readConfigurationData(capturedPath.capture());
426 verify(brokerFacade).readOperationalData(capturedPath.capture());
429 verifyPath(capturedPath.getValue(), INTERFACES_QNAME, INTERFACE_QNAME,
430 new Object[]{INTERFACE_QNAME, NAME_QNAME, "eth0"});
433 DOMMountPoint setupTestMountPoint() throws FileNotFoundException, ReactorException {
434 final SchemaContext schemaContextTestModule = TestUtils.loadSchemaContext("/full-versions/test-module");
435 final DOMMountPoint mockMountPoint = mock(DOMMountPoint.class);
436 doReturn(schemaContextTestModule).when(mockMountPoint).getSchemaContext();
438 final DOMMountPointService mockMountService = mock(DOMMountPointService.class);
439 doReturn(Optional.of(mockMountPoint)).when(mockMountService).getMountPoint(notNull(YangInstanceIdentifier.class));
441 ControllerContext.getInstance().setMountService(mockMountService);
442 return mockMountPoint;
445 void verifyLeafNode(final DataContainerNode<?> parent, final QName leafType, final Object leafValue) {
446 final Optional<DataContainerChild<?, ?>> leafChild = parent.getChild(new NodeIdentifier(leafType));
447 assertEquals(leafType.toString() + " present", true, leafChild.isPresent());
448 assertEquals(leafType.toString() + " value", leafValue, leafChild.get().getValue());
451 void verifyPath(final YangInstanceIdentifier path, final Object... expArgs) {
452 final List<PathArgument> pathArgs = path.getPathArguments();
453 assertEquals("Arg count for actual path " + path, expArgs.length, pathArgs.size());
455 for(final PathArgument actual: pathArgs) {
457 if(expArgs[i] instanceof Object[]) {
458 final Object[] listEntry = (Object[]) expArgs[i];
459 expNodeType = (QName) listEntry[0];
461 assertTrue(actual instanceof NodeIdentifierWithPredicates);
462 final Map<QName, Object> keyValues = ((NodeIdentifierWithPredicates)actual).getKeyValues();
463 assertEquals(String.format("Path arg %d keyValues size", i + 1), 1, keyValues.size());
464 final QName expKey = (QName) listEntry[1];
465 assertEquals(String.format("Path arg %d keyValue for %s", i + 1, expKey), listEntry[2],
466 keyValues.get(expKey));
468 expNodeType = (QName) expArgs[i];
471 assertEquals(String.format("Path arg %d node type", i + 1), expNodeType, actual.getNodeType());