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;
26 import com.google.common.base.Optional;
27 import com.google.common.io.Resources;
28 import com.google.common.util.concurrent.Futures;
29 import java.io.FileNotFoundException;
30 import java.io.IOException;
31 import java.nio.charset.StandardCharsets;
32 import java.util.List;
34 import javax.ws.rs.core.Response.Status;
35 import org.junit.Before;
36 import org.junit.BeforeClass;
37 import org.junit.Test;
38 import org.mockito.ArgumentCaptor;
39 import org.mockito.Mockito;
40 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
41 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
42 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
43 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
44 import org.opendaylight.controller.md.sal.dom.api.DOMRpcException;
45 import org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementationNotAvailableException;
46 import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
47 import org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult;
48 import org.opendaylight.netconf.sal.restconf.impl.BrokerFacade;
49 import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
50 import org.opendaylight.netconf.sal.restconf.impl.JSONRestconfServiceImpl;
51 import org.opendaylight.netconf.sal.restconf.impl.PutResult;
52 import org.opendaylight.netconf.sal.restconf.impl.RestconfImpl;
53 import org.opendaylight.yangtools.yang.common.OperationFailedException;
54 import org.opendaylight.yangtools.yang.common.QName;
55 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
56 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
57 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
58 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
59 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
60 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
61 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
62 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
63 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
64 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
65 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
66 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
67 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
68 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
69 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
72 * Unit tests for JSONRestconfServiceImpl.
74 * @author Thomas Pantelis
77 public class JSONRestconfServiceImplTest {
78 static final String IETF_INTERFACES_NS = "urn:ietf:params:xml:ns:yang:ietf-interfaces";
79 static final String IETF_INTERFACES_VERSION = "2013-07-04";
80 static final QName INTERFACES_QNAME = QName.create(IETF_INTERFACES_NS, IETF_INTERFACES_VERSION, "interfaces");
81 static final QName INTERFACE_QNAME = QName.create(IETF_INTERFACES_NS, IETF_INTERFACES_VERSION, "interface");
82 static final QName NAME_QNAME = QName.create(IETF_INTERFACES_NS, IETF_INTERFACES_VERSION, "name");
83 static final QName TYPE_QNAME = QName.create(IETF_INTERFACES_NS, IETF_INTERFACES_VERSION, "type");
84 static final QName ENABLED_QNAME = QName.create(IETF_INTERFACES_NS, IETF_INTERFACES_VERSION, "enabled");
85 static final QName DESC_QNAME = QName.create(IETF_INTERFACES_NS, IETF_INTERFACES_VERSION, "description");
87 static final String TEST_MODULE_NS = "test:module";
88 static final String TEST_MODULE_VERSION = "2014-01-09";
89 static final QName TEST_CONT_QNAME = QName.create(TEST_MODULE_NS, TEST_MODULE_VERSION, "cont");
90 static final QName TEST_CONT1_QNAME = QName.create(TEST_MODULE_NS, TEST_MODULE_VERSION, "cont1");
91 static final QName TEST_LF11_QNAME = QName.create(TEST_MODULE_NS, TEST_MODULE_VERSION, "lf11");
92 static final QName TEST_LF12_QNAME = QName.create(TEST_MODULE_NS, TEST_MODULE_VERSION, "lf12");
94 static final String TOASTER_MODULE_NS = "http://netconfcentral.org/ns/toaster";
95 static final String TOASTER_MODULE_VERSION = "2009-11-20";
96 static final QName TOASTER_DONENESS_QNAME =
97 QName.create(TOASTER_MODULE_NS, TOASTER_MODULE_VERSION, "toasterDoneness");
98 static final QName TOASTER_TYPE_QNAME = QName.create(TOASTER_MODULE_NS, TOASTER_MODULE_VERSION, "toasterToastType");
99 static final QName WHEAT_BREAD_QNAME = QName.create(TOASTER_MODULE_NS, TOASTER_MODULE_VERSION, "wheat-bread");
100 static final QName MAKE_TOAST_QNAME = QName.create(TOASTER_MODULE_NS, TOASTER_MODULE_VERSION, "make-toast");
101 static final QName CANCEL_TOAST_QNAME = QName.create(TOASTER_MODULE_NS, TOASTER_MODULE_VERSION, "cancel-toast");
102 static final QName TEST_OUTPUT_QNAME = QName.create(TOASTER_MODULE_NS, TOASTER_MODULE_VERSION, "testOutput");
103 static final QName TEXT_OUT_QNAME = QName.create(TOASTER_MODULE_NS, TOASTER_MODULE_VERSION, "textOut");
105 private static BrokerFacade brokerFacade;
107 private final JSONRestconfServiceImpl service = new JSONRestconfServiceImpl();
110 public static void init() throws IOException, ReactorException {
111 ControllerContext.getInstance().setSchemas(TestUtils.loadSchemaContext("/full-versions/yangs"));
112 brokerFacade = mock(BrokerFacade.class);
113 RestconfImpl.getInstance().setBroker(brokerFacade);
114 RestconfImpl.getInstance().setControllerContext(ControllerContext.getInstance());
118 public void setup() {
122 private static String loadData(final String path) throws IOException {
123 return Resources.asCharSource(JSONRestconfServiceImplTest.class.getResource(path),
124 StandardCharsets.UTF_8).read();
127 @SuppressWarnings("rawtypes")
129 public void testPut() throws Exception {
130 final PutResult result = mock(PutResult.class);
131 when(brokerFacade.commitConfigurationDataPut(notNull(SchemaContext.class),
132 notNull(YangInstanceIdentifier.class), notNull(NormalizedNode.class), Mockito.anyString(),
133 Mockito.anyString())).thenReturn(result);
134 when(result.getFutureOfPutData())
135 .thenReturn(Futures.immediateCheckedFuture(null));
136 when(result.getStatus()).thenReturn(Status.OK);
137 final String uriPath = "ietf-interfaces:interfaces/interface/eth0";
138 final String payload = loadData("/parts/ietf-interfaces_interfaces.json");
139 this.service.put(uriPath, payload);
141 final ArgumentCaptor<YangInstanceIdentifier> capturedPath =
142 ArgumentCaptor.forClass(YangInstanceIdentifier.class);
143 final ArgumentCaptor<NormalizedNode> capturedNode = ArgumentCaptor.forClass(NormalizedNode.class);
144 verify(brokerFacade).commitConfigurationDataPut(notNull(SchemaContext.class), capturedPath.capture(),
145 capturedNode.capture(), Mockito.anyString(), Mockito.anyString());
147 verifyPath(capturedPath.getValue(), INTERFACES_QNAME, INTERFACE_QNAME,
148 new Object[]{INTERFACE_QNAME, NAME_QNAME, "eth0"});
150 assertTrue("Expected MapEntryNode. Actual " + capturedNode.getValue().getClass(),
151 capturedNode.getValue() instanceof MapEntryNode);
152 final MapEntryNode actualNode = (MapEntryNode) capturedNode.getValue();
153 assertEquals("MapEntryNode node type", INTERFACE_QNAME, actualNode.getNodeType());
154 verifyLeafNode(actualNode, NAME_QNAME, "eth0");
155 verifyLeafNode(actualNode, TYPE_QNAME, "ethernetCsmacd");
156 verifyLeafNode(actualNode, ENABLED_QNAME, Boolean.FALSE);
157 verifyLeafNode(actualNode, DESC_QNAME, "some interface");
160 @SuppressWarnings("rawtypes")
162 public void testPutBehindMountPoint() throws Exception {
163 final DOMMountPoint mockMountPoint = setupTestMountPoint();
164 final PutResult result = mock(PutResult.class);
165 when(brokerFacade.commitMountPointDataPut(notNull(DOMMountPoint.class),
166 notNull(YangInstanceIdentifier.class), notNull(NormalizedNode.class), Mockito.anyString(),
167 Mockito.anyString())).thenReturn(result);
168 when(result.getFutureOfPutData()).thenReturn(Futures.immediateCheckedFuture(null));
169 when(result.getStatus()).thenReturn(Status.OK);
170 final String uriPath = "ietf-interfaces:interfaces/yang-ext:mount/test-module:cont/cont1";
171 final String payload = loadData("/full-versions/testCont1Data.json");
173 this.service.put(uriPath, payload);
175 final ArgumentCaptor<YangInstanceIdentifier> capturedPath =
176 ArgumentCaptor.forClass(YangInstanceIdentifier.class);
177 final ArgumentCaptor<NormalizedNode> capturedNode = ArgumentCaptor.forClass(NormalizedNode.class);
178 verify(brokerFacade).commitMountPointDataPut(same(mockMountPoint), capturedPath.capture(),
179 capturedNode.capture(), Mockito.anyString(), Mockito.anyString());
181 verifyPath(capturedPath.getValue(), TEST_CONT_QNAME, TEST_CONT1_QNAME);
183 assertTrue("Expected ContainerNode", capturedNode.getValue() instanceof ContainerNode);
184 final ContainerNode actualNode = (ContainerNode) capturedNode.getValue();
185 assertEquals("ContainerNode node type", TEST_CONT1_QNAME, actualNode.getNodeType());
186 verifyLeafNode(actualNode, TEST_LF11_QNAME, "lf11 data");
187 verifyLeafNode(actualNode, TEST_LF12_QNAME, "lf12 data");
190 @Test(expected = OperationFailedException.class)
191 @SuppressWarnings("checkstyle:IllegalThrows")
192 public void testPutFailure() throws Throwable {
193 final PutResult result = mock(PutResult.class);
195 when(result.getFutureOfPutData())
196 .thenReturn(Futures.immediateFailedCheckedFuture(new TransactionCommitFailedException("mock")));
197 when(result.getStatus()).thenReturn(Status.OK);
198 when(brokerFacade.commitConfigurationDataPut(notNull(SchemaContext.class),
199 notNull(YangInstanceIdentifier.class), notNull(NormalizedNode.class), Mockito.anyString(),
200 Mockito.anyString())).thenReturn(result);
202 final String uriPath = "ietf-interfaces:interfaces/interface/eth0";
203 final String payload = loadData("/parts/ietf-interfaces_interfaces.json");
205 this.service.put(uriPath, payload);
208 @SuppressWarnings("rawtypes")
210 public void testPost() throws Exception {
211 doReturn(Futures.immediateCheckedFuture(null)).when(brokerFacade).commitConfigurationDataPost(
212 any(SchemaContext.class), any(YangInstanceIdentifier.class), any(NormalizedNode.class),
213 Mockito.anyString(), Mockito.anyString());
215 final String uriPath = null;
216 final String payload = loadData("/parts/ietf-interfaces_interfaces_absolute_path.json");
218 this.service.post(uriPath, payload);
220 final ArgumentCaptor<YangInstanceIdentifier> capturedPath =
221 ArgumentCaptor.forClass(YangInstanceIdentifier.class);
222 final ArgumentCaptor<NormalizedNode> capturedNode = ArgumentCaptor.forClass(NormalizedNode.class);
223 verify(brokerFacade).commitConfigurationDataPost(notNull(SchemaContext.class), capturedPath.capture(),
224 capturedNode.capture(), Mockito.anyString(), Mockito.anyString());
226 verifyPath(capturedPath.getValue(), INTERFACES_QNAME);
228 assertTrue("Expected ContainerNode", capturedNode.getValue() instanceof ContainerNode);
229 final ContainerNode actualNode = (ContainerNode) capturedNode.getValue();
230 assertEquals("ContainerNode node type", INTERFACES_QNAME, actualNode.getNodeType());
232 final Optional<DataContainerChild<?, ?>> mapChild = actualNode.getChild(new NodeIdentifier(INTERFACE_QNAME));
233 assertEquals(INTERFACE_QNAME.toString() + " present", true, mapChild.isPresent());
234 assertTrue("Expected MapNode. Actual " + mapChild.get().getClass(), mapChild.get() instanceof MapNode);
235 final MapNode mapNode = (MapNode)mapChild.get();
237 final NodeIdentifierWithPredicates entryNodeID = new NodeIdentifierWithPredicates(
238 INTERFACE_QNAME, NAME_QNAME, "eth0");
239 final Optional<MapEntryNode> entryChild = mapNode.getChild(entryNodeID);
240 assertEquals(entryNodeID.toString() + " present", true, entryChild.isPresent());
241 final MapEntryNode entryNode = entryChild.get();
242 verifyLeafNode(entryNode, NAME_QNAME, "eth0");
243 verifyLeafNode(entryNode, TYPE_QNAME, "ethernetCsmacd");
244 verifyLeafNode(entryNode, ENABLED_QNAME, Boolean.FALSE);
245 verifyLeafNode(entryNode, DESC_QNAME, "some interface");
248 @SuppressWarnings("rawtypes")
250 public void testPostBehindMountPoint() throws Exception {
251 final DOMMountPoint mockMountPoint = setupTestMountPoint();
252 doReturn(Futures.immediateCheckedFuture(null)).when(brokerFacade).commitConfigurationDataPost(
253 notNull(DOMMountPoint.class), notNull(YangInstanceIdentifier.class), notNull(NormalizedNode.class),
254 Mockito.anyString(), Mockito.anyString());
256 final String uriPath = "ietf-interfaces:interfaces/yang-ext:mount/test-module:cont";
257 final String payload = loadData("/full-versions/testCont1Data.json");
259 this.service.post(uriPath, payload);
261 final ArgumentCaptor<YangInstanceIdentifier> capturedPath =
262 ArgumentCaptor.forClass(YangInstanceIdentifier.class);
263 final ArgumentCaptor<NormalizedNode> capturedNode = ArgumentCaptor.forClass(NormalizedNode.class);
264 verify(brokerFacade).commitConfigurationDataPost(same(mockMountPoint), capturedPath.capture(),
265 capturedNode.capture(), Mockito.anyString(), Mockito.anyString());
267 verifyPath(capturedPath.getValue(), TEST_CONT_QNAME, TEST_CONT1_QNAME);
269 assertTrue("Expected ContainerNode", capturedNode.getValue() instanceof ContainerNode);
270 final ContainerNode actualNode = (ContainerNode) capturedNode.getValue();
271 assertEquals("ContainerNode node type", TEST_CONT1_QNAME, actualNode.getNodeType());
272 verifyLeafNode(actualNode, TEST_LF11_QNAME, "lf11 data");
273 verifyLeafNode(actualNode, TEST_LF12_QNAME, "lf12 data");
276 @Test(expected = TransactionCommitFailedException.class)
277 @SuppressWarnings("checkstyle:IllegalThrows")
278 public void testPostFailure() throws Throwable {
279 doReturn(Futures.immediateFailedCheckedFuture(new TransactionCommitFailedException("mock"))).when(brokerFacade)
280 .commitConfigurationDataPost(any(SchemaContext.class), any(YangInstanceIdentifier.class),
281 any(NormalizedNode.class), Mockito.anyString(), Mockito.anyString());
283 final String uriPath = null;
284 final String payload = loadData("/parts/ietf-interfaces_interfaces_absolute_path.json");
287 this.service.post(uriPath, payload);
288 } catch (final OperationFailedException e) {
289 assertNotNull(e.getCause());
295 public void testDelete() throws Exception {
296 doReturn(Futures.immediateCheckedFuture(null)).when(brokerFacade)
297 .commitConfigurationDataDelete(notNull(YangInstanceIdentifier.class));
299 final String uriPath = "ietf-interfaces:interfaces/interface/eth0";
301 this.service.delete(uriPath);
303 final ArgumentCaptor<YangInstanceIdentifier> capturedPath =
304 ArgumentCaptor.forClass(YangInstanceIdentifier.class);
305 verify(brokerFacade).commitConfigurationDataDelete(capturedPath.capture());
307 verifyPath(capturedPath.getValue(), INTERFACES_QNAME, INTERFACE_QNAME,
308 new Object[]{INTERFACE_QNAME, NAME_QNAME, "eth0"});
311 @Test(expected = OperationFailedException.class)
312 public void testDeleteFailure() throws Exception {
313 final String invalidUriPath = "ietf-interfaces:interfaces/invalid";
315 this.service.delete(invalidUriPath);
319 public void testGetConfig() throws Exception {
320 testGet(LogicalDatastoreType.CONFIGURATION);
324 public void testGetOperational() throws Exception {
325 testGet(LogicalDatastoreType.OPERATIONAL);
329 public void testGetWithNoData() throws OperationFailedException {
330 doReturn(null).when(brokerFacade).readConfigurationData(notNull(YangInstanceIdentifier.class),
331 Mockito.anyString());
332 final String uriPath = "ietf-interfaces:interfaces";
333 this.service.get(uriPath, LogicalDatastoreType.CONFIGURATION);
336 @Test(expected = OperationFailedException.class)
337 public void testGetFailure() throws Exception {
338 final String invalidUriPath = "/ietf-interfaces:interfaces/invalid";
339 this.service.get(invalidUriPath, LogicalDatastoreType.CONFIGURATION);
342 @SuppressWarnings("rawtypes")
344 public void testInvokeRpcWithInput() throws Exception {
345 final SchemaPath path = SchemaPath.create(true, MAKE_TOAST_QNAME);
347 final DOMRpcResult expResult = new DefaultDOMRpcResult((NormalizedNode<?, ?>)null);
348 doReturn(Futures.immediateCheckedFuture(expResult)).when(brokerFacade).invokeRpc(eq(path),
349 any(NormalizedNode.class));
351 final String uriPath = "toaster:make-toast";
352 final String input = loadData("/full-versions/make-toast-rpc-input.json");
354 final Optional<String> output = this.service.invokeRpc(uriPath, Optional.of(input));
356 assertEquals("Output present", false, output.isPresent());
358 final ArgumentCaptor<NormalizedNode> capturedNode = ArgumentCaptor.forClass(NormalizedNode.class);
359 verify(brokerFacade).invokeRpc(eq(path), capturedNode.capture());
361 assertTrue("Expected ContainerNode. Actual " + capturedNode.getValue().getClass(),
362 capturedNode.getValue() instanceof ContainerNode);
363 final ContainerNode actualNode = (ContainerNode) capturedNode.getValue();
364 verifyLeafNode(actualNode, TOASTER_DONENESS_QNAME, Long.valueOf(10));
365 verifyLeafNode(actualNode, TOASTER_TYPE_QNAME, WHEAT_BREAD_QNAME);
369 public void testInvokeRpcWithNoInput() throws Exception {
370 final SchemaPath path = SchemaPath.create(true, CANCEL_TOAST_QNAME);
372 final DOMRpcResult expResult = new DefaultDOMRpcResult((NormalizedNode<?, ?>)null);
373 doReturn(Futures.immediateCheckedFuture(expResult)).when(brokerFacade).invokeRpc(any(SchemaPath.class),
374 any(NormalizedNode.class));
376 final String uriPath = "toaster:cancel-toast";
378 final Optional<String> output = this.service.invokeRpc(uriPath, Optional.<String>absent());
380 assertEquals("Output present", false, output.isPresent());
382 verify(brokerFacade).invokeRpc(eq(path), isNull(NormalizedNode.class));
386 public void testInvokeRpcWithOutput() throws Exception {
387 final SchemaPath path = SchemaPath.create(true, TEST_OUTPUT_QNAME);
389 final NormalizedNode<?, ?> outputNode = ImmutableContainerNodeBuilder.create()
390 .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TEST_OUTPUT_QNAME))
391 .withChild(ImmutableNodes.leafNode(TEXT_OUT_QNAME, "foo")).build();
392 final DOMRpcResult expResult = new DefaultDOMRpcResult(outputNode);
393 doReturn(Futures.immediateCheckedFuture(expResult)).when(brokerFacade).invokeRpc(any(SchemaPath.class),
394 any(NormalizedNode.class));
396 final String uriPath = "toaster:testOutput";
398 final Optional<String> output = this.service.invokeRpc(uriPath, Optional.<String>absent());
400 assertEquals("Output present", true, output.isPresent());
401 assertNotNull("Returned null response", output.get());
402 assertThat("Missing \"textOut\"", output.get(), containsString("\"textOut\":\"foo\""));
404 verify(brokerFacade).invokeRpc(eq(path), isNull(NormalizedNode.class));
407 @Test(expected = OperationFailedException.class)
408 public void testInvokeRpcFailure() throws Exception {
409 final DOMRpcException exception = new DOMRpcImplementationNotAvailableException("testExeption");
410 doReturn(Futures.immediateFailedCheckedFuture(exception)).when(brokerFacade).invokeRpc(any(SchemaPath.class),
411 any(NormalizedNode.class));
413 final String uriPath = "toaster:cancel-toast";
415 this.service.invokeRpc(uriPath, Optional.<String>absent());
418 void testGet(final LogicalDatastoreType datastoreType) throws OperationFailedException {
419 final MapEntryNode entryNode = ImmutableNodes.mapEntryBuilder(INTERFACE_QNAME, NAME_QNAME, "eth0")
420 .withChild(ImmutableNodes.leafNode(NAME_QNAME, "eth0"))
421 .withChild(ImmutableNodes.leafNode(TYPE_QNAME, "ethernetCsmacd"))
422 .withChild(ImmutableNodes.leafNode(ENABLED_QNAME, Boolean.TRUE))
423 .withChild(ImmutableNodes.leafNode(DESC_QNAME, "eth interface"))
426 if (datastoreType == LogicalDatastoreType.CONFIGURATION) {
427 doReturn(entryNode).when(brokerFacade).readConfigurationData(notNull(YangInstanceIdentifier.class),
428 Mockito.anyString());
430 doReturn(entryNode).when(brokerFacade).readOperationalData(notNull(YangInstanceIdentifier.class));
433 final String uriPath = "/ietf-interfaces:interfaces/interface/eth0";
435 final Optional<String> optionalResp = this.service.get(uriPath, datastoreType);
436 assertEquals("Response present", true, optionalResp.isPresent());
437 final String jsonResp = optionalResp.get();
439 assertNotNull("Returned null response", jsonResp);
440 assertThat("Missing \"name\"", jsonResp, containsString("\"name\":\"eth0\""));
441 assertThat("Missing \"type\"", jsonResp, containsString("\"type\":\"ethernetCsmacd\""));
442 assertThat("Missing \"enabled\"", jsonResp, containsString("\"enabled\":true"));
443 assertThat("Missing \"description\"", jsonResp, containsString("\"description\":\"eth interface\""));
445 final ArgumentCaptor<YangInstanceIdentifier> capturedPath =
446 ArgumentCaptor.forClass(YangInstanceIdentifier.class);
447 if (datastoreType == LogicalDatastoreType.CONFIGURATION) {
448 verify(brokerFacade).readConfigurationData(capturedPath.capture(), Mockito.anyString());
450 verify(brokerFacade).readOperationalData(capturedPath.capture());
453 verifyPath(capturedPath.getValue(), INTERFACES_QNAME, INTERFACE_QNAME,
454 new Object[]{INTERFACE_QNAME, NAME_QNAME, "eth0"});
457 DOMMountPoint setupTestMountPoint() throws FileNotFoundException, ReactorException {
458 final SchemaContext schemaContextTestModule = TestUtils.loadSchemaContext("/full-versions/test-module");
459 final DOMMountPoint mockMountPoint = mock(DOMMountPoint.class);
460 doReturn(schemaContextTestModule).when(mockMountPoint).getSchemaContext();
462 final DOMMountPointService mockMountService = mock(DOMMountPointService.class);
463 doReturn(Optional.of(mockMountPoint))
464 .when(mockMountService).getMountPoint(notNull(YangInstanceIdentifier.class));
466 ControllerContext.getInstance().setMountService(mockMountService);
467 return mockMountPoint;
470 void verifyLeafNode(final DataContainerNode<?> parent, final QName leafType, final Object leafValue) {
471 final Optional<DataContainerChild<?, ?>> leafChild = parent.getChild(new NodeIdentifier(leafType));
472 assertEquals(leafType.toString() + " present", true, leafChild.isPresent());
473 assertEquals(leafType.toString() + " value", leafValue, leafChild.get().getValue());
476 void verifyPath(final YangInstanceIdentifier path, final Object... expArgs) {
477 final List<PathArgument> pathArgs = path.getPathArguments();
478 assertEquals("Arg count for actual path " + path, expArgs.length, pathArgs.size());
480 for (final PathArgument actual: pathArgs) {
482 if (expArgs[index] instanceof Object[]) {
483 final Object[] listEntry = (Object[]) expArgs[index];
484 expNodeType = (QName) listEntry[0];
486 assertTrue(actual instanceof NodeIdentifierWithPredicates);
487 final Map<QName, Object> keyValues = ((NodeIdentifierWithPredicates)actual).getKeyValues();
488 assertEquals(String.format("Path arg %d keyValues size", index + 1), 1, keyValues.size());
489 final QName expKey = (QName) listEntry[1];
490 assertEquals(String.format("Path arg %d keyValue for %s", index + 1, expKey), listEntry[2],
491 keyValues.get(expKey));
493 expNodeType = (QName) expArgs[index];
496 assertEquals(String.format("Path arg %d node type", index + 1), expNodeType, actual.getNodeType());