Remove EffectiveAugmentationSchema
[yangtools.git] / model / yang-model-util / src / test / java / org / opendaylight / yangtools / yang / model / util / YT1404Test.java
1 /*
2  * Copyright (c) 2022 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.model.util;
9
10 import static org.junit.jupiter.api.Assertions.assertEquals;
11 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
12 import static org.junit.jupiter.api.Assertions.assertSame;
13
14 import com.google.common.collect.Iterables;
15 import org.junit.jupiter.api.Test;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
19 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
20
21 class YT1404Test {
22     private static final QName FOO = QName.create("foo", "foo");
23     private static final QName BAR = QName.create("foo", "bar");
24     private static final QName BAZ = QName.create("foo", "baz");
25
26     @Test
27     void testDeviatedEffectiveAugmentationSchema() {
28         final var module = YangParserTestUtils.parseYang("""
29             module dev {
30               namespace dev;
31               prefix dev;
32
33               import foo {
34                 prefix foo;
35               }
36
37               deviation /foo:foo/foo:baz {
38                 deviate not-supported;
39               }
40             }""", """
41             module foo {
42               namespace foo;
43               prefix foo;
44
45               container foo;
46
47               augment /foo {
48                 leaf bar {
49                   type string;
50                 }
51                 leaf baz {
52                   type string;
53                 }
54               }
55             }""").findModule("foo").orElseThrow();
56         final var augment = Iterables.getOnlyElement(module.getAugmentations());
57         assertEquals(2, augment.getChildNodes().size());
58         assertInstanceOf(LeafSchemaNode.class, augment.dataChildByName(BAR));
59         assertInstanceOf(LeafSchemaNode.class, augment.dataChildByName(BAZ));
60
61         final var foo = assertInstanceOf(ContainerSchemaNode.class, module.getDataChildByName(FOO));
62         assertEquals(1, foo.getChildNodes().size());
63         assertInstanceOf(LeafSchemaNode.class, foo.dataChildByName(BAR));
64
65         assertSame(augment, Iterables.getOnlyElement(foo.getAvailableAugmentations()));
66     }
67 }