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.junit.jupiter.api.Assertions.assertEquals;
11 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
14 import org.junit.jupiter.api.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;
21 class YT1465Test extends AbstractYangTest {
23 void supportedLeafInChoiceAugment() throws Exception {
24 final var baz = assertBaz(StmtTestUtils.parseYangSource("/bugs/YT1465/foo.yang", null));
25 final var schemas = baz.schemaTreeNodes();
26 assertEquals(2, schemas.size());
27 final var it = schemas.iterator();
29 final var first = assertInstanceOf(CaseEffectiveStatement.class, it.next());
30 assertEquals(QName.create("foo", "one"), first.argument());
32 final var second = assertInstanceOf(CaseEffectiveStatement.class, it.next());
33 assertEquals(QName.create("foo", "two"), second.argument());
37 void unsupportedLeafInChoiceAugment() throws Exception {
38 final var baz = assertBaz(StmtTestUtils.parseYangSource("/bugs/YT1465/foo.yang", Set.of()));
39 final var schemas = baz.schemaTreeNodes();
40 assertEquals(1, schemas.size());
41 final var first = assertInstanceOf(CaseEffectiveStatement.class, schemas.iterator().next());
42 assertEquals(QName.create("foo", "one"), first.argument());
45 private static ChoiceEffectiveStatement assertBaz(final EffectiveModelContext ctx) {
46 final var foo = ctx.findModuleStatements("foo").iterator().next()
47 .findFirstEffectiveSubstatement(ContainerEffectiveStatement.class).orElseThrow();
48 assertEquals(QName.create("foo", "foo"), foo.argument());
50 final var bar = foo.findFirstEffectiveSubstatement(ContainerEffectiveStatement.class).orElseThrow();
51 assertEquals(QName.create("foo", "bar"), bar.argument());
53 final var baz = bar.findFirstEffectiveSubstatement(ChoiceEffectiveStatement.class).orElseThrow();
54 assertEquals(QName.create("foo", "baz"), baz.argument());