2 * Copyright (c) 2022 PANTHEON.tech s.r.o. 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.MatcherAssert.assertThat;
12 import static org.junit.Assert.assertEquals;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
18 import org.opendaylight.yangtools.yang.model.api.stmt.CaseEffectiveStatement;
19 import org.opendaylight.yangtools.yang.model.api.stmt.ChoiceEffectiveStatement;
20 import org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement;
21 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeAwareEffectiveStatement.SchemaTreeNamespace;
23 public class YT1465Test extends AbstractYangTest {
25 public void supportedLeafInChoiceAugment() throws Exception {
26 final var baz = assertBaz(StmtTestUtils.parseYangSource("/bugs/YT1465/foo.yang", null));
27 final var schemas = baz.getAll(SchemaTreeNamespace.class).values();
28 assertEquals(2, schemas.size());
29 final var it = schemas.iterator();
31 final var first = it.next();
32 assertThat(first, instanceOf(CaseEffectiveStatement.class));
33 assertEquals(QName.create("foo", "one"), first.argument());
35 final var second = it.next();
36 assertThat(second, instanceOf(CaseEffectiveStatement.class));
37 assertEquals(QName.create("foo", "two"), second.argument());
41 public void unsupportedLeafInChoiceAugment() throws Exception {
42 final var baz = assertBaz(StmtTestUtils.parseYangSource("/bugs/YT1465/foo.yang", Set.of()));
43 final var schemas = baz.getAll(SchemaTreeNamespace.class).values();
44 assertEquals(1, schemas.size());
45 final var first = schemas.iterator().next();
46 assertThat(first, instanceOf(CaseEffectiveStatement.class));
47 assertEquals(QName.create("foo", "one"), first.argument());
50 private static ChoiceEffectiveStatement assertBaz(final EffectiveModelContext ctx) {
51 final var foo = ctx.findModuleStatements("foo").iterator().next()
52 .findFirstEffectiveSubstatement(ContainerEffectiveStatement.class).orElseThrow();
53 assertEquals(QName.create("foo", "foo"), foo.argument());
55 final var bar = foo.findFirstEffectiveSubstatement(ContainerEffectiveStatement.class).orElseThrow();
56 assertEquals(QName.create("foo", "bar"), bar.argument());
58 final var baz = bar.findFirstEffectiveSubstatement(ChoiceEffectiveStatement.class).orElseThrow();
59 assertEquals(QName.create("foo", "baz"), baz.argument());