2 * Copyright (c) 2021 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.model.util;
10 import static org.hamcrest.CoreMatchers.instanceOf;
11 import static org.hamcrest.MatcherAssert.assertThat;
12 import static org.junit.Assert.assertEquals;
14 import org.junit.Test;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
17 import org.opendaylight.yangtools.yang.model.api.stmt.CaseEffectiveStatement;
18 import org.opendaylight.yangtools.yang.model.api.stmt.ChoiceEffectiveStatement;
19 import org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement;
20 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
21 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
23 public class YT1231Test {
24 private static final QName FOO = QName.create("foo", "foo");
25 private static final QName BAR = QName.create("foo", "bar");
26 private static final QName BAZ = QName.create("foo", "baz");
27 private static final QName XYZZY = QName.create("foo", "xyzzy");
30 public void testEnterDataTree() {
31 final EffectiveModelContext context = YangParserTestUtils.parseYangResource("/yt1231.yang");
32 final SchemaInferenceStack stack = new SchemaInferenceStack(context);
35 assertThat(stack.enterDataTree(FOO), instanceOf(ContainerEffectiveStatement.class));
36 assertEquals(Absolute.of(FOO), stack.toSchemaNodeIdentifier());
37 assertThat(stack.enterDataTree(FOO), instanceOf(ContainerEffectiveStatement.class));
38 assertEquals(Absolute.of(FOO, FOO), stack.toSchemaNodeIdentifier());
41 // Has to cross four layers of choice/case
42 assertThat(stack.enterDataTree(XYZZY), instanceOf(ContainerEffectiveStatement.class));
43 assertEquals(Absolute.of(FOO, BAR, BAR, BAZ, BAZ, XYZZY), stack.toSchemaNodeIdentifier());
46 assertThat(stack.enterSchemaTree(BAR), instanceOf(ChoiceEffectiveStatement.class));
47 assertThat(stack.enterSchemaTree(BAR), instanceOf(CaseEffectiveStatement.class));
48 assertEquals(Absolute.of(FOO, BAR, BAR), stack.toSchemaNodeIdentifier());
52 public void testEnterChoice() {
53 final EffectiveModelContext context = YangParserTestUtils.parseYangResource("/yt1231.yang");
54 final SchemaInferenceStack stack = new SchemaInferenceStack(context);
57 assertThat(stack.enterDataTree(FOO), instanceOf(ContainerEffectiveStatement.class));
58 assertEquals(Absolute.of(FOO), stack.toSchemaNodeIdentifier());
59 assertThat(stack.enterChoice(BAR), instanceOf(ChoiceEffectiveStatement.class));
60 assertEquals(Absolute.of(FOO, BAR), stack.toSchemaNodeIdentifier());
62 // Has to cross choice -> case -> choice
63 assertThat(stack.enterChoice(BAZ), instanceOf(ChoiceEffectiveStatement.class));
64 assertEquals(Absolute.of(FOO, BAR, BAR, BAZ), stack.toSchemaNodeIdentifier());
66 // Now the same with just case -> choice
68 assertThat(stack.enterSchemaTree(BAR), instanceOf(CaseEffectiveStatement.class));
69 assertThat(stack.enterChoice(BAZ), instanceOf(ChoiceEffectiveStatement.class));
70 assertEquals(Absolute.of(FOO, BAR, BAR, BAZ), stack.toSchemaNodeIdentifier());