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.utils.parser;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
13 import static org.junit.Assert.fail;
14 import static org.mockito.Mockito.doReturn;
15 import static org.mockito.Mockito.when;
17 import com.google.common.collect.Sets;
18 import java.util.Collections;
19 import java.util.List;
20 import java.util.Optional;
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.junit.runner.RunWith;
25 import org.mockito.Mock;
26 import org.mockito.junit.MockitoJUnitRunner;
27 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
28 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
29 import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
30 import org.opendaylight.restconf.common.errors.RestconfError.ErrorType;
31 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
32 import org.opendaylight.yangtools.yang.common.QName;
33 import org.opendaylight.yangtools.yang.common.QNameModule;
34 import org.opendaylight.yangtools.yang.common.Revision;
35 import org.opendaylight.yangtools.yang.common.XMLNamespace;
36 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
37 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
38 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
39 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
40 import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
41 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
42 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
43 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
44 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
45 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
46 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
49 * Unit test for {@link ParserFieldsParameter}.
51 @RunWith(MockitoJUnitRunner.class)
52 public class ParserFieldsParameterTest {
55 private InstanceIdentifierContext<ContainerSchemaNode> identifierJukebox;
58 private InstanceIdentifierContext<ContainerSchemaNode> identifierTestServices;
60 private static final QNameModule Q_NAME_MODULE_JUKEBOX = QNameModule.create(
61 XMLNamespace.of("http://example.com/ns/example-jukebox"), Revision.of("2015-04-04"));
62 private static final QNameModule Q_NAME_MODULE_TEST_SERVICES = QNameModule.create(
63 XMLNamespace.of("tests:test-services"), Revision.of("2019-03-25"));
64 private static final QNameModule Q_NAME_MODULE_AUGMENTED_JUKEBOX = QNameModule.create(
65 XMLNamespace.of("http://example.com/ns/augmented-jukebox"), Revision.of("2016-05-05"));
69 private ContainerSchemaNode containerJukebox;
70 private static final QName JUKEBOX_Q_NAME = QName.create(Q_NAME_MODULE_JUKEBOX, "jukebox");
74 private ContainerSchemaNode containerPlayer;
75 private static final QName PLAYER_Q_NAME = QName.create(Q_NAME_MODULE_JUKEBOX, "player");
79 private ContainerSchemaNode containerLibrary;
80 private static final QName LIBRARY_Q_NAME = QName.create(Q_NAME_MODULE_JUKEBOX, "library");
82 // container augmented library
84 private ContainerSchemaNode augmentedContainerLibrary;
85 private static final QName AUGMENTED_LIBRARY_Q_NAME = QName.create(Q_NAME_MODULE_AUGMENTED_JUKEBOX,
88 // augmentation that contains speed leaf
90 private AugmentationSchemaNode speedAugmentation;
94 private LeafSchemaNode leafSpeed;
95 private static final QName SPEED_Q_NAME = QName.create(Q_NAME_MODULE_AUGMENTED_JUKEBOX, "speed");
99 private ListSchemaNode listAlbum;
100 private static final QName ALBUM_Q_NAME = QName.create(Q_NAME_MODULE_JUKEBOX, "album");
104 private LeafSchemaNode leafName;
105 private static final QName NAME_Q_NAME = QName.create(Q_NAME_MODULE_JUKEBOX, "name");
107 // container test data
109 private ContainerSchemaNode containerTestData;
110 private static final QName TEST_DATA_Q_NAME = QName.create(Q_NAME_MODULE_TEST_SERVICES, "test-data");
114 private ListSchemaNode listServices;
115 private static final QName SERVICES_Q_NAME = QName.create(Q_NAME_MODULE_TEST_SERVICES, "services");
117 // leaf type-of-service
119 private LeafSchemaNode leafTypeOfService;
120 private static final QName TYPE_OF_SERVICE_Q_NAME = QName.create(Q_NAME_MODULE_TEST_SERVICES, "type-of-service");
124 private ListSchemaNode listInstance;
125 private static final QName INSTANCE_Q_NAME = QName.create(Q_NAME_MODULE_TEST_SERVICES, "instance");
127 // leaf instance-name
129 private LeafSchemaNode leafInstanceName;
130 private static final QName INSTANCE_NAME_Q_NAME = QName.create(Q_NAME_MODULE_TEST_SERVICES, "instance-name");
134 private LeafSchemaNode leafProvider;
135 private static final QName PROVIDER_Q_NAME = QName.create(Q_NAME_MODULE_TEST_SERVICES, "provider");
137 // container next-data
139 private ContainerSchemaNode containerNextData;
140 private static final QName NEXT_DATA_Q_NAME = QName.create(Q_NAME_MODULE_TEST_SERVICES, "next-data");
144 private LeafSchemaNode leafNextService;
145 private static final QName NEXT_SERVICE_Q_NAME = QName.create(Q_NAME_MODULE_TEST_SERVICES, "next-service");
147 // leaf-list protocols
149 private LeafListSchemaNode leafListProtocols;
150 private static final QName PROTOCOLS_Q_NAME = QName.create(Q_NAME_MODULE_TEST_SERVICES, "protocols");
153 public void setUp() throws Exception {
154 final EffectiveModelContext schemaContextJukebox =
155 YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/jukebox"));
156 initJukeboxSchemaNodes(schemaContextJukebox);
158 final EffectiveModelContext schemaContextTestServices =
159 YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/test-services"));
160 initTestServicesSchemaNodes(schemaContextTestServices);
163 private void initJukeboxSchemaNodes(final EffectiveModelContext schemaContext) {
164 when(identifierJukebox.getSchemaContext()).thenReturn(schemaContext);
165 when(containerJukebox.getQName()).thenReturn(JUKEBOX_Q_NAME);
166 when(identifierJukebox.getSchemaNode()).thenReturn(containerJukebox);
168 when(containerLibrary.getQName()).thenReturn(LIBRARY_Q_NAME);
169 when(containerJukebox.dataChildByName(LIBRARY_Q_NAME)).thenReturn(containerLibrary);
171 when(augmentedContainerLibrary.getQName()).thenReturn(AUGMENTED_LIBRARY_Q_NAME);
172 when(containerJukebox.dataChildByName(AUGMENTED_LIBRARY_Q_NAME))
173 .thenReturn(augmentedContainerLibrary);
175 when(containerPlayer.getQName()).thenReturn(PLAYER_Q_NAME);
176 when(containerJukebox.dataChildByName(PLAYER_Q_NAME)).thenReturn(containerPlayer);
178 when(listAlbum.getQName()).thenReturn(ALBUM_Q_NAME);
179 when(containerLibrary.dataChildByName(ALBUM_Q_NAME)).thenReturn(listAlbum);
181 when(leafName.getQName()).thenReturn(NAME_Q_NAME);
182 when(listAlbum.dataChildByName(NAME_Q_NAME)).thenReturn(leafName);
184 when(leafSpeed.getQName()).thenReturn(SPEED_Q_NAME);
185 when(leafSpeed.isAugmenting()).thenReturn(true);
186 when(containerPlayer.dataChildByName(SPEED_Q_NAME)).thenReturn(leafSpeed);
187 when(containerPlayer.getDataChildByName(SPEED_Q_NAME)).thenReturn(leafSpeed);
188 doReturn(Collections.singletonList(leafSpeed)).when(speedAugmentation).getChildNodes();
189 doReturn(Collections.singleton(speedAugmentation)).when(containerPlayer).getAvailableAugmentations();
190 when(speedAugmentation.findDataChildByName(SPEED_Q_NAME)).thenReturn(Optional.of(leafSpeed));
193 private void initTestServicesSchemaNodes(final EffectiveModelContext schemaContext) {
194 when(identifierTestServices.getSchemaContext()).thenReturn(schemaContext);
195 when(containerTestData.getQName()).thenReturn(TEST_DATA_Q_NAME);
196 when(identifierTestServices.getSchemaNode()).thenReturn(containerTestData);
198 when(listServices.getQName()).thenReturn(SERVICES_Q_NAME);
199 when(containerTestData.dataChildByName(SERVICES_Q_NAME)).thenReturn(listServices);
201 when(leafListProtocols.getQName()).thenReturn(PROTOCOLS_Q_NAME);
202 when(containerTestData.dataChildByName(PROTOCOLS_Q_NAME)).thenReturn(leafListProtocols);
204 when(leafTypeOfService.getQName()).thenReturn(TYPE_OF_SERVICE_Q_NAME);
205 when(listServices.dataChildByName(TYPE_OF_SERVICE_Q_NAME)).thenReturn(leafTypeOfService);
207 when(listInstance.getQName()).thenReturn(INSTANCE_Q_NAME);
208 when(listServices.dataChildByName(INSTANCE_Q_NAME)).thenReturn(listInstance);
210 when(leafInstanceName.getQName()).thenReturn(INSTANCE_NAME_Q_NAME);
211 when(listInstance.dataChildByName(INSTANCE_NAME_Q_NAME)).thenReturn(leafInstanceName);
213 when(leafProvider.getQName()).thenReturn(PROVIDER_Q_NAME);
214 when(listInstance.dataChildByName(PROVIDER_Q_NAME)).thenReturn(leafProvider);
216 when(containerNextData.getQName()).thenReturn(NEXT_DATA_Q_NAME);
217 when(listServices.dataChildByName(NEXT_DATA_Q_NAME)).thenReturn(containerNextData);
219 when(leafNextService.getQName()).thenReturn(NEXT_SERVICE_Q_NAME);
220 when(containerNextData.dataChildByName(NEXT_SERVICE_Q_NAME)).thenReturn(leafNextService);
224 * Test parse fields parameter containing only one child selected.
227 public void parseFieldsParameterSimplePathTest() {
228 final String input = "library";
229 final List<Set<QName>> parsedFields = ParserFieldsParameter.parseFieldsParameter(identifierJukebox, input);
231 assertNotNull(parsedFields);
232 assertEquals(1, parsedFields.size());
233 assertEquals(1, parsedFields.get(0).size());
234 assertTrue(parsedFields.get(0).contains(LIBRARY_Q_NAME));
238 * Test parse fields parameter containing two child nodes selected.
241 public void parseFieldsParameterDoublePathTest() {
242 final String input = "library;player";
243 final List<Set<QName>> parsedFields = ParserFieldsParameter.parseFieldsParameter(identifierJukebox, input);
245 assertNotNull(parsedFields);
246 assertEquals(1, parsedFields.size());
247 assertEquals(2, parsedFields.get(0).size());
248 assertTrue(parsedFields.get(0).contains(LIBRARY_Q_NAME));
249 assertTrue(parsedFields.get(0).contains(PLAYER_Q_NAME));
253 * Test parse fields parameter containing sub-children selected delimited by slash.
256 public void parseFieldsParameterSubPathTest() {
257 final String input = "library/album/name";
258 final List<Set<QName>> parsedFields = ParserFieldsParameter.parseFieldsParameter(identifierJukebox, input);
260 assertNotNull(parsedFields);
261 assertEquals(3, parsedFields.size());
263 assertEquals(1, parsedFields.get(0).size());
264 assertTrue(parsedFields.get(0).contains(LIBRARY_Q_NAME));
266 assertEquals(1, parsedFields.get(1).size());
267 assertTrue(parsedFields.get(1).contains(ALBUM_Q_NAME));
269 assertEquals(1, parsedFields.get(2).size());
270 assertTrue(parsedFields.get(2).contains(NAME_Q_NAME));
274 * Test parse fields parameter containing sub-children selected delimited by parenthesis.
277 public void parseFieldsParameterChildrenPathTest() {
278 final String input = "library(album(name))";
279 final List<Set<QName>> parsedFields = ParserFieldsParameter.parseFieldsParameter(identifierJukebox, input);
281 assertNotNull(parsedFields);
282 assertEquals(3, parsedFields.size());
284 assertEquals(1, parsedFields.get(0).size());
285 assertTrue(parsedFields.get(0).contains(LIBRARY_Q_NAME));
287 assertEquals(1, parsedFields.get(1).size());
288 assertTrue(parsedFields.get(1).contains(ALBUM_Q_NAME));
290 assertEquals(1, parsedFields.get(2).size());
291 assertTrue(parsedFields.get(2).contains(NAME_Q_NAME));
295 * Test parse fields parameter when augmentation with different namespace is used.
298 public void parseFieldsParameterNamespaceTest() {
299 final String input = "augmented-jukebox:augmented-library";
300 final List<Set<QName>> parsedFields = ParserFieldsParameter.parseFieldsParameter(identifierJukebox, input);
302 assertNotNull(parsedFields);
303 assertEquals(1, parsedFields.size());
305 assertEquals(1, parsedFields.get(0).size());
306 assertTrue(parsedFields.get(0).contains(AUGMENTED_LIBRARY_Q_NAME));
310 * Testing of fields parameter parsing when multiple nodes are wrapped in brackets and these nodes are not
311 * direct children of parent node - multiple children which are constructed using '/'.
314 public void parseFieldsParameterWithMultipleChildrenTest1() {
315 final String input = "services(type-of-service;instance/instance-name;instance/provider)";
316 final List<Set<QName>> parsedFields = ParserFieldsParameter.parseFieldsParameter(identifierTestServices, input);
318 assertNotNull(parsedFields);
319 assertEquals(parsedFields.size(), 3);
321 assertEquals(parsedFields.get(0).size(), 1);
322 assertTrue(parsedFields.get(0).contains(SERVICES_Q_NAME));
324 assertEquals(parsedFields.get(1).size(), 2);
325 assertTrue(parsedFields.get(1).containsAll(Sets.newHashSet(TYPE_OF_SERVICE_Q_NAME, INSTANCE_Q_NAME)));
327 assertEquals(parsedFields.get(2).size(), 2);
328 assertTrue(parsedFields.get(2).containsAll(Sets.newHashSet(INSTANCE_NAME_Q_NAME, PROVIDER_Q_NAME)));
332 * Testing of fields parameter parsing when multiple nodes are wrapped in brackets and these nodes are not
333 * direct children of parent node - one of children nodes is typed using brackets, other is constructed using '/'.
336 public void parseFieldsParameterWithMultipleChildrenTest2() {
337 final String input = "services(type-of-service;instance(instance-name;provider))";
338 final List<Set<QName>> parsedFields = ParserFieldsParameter.parseFieldsParameter(identifierTestServices, input);
340 assertNotNull(parsedFields);
341 assertEquals(parsedFields.size(), 3);
343 assertEquals(parsedFields.get(0).size(), 1);
344 assertTrue(parsedFields.get(0).contains(SERVICES_Q_NAME));
346 assertEquals(parsedFields.get(1).size(), 2);
347 assertTrue(parsedFields.get(1).containsAll(Sets.newHashSet(TYPE_OF_SERVICE_Q_NAME, INSTANCE_Q_NAME)));
349 assertEquals(parsedFields.get(2).size(), 2);
350 assertTrue(parsedFields.get(2).containsAll(Sets.newHashSet(INSTANCE_NAME_Q_NAME, PROVIDER_Q_NAME)));
354 * Testing of fields parameter parsing when multiple nodes are wrapped in brackets and these nodes are not
355 * direct children of parent node - multiple children with different parent nodes.
358 public void parseFieldsParameterWithMultipleChildrenTest3() {
359 final String input = "services(instance/instance-name;type-of-service;next-data/next-service)";
360 final List<Set<QName>> parsedFields = ParserFieldsParameter.parseFieldsParameter(identifierTestServices, input);
362 assertNotNull(parsedFields);
363 assertEquals(parsedFields.size(), 3);
365 assertEquals(parsedFields.get(0).size(), 1);
366 assertTrue(parsedFields.get(0).contains(SERVICES_Q_NAME));
368 assertEquals(parsedFields.get(1).size(), 3);
369 assertTrue(parsedFields.get(1).containsAll(
370 Sets.newHashSet(TYPE_OF_SERVICE_Q_NAME, INSTANCE_Q_NAME, NEXT_DATA_Q_NAME)));
372 assertEquals(parsedFields.get(2).size(), 2);
373 assertTrue(parsedFields.get(2).containsAll(
374 Sets.newHashSet(INSTANCE_NAME_Q_NAME, NEXT_SERVICE_Q_NAME)));
378 * Test parse fields parameter containing not expected character.
381 public void parseFieldsParameterNotExpectedCharacterNegativeTest() {
382 final String input = "*";
385 ParserFieldsParameter.parseFieldsParameter(this.identifierJukebox, input);
386 fail("Test should fail due to not expected character used in parameter input value");
387 } catch (final RestconfDocumentedException e) {
389 assertEquals("Error type is not correct", ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
390 assertEquals("Error tag is not correct", ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
391 assertEquals("Error status code is not correct", 400, e.getErrors().get(0).getErrorTag().getStatusCode());
396 * Test parse fields parameter with missing closing parenthesis.
399 public void parseFieldsParameterMissingParenthesisNegativeTest() {
400 final String input = "library(";
403 ParserFieldsParameter.parseFieldsParameter(this.identifierJukebox, input);
404 fail("Test should fail due to missing closing parenthesis");
405 } catch (final RestconfDocumentedException e) {
407 assertEquals("Error type is not correct", ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
408 assertEquals("Error tag is not correct", ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
409 assertEquals("Error status code is not correct", 400, e.getErrors().get(0).getErrorTag().getStatusCode());
414 * Test parse fields parameter when not existing child node selected.
417 public void parseFieldsParameterMissingChildNodeNegativeTest() {
418 final String input = "library(not-existing)";
421 ParserFieldsParameter.parseFieldsParameter(this.identifierJukebox, input);
422 fail("Test should fail due to missing child node in parent node");
423 } catch (final RestconfDocumentedException e) {
425 assertEquals("Error type is not correct", ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
426 assertEquals("Error tag is not correct", ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
427 assertEquals("Error status code is not correct", 400, e.getErrors().get(0).getErrorTag().getStatusCode());
432 * Test parse fields parameter with unexpected character after parenthesis.
435 public void parseFieldsParameterAfterParenthesisNegativeTest() {
436 final String input = "library(album);";
439 ParserFieldsParameter.parseFieldsParameter(this.identifierJukebox, input);
440 fail("Test should fail due to unexpected character after parenthesis");
441 } catch (final RestconfDocumentedException e) {
443 assertEquals("Error type is not correct", ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
444 assertEquals("Error tag is not correct", ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
445 assertEquals("Error status code is not correct", 400, e.getErrors().get(0).getErrorTag().getStatusCode());
450 * Test parse fields parameter with missing semicolon after parenthesis.
453 public void parseFieldsParameterMissingSemicolonNegativeTest() {
454 final String input = "library(album)player";
457 ParserFieldsParameter.parseFieldsParameter(this.identifierJukebox, input);
458 fail("Test should fail due to missing semicolon after parenthesis");
459 } catch (final RestconfDocumentedException e) {
461 assertEquals("Error type is not correct", ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
462 assertEquals("Error tag is not correct", ErrorTag.INVALID_VALUE, e.getErrors().get(0).getErrorTag());
463 assertEquals("Error status code is not correct", 400, e.getErrors().get(0).getErrorTag().getStatusCode());
468 public void parseTopLevelContainerToPathTest() {
469 final String input = "library";
470 final List<YangInstanceIdentifier> parsedFields = ParserFieldsParameter.parseFieldsPaths(
471 identifierJukebox, input);
473 assertNotNull(parsedFields);
474 assertEquals(1, parsedFields.size());
475 final List<PathArgument> pathArguments = parsedFields.get(0).getPathArguments();
476 assertEquals(1, pathArguments.size());
477 assertEquals(LIBRARY_Q_NAME, pathArguments.get(0).getNodeType());
481 public void parseTwoTopLevelContainersToPathsTest() {
482 final String input = "library;player";
483 final List<YangInstanceIdentifier> parsedFields = ParserFieldsParameter.parseFieldsPaths(
484 identifierJukebox, input);
486 assertNotNull(parsedFields);
487 assertEquals(2, parsedFields.size());
489 final Optional<YangInstanceIdentifier> libraryPath = findPath(parsedFields, LIBRARY_Q_NAME);
490 assertTrue(libraryPath.isPresent());
491 assertEquals(1, libraryPath.get().getPathArguments().size());
493 final Optional<YangInstanceIdentifier> playerPath = findPath(parsedFields, PLAYER_Q_NAME);
494 assertTrue(playerPath.isPresent());
495 assertEquals(1, libraryPath.get().getPathArguments().size());
499 public void parseNestedLeafToPathTest() {
500 final String input = "library/album/name";
501 final List<YangInstanceIdentifier> parsedFields = ParserFieldsParameter.parseFieldsPaths(
502 identifierJukebox, input);
504 assertEquals(1, parsedFields.size());
505 final List<PathArgument> pathArguments = parsedFields.get(0).getPathArguments();
506 assertEquals(3, pathArguments.size());
508 assertEquals(LIBRARY_Q_NAME, pathArguments.get(0).getNodeType());
509 assertEquals(ALBUM_Q_NAME, pathArguments.get(1).getNodeType());
510 assertEquals(NAME_Q_NAME, pathArguments.get(2).getNodeType());
514 public void parseAugmentedLeafToPathTest() {
515 final String input = "player/augmented-jukebox:speed";
516 final List<YangInstanceIdentifier> parsedFields = ParserFieldsParameter.parseFieldsPaths(
517 identifierJukebox, input);
519 assertEquals(1, parsedFields.size());
520 final List<PathArgument> pathArguments = parsedFields.get(0).getPathArguments();
522 assertEquals(3, pathArguments.size());
523 assertEquals(PLAYER_Q_NAME, pathArguments.get(0).getNodeType());
524 assertTrue(pathArguments.get(1) instanceof AugmentationIdentifier);
525 assertEquals(SPEED_Q_NAME, pathArguments.get(2).getNodeType());
529 public void parseMultipleFieldsOnDifferentLevelsToPathsTest() {
530 final String input = "services(type-of-service;instance/instance-name;instance/provider)";
531 final List<YangInstanceIdentifier> parsedFields = ParserFieldsParameter.parseFieldsPaths(
532 identifierTestServices, input);
534 assertEquals(3, parsedFields.size());
536 final Optional<YangInstanceIdentifier> tosPath = findPath(parsedFields, TYPE_OF_SERVICE_Q_NAME);
537 assertTrue(tosPath.isPresent());
538 assertEquals(2, tosPath.get().getPathArguments().size());
540 final Optional<YangInstanceIdentifier> instanceNamePath = findPath(parsedFields, INSTANCE_NAME_Q_NAME);
541 assertTrue(instanceNamePath.isPresent());
542 assertEquals(3, instanceNamePath.get().getPathArguments().size());
544 final Optional<YangInstanceIdentifier> providerPath = findPath(parsedFields, PROVIDER_Q_NAME);
545 assertTrue(providerPath.isPresent());
546 assertEquals(3, providerPath.get().getPathArguments().size());
550 public void parseListFieldUnderListToPathTest() {
551 final String input = "services/instance";
552 final List<YangInstanceIdentifier> parsedFields = ParserFieldsParameter.parseFieldsPaths(
553 identifierTestServices, input);
555 assertEquals(1, parsedFields.size());
556 final List<PathArgument> pathArguments = parsedFields.get(0).getPathArguments();
557 assertEquals(2, pathArguments.size());
559 assertEquals(SERVICES_Q_NAME, pathArguments.get(0).getNodeType());
560 assertTrue(pathArguments.get(0) instanceof NodeIdentifier);
561 assertEquals(INSTANCE_Q_NAME, pathArguments.get(1).getNodeType());
562 assertTrue(pathArguments.get(1) instanceof NodeIdentifier);
566 public void parseLeafListFieldToPathTest() {
567 final String input = "protocols";
568 final List<YangInstanceIdentifier> parsedFields = ParserFieldsParameter.parseFieldsPaths(
569 identifierTestServices, input);
571 assertEquals(1, parsedFields.size());
572 final List<PathArgument> pathArguments = parsedFields.get(0).getPathArguments();
573 assertEquals(1, pathArguments.size());
574 assertTrue(pathArguments.get(0) instanceof NodeIdentifier);
575 assertEquals(PROTOCOLS_Q_NAME, pathArguments.get(0).getNodeType());
578 private static Optional<YangInstanceIdentifier> findPath(final List<YangInstanceIdentifier> paths,
579 final QName lastPathArg) {
580 return paths.stream()
581 .filter(path -> lastPathArg.equals(path.getLastPathArgument().getNodeType()))