2 * Copyright (c) 2016 Cisco 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.restconf.nb.rfc8040.rests.services.impl;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertNull;
14 import static org.junit.Assert.assertThrows;
15 import static org.junit.Assert.assertTrue;
16 import static org.mockito.ArgumentMatchers.any;
17 import static org.mockito.Mockito.doNothing;
18 import static org.mockito.Mockito.doReturn;
19 import static org.mockito.Mockito.mock;
20 import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateFalseFluentFuture;
21 import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateFluentFuture;
22 import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateTrueFluentFuture;
25 import java.util.Collection;
26 import java.util.List;
27 import java.util.Optional;
29 import javax.ws.rs.container.AsyncResponse;
30 import javax.ws.rs.core.MultivaluedHashMap;
31 import javax.ws.rs.core.MultivaluedMap;
32 import javax.ws.rs.core.Response;
33 import javax.ws.rs.core.UriBuilder;
34 import javax.ws.rs.core.UriInfo;
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.junit.runner.RunWith;
38 import org.mockito.ArgumentCaptor;
39 import org.mockito.Mock;
40 import org.mockito.junit.MockitoJUnitRunner;
41 import org.opendaylight.mdsal.common.api.CommitInfo;
42 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
43 import org.opendaylight.mdsal.dom.api.DOMActionService;
44 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
45 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction;
46 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction;
47 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
48 import org.opendaylight.mdsal.dom.api.DOMMountPoint;
49 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
50 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
51 import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
52 import org.opendaylight.mdsal.dom.spi.FixedDOMSchemaService;
53 import org.opendaylight.netconf.dom.api.NetconfDataTreeService;
54 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
55 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
56 import org.opendaylight.restconf.common.patch.PatchContext;
57 import org.opendaylight.restconf.common.patch.PatchEntity;
58 import org.opendaylight.restconf.common.patch.PatchStatusContext;
59 import org.opendaylight.restconf.nb.rfc8040.AbstractJukeboxTest;
60 import org.opendaylight.restconf.nb.rfc8040.databind.DatabindContext;
61 import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
62 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfStreamsSubscriptionService;
63 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy;
64 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy;
65 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy;
66 import org.opendaylight.restconf.nb.rfc8040.streams.StreamsConfiguration;
67 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.patch.rev170222.yang.patch.yang.patch.Edit.Operation;
68 import org.opendaylight.yangtools.yang.common.ErrorTag;
69 import org.opendaylight.yangtools.yang.common.ErrorType;
70 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
71 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
72 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
73 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
74 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
75 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
76 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
78 @RunWith(MockitoJUnitRunner.StrictStubs.class)
79 public class RestconfDataServiceImplTest extends AbstractJukeboxTest {
80 private static final NodeIdentifier PLAYLIST_NID = new NodeIdentifier(PLAYLIST_QNAME);
81 private static final NodeIdentifier LIBRARY_NID = new NodeIdentifier(LIBRARY_QNAME);
83 // config contains one child the same as in operational and one additional
84 private static final ContainerNode CONFIG_JUKEBOX = Builders.containerBuilder()
85 .withNodeIdentifier(new NodeIdentifier(JUKEBOX_QNAME))
86 .withChild(CONT_PLAYER)
87 .withChild(Builders.containerBuilder().withNodeIdentifier(LIBRARY_NID).build())
89 // operational contains one child the same as in config and one additional
90 private static final ContainerNode OPER_JUKEBOX = Builders.containerBuilder()
91 .withNodeIdentifier(new NodeIdentifier(JUKEBOX_QNAME))
92 .withChild(CONT_PLAYER)
93 .withChild(Builders.mapBuilder().withNodeIdentifier(PLAYLIST_NID).build())
96 private RestconfDataServiceImpl dataService;
99 private DOMTransactionChain domTransactionChain;
101 private UriInfo uriInfo;
103 private DOMDataTreeReadWriteTransaction readWrite;
105 private DOMDataTreeReadTransaction read;
107 private DOMDataTreeWriteTransaction write;
109 private DOMMountPointService mountPointService;
111 private DOMMountPoint mountPoint;
113 private DOMDataBroker mountDataBroker;
115 private NetconfDataTreeService netconfService;
117 private DOMActionService actionService;
119 private RestconfStreamsSubscriptionService delegRestconfSubscrService;
121 private MultivaluedMap<String, String> queryParamenters;
123 private AsyncResponse asyncResponse;
126 public void setUp() throws Exception {
127 doReturn(Set.of()).when(queryParamenters).entrySet();
128 doReturn(queryParamenters).when(uriInfo).getQueryParameters();
130 doReturn(CommitInfo.emptyFluentFuture()).when(readWrite).commit();
132 final var dataBroker = mock(DOMDataBroker.class);
133 doReturn(read).when(dataBroker).newReadOnlyTransaction();
134 doReturn(readWrite).when(dataBroker).newReadWriteTransaction();
136 dataService = new RestconfDataServiceImpl(() -> DatabindContext.ofModel(JUKEBOX_SCHEMA), dataBroker,
137 mountPointService, delegRestconfSubscrService, actionService, new StreamsConfiguration(0, 1, 0, false));
138 doReturn(Optional.of(mountPoint)).when(mountPointService)
139 .getMountPoint(any(YangInstanceIdentifier.class));
140 doReturn(Optional.of(FixedDOMSchemaService.of(JUKEBOX_SCHEMA))).when(mountPoint)
141 .getService(DOMSchemaService.class);
142 doReturn(Optional.of(mountDataBroker)).when(mountPoint).getService(DOMDataBroker.class);
143 doReturn(Optional.empty()).when(mountPoint).getService(NetconfDataTreeService.class);
144 doReturn(read).when(mountDataBroker).newReadOnlyTransaction();
145 doReturn(readWrite).when(mountDataBroker).newReadWriteTransaction();
149 public void testReadData() {
150 doReturn(new MultivaluedHashMap<>()).when(uriInfo).getQueryParameters();
151 doReturn(immediateFluentFuture(Optional.of(EMPTY_JUKEBOX))).when(read)
152 .read(LogicalDatastoreType.CONFIGURATION, JUKEBOX_IID);
153 doReturn(immediateFluentFuture(Optional.empty()))
154 .when(read).read(LogicalDatastoreType.OPERATIONAL, JUKEBOX_IID);
155 final Response response = dataService.readData("example-jukebox:jukebox", uriInfo);
156 assertNotNull(response);
157 assertEquals(200, response.getStatus());
158 assertEquals(EMPTY_JUKEBOX, ((NormalizedNodePayload) response.getEntity()).getData());
162 public void testReadRootData() {
163 doReturn(new MultivaluedHashMap<>()).when(uriInfo).getQueryParameters();
164 doReturn(immediateFluentFuture(Optional.of(wrapNodeByDataRootContainer(CONFIG_JUKEBOX))))
166 .read(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.of());
167 doReturn(immediateFluentFuture(Optional.of(wrapNodeByDataRootContainer(OPER_JUKEBOX))))
169 .read(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.of());
170 final Response response = dataService.readData(uriInfo);
171 assertNotNull(response);
172 assertEquals(200, response.getStatus());
174 final NormalizedNode data = ((NormalizedNodePayload) response.getEntity()).getData();
175 assertTrue(data instanceof ContainerNode);
176 final Collection<DataContainerChild> rootNodes = ((ContainerNode) data).body();
177 assertEquals(1, rootNodes.size());
178 final Collection<DataContainerChild> allDataChildren = ((ContainerNode) rootNodes.iterator().next()).body();
179 assertEquals(3, allDataChildren.size());
182 private static ContainerNode wrapNodeByDataRootContainer(final DataContainerChild data) {
183 return Builders.containerBuilder()
184 .withNodeIdentifier(NodeIdentifier.create(SchemaContext.NAME))
190 * Test read data from mount point when both {@link LogicalDatastoreType#CONFIGURATION} and
191 * {@link LogicalDatastoreType#OPERATIONAL} contains the same data and some additional data to be merged.
194 public void testReadDataMountPoint() {
195 doReturn(new MultivaluedHashMap<>()).when(uriInfo).getQueryParameters();
196 doReturn(immediateFluentFuture(Optional.of(CONFIG_JUKEBOX))).when(read)
197 .read(LogicalDatastoreType.CONFIGURATION, JUKEBOX_IID);
198 doReturn(immediateFluentFuture(Optional.of(OPER_JUKEBOX))).when(read)
199 .read(LogicalDatastoreType.OPERATIONAL, JUKEBOX_IID);
201 final Response response = dataService.readData(
202 "example-jukebox:jukebox/yang-ext:mount/example-jukebox:jukebox", uriInfo);
204 assertNotNull(response);
205 assertEquals(200, response.getStatus());
207 // response must contain all child nodes from config and operational containers merged in one container
208 final NormalizedNode data = ((NormalizedNodePayload) response.getEntity()).getData();
209 assertTrue(data instanceof ContainerNode);
210 assertEquals(3, ((ContainerNode) data).size());
211 assertNotNull(((ContainerNode) data).childByArg(CONT_PLAYER.name()));
212 assertNotNull(((ContainerNode) data).childByArg(LIBRARY_NID));
213 assertNotNull(((ContainerNode) data).childByArg(PLAYLIST_NID));
217 public void testReadDataNoData() {
218 doReturn(new MultivaluedHashMap<>()).when(uriInfo).getQueryParameters();
219 doReturn(immediateFluentFuture(Optional.empty()))
220 .when(read).read(LogicalDatastoreType.CONFIGURATION, JUKEBOX_IID);
221 doReturn(immediateFluentFuture(Optional.empty()))
222 .when(read).read(LogicalDatastoreType.OPERATIONAL, JUKEBOX_IID);
224 final var errors = assertThrows(RestconfDocumentedException.class,
225 () -> dataService.readData("example-jukebox:jukebox", uriInfo)).getErrors();
226 assertEquals(1, errors.size());
227 final var error = errors.get(0);
228 assertEquals(ErrorType.PROTOCOL, error.getErrorType());
229 assertEquals(ErrorTag.DATA_MISSING, error.getErrorTag());
230 assertEquals("Request could not be completed because the relevant data model content does not exist",
231 error.getErrorMessage());
235 * Read data from config datastore according to content parameter.
238 public void testReadDataConfigTest() {
239 final MultivaluedHashMap<String, String> parameters = new MultivaluedHashMap<>();
240 parameters.put("content", List.of("config"));
242 doReturn(parameters).when(uriInfo).getQueryParameters();
243 doReturn(immediateFluentFuture(Optional.of(CONFIG_JUKEBOX))).when(read)
244 .read(LogicalDatastoreType.CONFIGURATION, JUKEBOX_IID);
246 final Response response = dataService.readData("example-jukebox:jukebox", uriInfo);
248 assertNotNull(response);
249 assertEquals(200, response.getStatus());
251 // response must contain only config data
252 final NormalizedNode data = ((NormalizedNodePayload) response.getEntity()).getData();
254 // config data present
255 assertNotNull(((ContainerNode) data).childByArg(CONT_PLAYER.name()));
256 assertNotNull(((ContainerNode) data).childByArg(LIBRARY_NID));
259 assertNull(((ContainerNode) data).childByArg(PLAYLIST_NID));
263 * Read data from operational datastore according to content parameter.
266 public void testReadDataOperationalTest() {
267 final MultivaluedHashMap<String, String> parameters = new MultivaluedHashMap<>();
268 parameters.put("content", List.of("nonconfig"));
270 doReturn(parameters).when(uriInfo).getQueryParameters();
271 doReturn(immediateFluentFuture(Optional.of(OPER_JUKEBOX))).when(read)
272 .read(LogicalDatastoreType.OPERATIONAL, JUKEBOX_IID);
274 final Response response = dataService.readData("example-jukebox:jukebox", uriInfo);
276 assertNotNull(response);
277 assertEquals(200, response.getStatus());
279 // response must contain only operational data
280 final NormalizedNode data = ((NormalizedNodePayload) response.getEntity()).getData();
282 // state data present
283 assertNotNull(((ContainerNode) data).childByArg(CONT_PLAYER.name()));
284 assertNotNull(((ContainerNode) data).childByArg(PLAYLIST_NID));
286 // config data absent
287 assertNull(((ContainerNode) data).childByArg(LIBRARY_NID));
291 public void testPutData() {
292 final InstanceIdentifierContext iidContext = InstanceIdentifierContext.ofLocalPath(JUKEBOX_SCHEMA, JUKEBOX_IID);
293 final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, EMPTY_JUKEBOX);
295 doReturn(immediateTrueFluentFuture()).when(read)
296 .exists(LogicalDatastoreType.CONFIGURATION, JUKEBOX_IID);
297 doNothing().when(readWrite).put(LogicalDatastoreType.CONFIGURATION, JUKEBOX_IID, EMPTY_JUKEBOX);
298 final Response response = dataService.putData(null, payload, uriInfo);
299 assertNotNull(response);
300 assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
304 public void testPutDataWithMountPoint() {
305 final InstanceIdentifierContext iidContext =
306 InstanceIdentifierContext.ofMountPointPath(mountPoint, JUKEBOX_SCHEMA, JUKEBOX_IID);
307 final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, EMPTY_JUKEBOX);
309 doReturn(immediateTrueFluentFuture()).when(read)
310 .exists(LogicalDatastoreType.CONFIGURATION, JUKEBOX_IID);
311 doNothing().when(readWrite).put(LogicalDatastoreType.CONFIGURATION, JUKEBOX_IID, EMPTY_JUKEBOX);
312 final Response response = dataService.putData(null, payload, uriInfo);
313 assertNotNull(response);
314 assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
318 public void testPostData() {
319 doReturn(new MultivaluedHashMap<>()).when(uriInfo).getQueryParameters();
320 final var node = JUKEBOX_IID.node(BAND_ENTRY.name());
321 doReturn(immediateFalseFluentFuture()).when(readWrite).exists(LogicalDatastoreType.CONFIGURATION, node);
322 doNothing().when(readWrite).put(LogicalDatastoreType.CONFIGURATION, node, BAND_ENTRY);
323 doReturn(UriBuilder.fromUri("http://localhost:8181/rests/")).when(uriInfo).getBaseUriBuilder();
325 final var response = dataService.postData(NormalizedNodePayload.of(
326 InstanceIdentifierContext.ofLocalPath(JUKEBOX_SCHEMA, JUKEBOX_IID),
327 Builders.mapBuilder().withNodeIdentifier(PLAYLIST_NID).withChild(BAND_ENTRY).build()),
329 assertEquals(201, response.getStatus());
330 assertEquals(URI.create("http://localhost:8181/rests/data/example-jukebox:jukebox"), response.getLocation());
334 public void testPostMapEntryData() {
335 doReturn(new MultivaluedHashMap<>()).when(uriInfo).getQueryParameters();
336 final var node = PLAYLIST_IID.node(BAND_ENTRY.name());
337 doReturn(immediateFalseFluentFuture()).when(readWrite).exists(LogicalDatastoreType.CONFIGURATION, node);
338 doNothing().when(readWrite).put(LogicalDatastoreType.CONFIGURATION, node, BAND_ENTRY);
339 doReturn(UriBuilder.fromUri("http://localhost:8181/rests/")).when(uriInfo).getBaseUriBuilder();
341 final var response = dataService.postData(NormalizedNodePayload.of(
342 InstanceIdentifierContext.ofLocalPath(JUKEBOX_SCHEMA, PLAYLIST_IID),
343 Builders.mapBuilder().withNodeIdentifier(PLAYLIST_NID).withChild(BAND_ENTRY).build()),
345 assertEquals(201, response.getStatus());
346 assertEquals(URI.create("http://localhost:8181/rests/data/example-jukebox:jukebox/playlist=name%20of%20band"),
347 response.getLocation());
351 public void testDeleteData() {
352 doNothing().when(readWrite).delete(LogicalDatastoreType.CONFIGURATION, JUKEBOX_IID);
353 doReturn(immediateTrueFluentFuture())
354 .when(readWrite).exists(LogicalDatastoreType.CONFIGURATION, JUKEBOX_IID);
355 final var captor = ArgumentCaptor.forClass(Response.class);
356 doReturn(true).when(asyncResponse).resume(captor.capture());
357 dataService.deleteData("example-jukebox:jukebox", asyncResponse);
359 assertEquals(204, captor.getValue().getStatus());
363 public void testDeleteDataNotExisting() {
364 doReturn(immediateFalseFluentFuture())
365 .when(readWrite).exists(LogicalDatastoreType.CONFIGURATION, JUKEBOX_IID);
366 final var captor = ArgumentCaptor.forClass(RestconfDocumentedException.class);
367 doReturn(true).when(asyncResponse).resume(captor.capture());
368 dataService.deleteData("example-jukebox:jukebox", asyncResponse);
370 final var errors = captor.getValue().getErrors();
371 assertEquals(1, errors.size());
372 final var error = errors.get(0);
373 assertEquals(ErrorType.PROTOCOL, error.getErrorType());
374 assertEquals(ErrorTag.DATA_MISSING, error.getErrorTag());
378 * Test of deleting data on mount point.
381 public void testDeleteDataMountPoint() {
382 doNothing().when(readWrite).delete(LogicalDatastoreType.CONFIGURATION, JUKEBOX_IID);
383 doReturn(immediateTrueFluentFuture())
384 .when(readWrite).exists(LogicalDatastoreType.CONFIGURATION, JUKEBOX_IID);
385 final var captor = ArgumentCaptor.forClass(Response.class);
386 doReturn(true).when(asyncResponse).resume(captor.capture());
387 dataService.deleteData("example-jukebox:jukebox/yang-ext:mount/example-jukebox:jukebox", asyncResponse);
389 assertEquals(204, captor.getValue().getStatus());
393 public void testPatchData() {
394 final InstanceIdentifierContext iidContext = InstanceIdentifierContext.ofLocalPath(JUKEBOX_SCHEMA, JUKEBOX_IID);
395 final PatchContext patch = new PatchContext(iidContext, List.of(
396 new PatchEntity("create data", Operation.Create, JUKEBOX_IID, EMPTY_JUKEBOX),
397 new PatchEntity("replace data", Operation.Replace, JUKEBOX_IID, EMPTY_JUKEBOX),
398 new PatchEntity("delete data", Operation.Delete, GAP_IID)), "test patch id");
400 doNothing().when(readWrite).delete(LogicalDatastoreType.CONFIGURATION, GAP_IID);
401 doReturn(immediateFalseFluentFuture())
402 .when(readWrite).exists(LogicalDatastoreType.CONFIGURATION, JUKEBOX_IID);
403 doReturn(immediateTrueFluentFuture())
404 .when(readWrite).exists(LogicalDatastoreType.CONFIGURATION, GAP_IID);
405 final PatchStatusContext status = dataService.yangPatchData(iidContext, patch);
406 assertTrue(status.ok());
407 assertEquals(3, status.editCollection().size());
408 assertEquals("replace data", status.editCollection().get(1).getEditId());
412 public void testPatchDataMountPoint() throws Exception {
413 final InstanceIdentifierContext iidContext = InstanceIdentifierContext.ofMountPointPath(mountPoint,
414 JUKEBOX_SCHEMA, JUKEBOX_IID);
415 final PatchContext patch = new PatchContext(iidContext, List.of(
416 new PatchEntity("create data", Operation.Create, JUKEBOX_IID, EMPTY_JUKEBOX),
417 new PatchEntity("replace data", Operation.Replace, JUKEBOX_IID, EMPTY_JUKEBOX),
418 new PatchEntity("delete data", Operation.Delete, GAP_IID)), "test patch id");
420 doNothing().when(readWrite).delete(LogicalDatastoreType.CONFIGURATION, GAP_IID);
421 doReturn(immediateFalseFluentFuture())
422 .when(readWrite).exists(LogicalDatastoreType.CONFIGURATION, JUKEBOX_IID);
423 doReturn(immediateTrueFluentFuture()).when(readWrite).exists(LogicalDatastoreType.CONFIGURATION, GAP_IID);
425 final PatchStatusContext status = dataService.yangPatchData(iidContext, patch);
426 assertTrue(status.ok());
427 assertEquals(3, status.editCollection().size());
428 assertNull(status.globalErrors());
432 public void testPatchDataDeleteNotExist() {
433 final InstanceIdentifierContext iidContext = InstanceIdentifierContext.ofLocalPath(JUKEBOX_SCHEMA, JUKEBOX_IID);
434 final PatchContext patch = new PatchContext(iidContext, List.of(
435 new PatchEntity("create data", Operation.Create, JUKEBOX_IID, EMPTY_JUKEBOX),
436 new PatchEntity("remove data", Operation.Remove, GAP_IID),
437 new PatchEntity("delete data", Operation.Delete, GAP_IID)), "test patch id");
439 doNothing().when(readWrite).delete(LogicalDatastoreType.CONFIGURATION, GAP_IID);
440 doReturn(immediateFalseFluentFuture())
441 .when(readWrite).exists(LogicalDatastoreType.CONFIGURATION, JUKEBOX_IID);
442 doReturn(immediateFalseFluentFuture())
443 .when(readWrite).exists(LogicalDatastoreType.CONFIGURATION, GAP_IID);
444 doReturn(true).when(readWrite).cancel();
445 final PatchStatusContext status = dataService.yangPatchData(iidContext, patch);
447 assertFalse(status.ok());
448 assertEquals(3, status.editCollection().size());
449 assertTrue(status.editCollection().get(0).isOk());
450 assertTrue(status.editCollection().get(1).isOk());
451 assertFalse(status.editCollection().get(2).isOk());
452 assertFalse(status.editCollection().get(2).getEditErrors().isEmpty());
453 final String errorMessage = status.editCollection().get(2).getEditErrors().get(0).getErrorMessage();
454 assertEquals("Data does not exist", errorMessage);
458 public void testGetRestconfStrategy() {
459 RestconfStrategy restconfStrategy = dataService.getRestconfStrategy(mountPoint);
460 assertTrue(restconfStrategy instanceof MdsalRestconfStrategy);
462 doReturn(Optional.of(netconfService)).when(mountPoint).getService(NetconfDataTreeService.class);
463 restconfStrategy = dataService.getRestconfStrategy(mountPoint);
464 assertTrue(restconfStrategy instanceof NetconfRestconfStrategy);
468 public void testValidInputData() {
469 RestconfDataServiceImpl.validInputData(true, NormalizedNodePayload.of(
470 InstanceIdentifierContext.ofLocalPath(JUKEBOX_SCHEMA, GAP_IID), GAP_LEAF));
474 public void testValidTopLevelNodeName() {
475 RestconfDataServiceImpl.validTopLevelNodeName(GAP_IID, NormalizedNodePayload.of(
476 InstanceIdentifierContext.ofLocalPath(JUKEBOX_SCHEMA, GAP_IID), GAP_LEAF));
477 RestconfDataServiceImpl.validTopLevelNodeName(JUKEBOX_IID, NormalizedNodePayload.of(
478 InstanceIdentifierContext.ofLocalPath(JUKEBOX_SCHEMA, JUKEBOX_IID), EMPTY_JUKEBOX));
482 public void testValidTopLevelNodeNamePathEmpty() {
483 final var iidContext = InstanceIdentifierContext.ofLocalPath(JUKEBOX_SCHEMA, GAP_IID);
484 final var payload = NormalizedNodePayload.of(iidContext, GAP_LEAF);
486 // FIXME: more asserts
487 assertThrows(RestconfDocumentedException.class,
488 () -> RestconfDataServiceImpl.validTopLevelNodeName(YangInstanceIdentifier.of(), payload));
492 public void testValidTopLevelNodeNameWrongTopIdentifier() {
493 final var iidContext = InstanceIdentifierContext.ofLocalPath(JUKEBOX_SCHEMA, GAP_IID);
494 final var payload = NormalizedNodePayload.of(iidContext, GAP_LEAF);
496 // FIXME: more asserts
497 assertThrows(RestconfDocumentedException.class,
498 () -> RestconfDataServiceImpl.validTopLevelNodeName(GAP_IID.getAncestor(1), payload));
502 public void testValidateListKeysEqualityInPayloadAndUri() {
503 final var iidContext = InstanceIdentifierContext.ofLocalPath(JUKEBOX_SCHEMA, YangInstanceIdentifier.builder()
505 .node(PLAYLIST_QNAME)
506 .nodeWithKey(PLAYLIST_QNAME, NAME_QNAME, "name of band")
508 final NormalizedNodePayload payload = NormalizedNodePayload.of(iidContext, BAND_ENTRY);
509 RestconfDataServiceImpl.validateListKeysEqualityInPayloadAndUri(payload);