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.startsWith;
11 import static org.hamcrest.MatcherAssert.assertThat;
12 import static org.junit.Assert.assertSame;
13 import static org.junit.Assert.assertThrows;
14 import static org.junit.Assert.assertTrue;
16 import java.util.NoSuchElementException;
17 import org.junit.BeforeClass;
18 import org.junit.Test;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
21 import org.opendaylight.yangtools.yang.model.api.stmt.DataTreeEffectiveStatement;
22 import org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement;
23 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
25 public class YT1233Test {
26 private static EffectiveModelContext context;
28 private final SchemaInferenceStack stack = SchemaInferenceStack.of(context);
31 public static void beforeClass() {
32 context = YangParserTestUtils.parseYangResource("/yt1233.yang");
36 public void testExitToDataTree() {
37 final DataTreeEffectiveStatement<?> foo = stack.enterDataTree(QName.create("foo", "foo"));
38 assertSame(foo, stack.exitToDataTree());
39 assertTrue(stack.isEmpty());
40 assertSame(foo, stack.enterDataTree(foo.argument()));
44 public void testExitToGrouping() {
45 final GroupingEffectiveStatement baz = stack.enterGrouping(QName.create("foo", "baz"));
46 assertTrue(stack.inGrouping());
47 final DataTreeEffectiveStatement<?> xyzzy = stack.enterDataTree(QName.create("foo", "xyzzy"));
48 assertSame(xyzzy, stack.exitToDataTree());
49 assertSame(baz, stack.currentStatement());
50 assertSame(xyzzy, stack.enterDataTree(xyzzy.argument()));
54 public void testEmptyExitToDataTree() {
55 assertThrows(NoSuchElementException.class, stack::exitToDataTree);
59 public void testSchemaExitToDataTree() {
60 stack.enterSchemaTree(QName.create("foo", "bar"));
61 final IllegalStateException ex = assertThrows(IllegalStateException.class, stack::exitToDataTree);
62 assertThat(ex.getMessage(), startsWith("Unexpected current "));