2 * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.yangtools.yang.data.util;
10 import static org.junit.jupiter.api.Assertions.assertEquals;
11 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
14 import org.junit.jupiter.api.AfterAll;
15 import org.junit.jupiter.api.BeforeAll;
16 import org.junit.jupiter.api.Test;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.common.QNameModule;
19 import org.opendaylight.yangtools.yang.common.XMLNamespace;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
22 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
23 import org.opendaylight.yangtools.yang.model.api.stmt.ChoiceEffectiveStatement;
24 import org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement;
25 import org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement;
26 import org.opendaylight.yangtools.yang.model.api.stmt.ListEffectiveStatement;
27 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
28 import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
29 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
32 private static final QNameModule MODULE = QNameModule.create(XMLNamespace.of("foo"));
33 private static final QName ONE = QName.create(MODULE, "one");
34 private static final QName TWO = QName.create(MODULE, "two");
35 private static final QName THREE = QName.create(MODULE, "three");
36 private static final QName FOUR = QName.create(MODULE, "four");
37 private static final QName FIVE = QName.create(MODULE, "five");
38 private static final QName SIX = QName.create(MODULE, "six");
40 private static DataSchemaContextTree CONTEXT;
42 private final SchemaInferenceStack stack = SchemaInferenceStack.of(CONTEXT.getEffectiveModelContext());
46 CONTEXT = DataSchemaContextTree.from(YangParserTestUtils.parseYangResource("/yt1412.yang"));
50 static void cleanup() {
55 void testEnterThroughChoice() {
56 final var one = assertInstanceOf(ContainerContextNode.class, CONTEXT.getRoot().enterChild(stack, ONE));
57 assertInstanceOf(ContainerEffectiveStatement.class, stack.currentStatement());
59 final var two = assertInstanceOf(ChoiceNodeContextNode.class, one.enterChild(FOUR, stack));
60 assertInstanceOf(ChoiceEffectiveStatement.class, stack.currentStatement());
62 final var three = assertInstanceOf(ChoiceNodeContextNode.class, two.enterChild(FOUR, stack));
63 assertInstanceOf(ChoiceEffectiveStatement.class, stack.currentStatement());
65 assertInstanceOf(LeafContextNode.class, three.enterChild(FOUR, stack));
66 assertInstanceOf(LeafEffectiveStatement.class, stack.currentStatement());
68 assertEquals(Absolute.of(ONE, TWO, THREE, THREE, FOUR, FOUR), stack.toSchemaNodeIdentifier());
72 void testEnterThroughAugment() {
73 final var one = assertInstanceOf(ContainerContextNode.class, CONTEXT.getRoot().enterChild(stack, ONE));
74 assertInstanceOf(ContainerEffectiveStatement.class, stack.currentStatement());
76 final var augment = assertInstanceOf(AugmentationContextNode.class, one.enterChild(FIVE, stack));
77 assertInstanceOf(ContainerEffectiveStatement.class, stack.currentStatement());
79 final var five = assertInstanceOf(UnkeyedListMixinContextNode.class, augment.enterChild(FIVE, stack));
80 assertInstanceOf(ListEffectiveStatement.class, stack.currentStatement());
82 assertInstanceOf(UnkeyedListItemContextNode.class, five.enterChild(FIVE, stack));
83 assertInstanceOf(ListEffectiveStatement.class, stack.currentStatement());
85 assertEquals(Absolute.of(ONE, FIVE), stack.toSchemaNodeIdentifier());
89 void testEnterThroughAugmentChoiceAugment() {
90 final var one = assertInstanceOf(ContainerContextNode.class, CONTEXT.getRoot().enterChild(stack, ONE));
91 assertInstanceOf(ContainerEffectiveStatement.class, stack.currentStatement());
93 final var two = assertInstanceOf(ChoiceNodeContextNode.class, one.enterChild(SIX, stack));
94 assertInstanceOf(ChoiceEffectiveStatement.class, stack.currentStatement());
96 final var three = assertInstanceOf(ChoiceNodeContextNode.class, two.enterChild(SIX, stack));
97 assertInstanceOf(ChoiceEffectiveStatement.class, stack.currentStatement());
99 assertInstanceOf(LeafContextNode.class, three.enterChild(SIX, stack));
100 assertInstanceOf(LeafEffectiveStatement.class, stack.currentStatement());
102 assertEquals(Absolute.of(ONE, TWO, THREE, THREE, SIX, SIX), stack.toSchemaNodeIdentifier());
106 void testEnterChoicePath() {
107 final var result = CONTEXT.enterPath(YangInstanceIdentifier.create(
108 new NodeIdentifier(ONE),
109 new NodeIdentifier(TWO),
110 new NodeIdentifier(THREE),
111 new NodeIdentifier(FOUR)))
114 assertInstanceOf(LeafContextNode.class, result.node());
115 assertEquals(Absolute.of(ONE, TWO, THREE, THREE, FOUR, FOUR), result.stack().toSchemaNodeIdentifier());
119 void testEnterAugmentPath() {
120 final var result = CONTEXT.enterPath(YangInstanceIdentifier.create(
121 new NodeIdentifier(ONE),
122 new AugmentationIdentifier(Set.of(FIVE)),
123 new NodeIdentifier(FIVE),
124 new NodeIdentifier(FIVE)))
127 assertInstanceOf(UnkeyedListItemContextNode.class, result.node());
128 assertEquals(Absolute.of(ONE, FIVE), result.stack().toSchemaNodeIdentifier());
132 void testEnterAugmentChoicePath() {
133 final var result = CONTEXT.enterPath(YangInstanceIdentifier.create(
134 new NodeIdentifier(ONE),
135 new NodeIdentifier(TWO),
136 new NodeIdentifier(THREE),
137 new NodeIdentifier(SIX)))
140 assertInstanceOf(LeafContextNode.class, result.node());
141 assertEquals(Absolute.of(ONE, TWO, THREE, THREE, SIX, SIX), result.stack().toSchemaNodeIdentifier());