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.stmt;
10 import static org.hamcrest.CoreMatchers.instanceOf;
11 import static org.hamcrest.CoreMatchers.startsWith;
12 import static org.hamcrest.MatcherAssert.assertThat;
13 import static org.junit.Assert.assertThrows;
15 import java.io.IOException;
16 import java.net.URISyntaxException;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.model.api.stmt.CaseEffectiveStatement;
20 import org.opendaylight.yangtools.yang.model.api.stmt.ChoiceEffectiveStatement;
21 import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
24 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
26 public class YT1410Test {
28 public void testRFC6020() {
29 final var ex = assertThrows(SomeModifiersUnresolvedException.class,
30 () -> StmtTestUtils.parseYangSource("/bugs/YT1410/foo.yang")).getCause();
31 assertThat(ex, instanceOf(SourceException.class));
32 assertThat(ex.getMessage(),
33 startsWith("CHOICE is not valid for CHOICE. Error in module foo (QNameModule{ns=foo}) [at "));
37 public void testRFC7950() throws YangSyntaxErrorException, ReactorException, URISyntaxException, IOException {
38 final var module = StmtTestUtils.parseYangSource("/bugs/YT1410/bar.yang")
39 .getModuleStatement(QName.create("bar", "bar"));
40 final var one = module.findSchemaTreeNode(QName.create("bar", "one")).orElseThrow();
41 assertThat(one, instanceOf(ChoiceEffectiveStatement.class));
42 final var two = ((ChoiceEffectiveStatement) one).findSchemaTreeNode(QName.create("bar", "two")).orElseThrow();
43 assertThat(two, instanceOf(CaseEffectiveStatement.class));
44 assertThat(((CaseEffectiveStatement) two).findSchemaTreeNode(QName.create("bar", "two")).orElseThrow(),
45 instanceOf(ChoiceEffectiveStatement.class));