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;
13 import org.junit.jupiter.api.AfterAll;
14 import org.junit.jupiter.api.BeforeAll;
15 import org.junit.jupiter.api.Test;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.common.QNameModule;
18 import org.opendaylight.yangtools.yang.common.XMLNamespace;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
21 import org.opendaylight.yangtools.yang.model.api.stmt.ChoiceEffectiveStatement;
22 import org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement;
23 import org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement;
24 import org.opendaylight.yangtools.yang.model.api.stmt.ListEffectiveStatement;
25 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
26 import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
27 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
30 private static final QNameModule MODULE = QNameModule.create(XMLNamespace.of("foo"));
31 private static final QName ONE = QName.create(MODULE, "one");
32 private static final QName TWO = QName.create(MODULE, "two");
33 private static final QName THREE = QName.create(MODULE, "three");
34 private static final QName FOUR = QName.create(MODULE, "four");
35 private static final QName FIVE = QName.create(MODULE, "five");
36 private static final QName SIX = QName.create(MODULE, "six");
38 private static DataSchemaContextTree CONTEXT;
40 private final SchemaInferenceStack stack = SchemaInferenceStack.of(CONTEXT.getEffectiveModelContext());
44 CONTEXT = DataSchemaContextTree.from(YangParserTestUtils.parseYangResource("/yt1412.yang"));
48 static void cleanup() {
53 void testEnterThroughChoice() {
54 final var one = assertInstanceOf(ContainerContextNode.class, CONTEXT.getRoot().enterChild(stack, ONE));
55 assertInstanceOf(ContainerEffectiveStatement.class, stack.currentStatement());
57 final var two = assertInstanceOf(ChoiceNodeContextNode.class, one.enterChild(FOUR, stack));
58 assertInstanceOf(ChoiceEffectiveStatement.class, stack.currentStatement());
60 final var three = assertInstanceOf(ChoiceNodeContextNode.class, two.enterChild(FOUR, stack));
61 assertInstanceOf(ChoiceEffectiveStatement.class, stack.currentStatement());
63 assertInstanceOf(LeafContextNode.class, three.enterChild(FOUR, stack));
64 assertInstanceOf(LeafEffectiveStatement.class, stack.currentStatement());
66 assertEquals(Absolute.of(ONE, TWO, THREE, THREE, FOUR, FOUR), stack.toSchemaNodeIdentifier());
70 void testEnterThroughAugment() {
71 final var one = assertInstanceOf(ContainerContextNode.class, CONTEXT.getRoot().enterChild(stack, ONE));
72 assertInstanceOf(ContainerEffectiveStatement.class, stack.currentStatement());
74 final var five = assertInstanceOf(UnkeyedListMixinContextNode.class, one.enterChild(FIVE, stack));
75 assertInstanceOf(ListEffectiveStatement.class, stack.currentStatement());
77 assertInstanceOf(UnkeyedListItemContextNode.class, five.enterChild(FIVE, stack));
78 assertInstanceOf(ListEffectiveStatement.class, stack.currentStatement());
80 assertEquals(Absolute.of(ONE, FIVE), stack.toSchemaNodeIdentifier());
84 void testEnterThroughAugmentChoiceAugment() {
85 final var one = assertInstanceOf(ContainerContextNode.class, CONTEXT.getRoot().enterChild(stack, ONE));
86 assertInstanceOf(ContainerEffectiveStatement.class, stack.currentStatement());
88 final var two = assertInstanceOf(ChoiceNodeContextNode.class, one.enterChild(SIX, stack));
89 assertInstanceOf(ChoiceEffectiveStatement.class, stack.currentStatement());
91 final var three = assertInstanceOf(ChoiceNodeContextNode.class, two.enterChild(SIX, stack));
92 assertInstanceOf(ChoiceEffectiveStatement.class, stack.currentStatement());
94 assertInstanceOf(LeafContextNode.class, three.enterChild(SIX, stack));
95 assertInstanceOf(LeafEffectiveStatement.class, stack.currentStatement());
97 assertEquals(Absolute.of(ONE, TWO, THREE, THREE, SIX, SIX), stack.toSchemaNodeIdentifier());
101 void testEnterChoicePath() {
102 final var result = CONTEXT.enterPath(YangInstanceIdentifier.create(
103 new NodeIdentifier(ONE),
104 new NodeIdentifier(TWO),
105 new NodeIdentifier(THREE),
106 new NodeIdentifier(FOUR)))
109 assertInstanceOf(LeafContextNode.class, result.node());
110 assertEquals(Absolute.of(ONE, TWO, THREE, THREE, FOUR, FOUR), result.stack().toSchemaNodeIdentifier());
114 void testEnterAugmentPath() {
115 final var result = CONTEXT.enterPath(YangInstanceIdentifier.create(
116 new NodeIdentifier(ONE),
117 new NodeIdentifier(FIVE),
118 new NodeIdentifier(FIVE)))
121 assertInstanceOf(UnkeyedListItemContextNode.class, result.node());
122 assertEquals(Absolute.of(ONE, FIVE), result.stack().toSchemaNodeIdentifier());
126 void testEnterAugmentChoicePath() {
127 final var result = CONTEXT.enterPath(YangInstanceIdentifier.create(
128 new NodeIdentifier(ONE),
129 new NodeIdentifier(TWO),
130 new NodeIdentifier(THREE),
131 new NodeIdentifier(SIX)))
134 assertInstanceOf(LeafContextNode.class, result.node());
135 assertEquals(Absolute.of(ONE, TWO, THREE, THREE, SIX, SIX), result.stack().toSchemaNodeIdentifier());