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.model.util;
10 import static org.hamcrest.CoreMatchers.instanceOf;
11 import static org.hamcrest.MatcherAssert.assertThat;
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertSame;
15 import com.google.common.collect.Iterables;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
20 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
22 public class YT1404Test {
23 private static final QName FOO = QName.create("foo", "foo");
24 private static final QName BAR = QName.create("foo", "bar");
25 private static final QName BAZ = QName.create("foo", "baz");
28 public void testDeviatedEffectiveAugmentationSchema() {
29 final var module = YangParserTestUtils.parseYangResourceDirectory("/yt1404").findModule("foo").orElseThrow();
30 final var augment = Iterables.getOnlyElement(module.getAugmentations());
31 assertEquals(2, augment.getChildNodes().size());
32 assertThat(augment.dataChildByName(BAR), instanceOf(LeafSchemaNode.class));
33 assertThat(augment.dataChildByName(BAZ), instanceOf(LeafSchemaNode.class));
35 final var foo = module.getDataChildByName(FOO);
36 assertThat(foo, instanceOf(ContainerSchemaNode.class));
37 final var fooCont = (ContainerSchemaNode) foo;
38 assertEquals(1, fooCont.getChildNodes().size());
39 final var fooBar = fooCont.dataChildByName(BAR);
40 assertThat(fooBar, instanceOf(LeafSchemaNode.class));
42 final var fooAugment = Iterables.getOnlyElement(fooCont.getAvailableAugmentations());
43 assertSame(augment, fooAugment);
45 final var effectiveAug = new EffectiveAugmentationSchema(augment, fooCont);
46 assertEquals(1, effectiveAug.getChildNodes().size());
47 assertSame(fooBar, effectiveAug.getDataChildByName(BAR));