2 * Copyright (c) 2020 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.junit.jupiter.api.Assertions.assertNotSame;
11 import static org.junit.jupiter.api.Assertions.assertSame;
13 import org.junit.jupiter.api.Test;
14 import org.opendaylight.yangtools.yang.common.QNameModule;
15 import org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement;
16 import org.opendaylight.yangtools.yang.model.api.stmt.KeyEffectiveStatement;
17 import org.opendaylight.yangtools.yang.model.api.stmt.ListEffectiveStatement;
19 class YT1195Test extends AbstractYangTest {
21 void testKeyStatementReuse() {
22 final var module = assertEffectiveModel("/bugs/YT1195/key.yang").getModuleStatement(QNameModule.of("foo"));
23 final var grpFoo = module.findFirstEffectiveSubstatement(GroupingEffectiveStatement.class).orElseThrow()
24 .findFirstEffectiveSubstatement(ListEffectiveStatement.class).orElseThrow();
25 final var foo = module.findFirstEffectiveSubstatement(ListEffectiveStatement.class).orElseThrow();
27 // The statements should not be the same due history being part of ListSchemaNode
28 assertNotSame(foo, grpFoo);
29 // The statements are instantiated in the same module, hence they should have the same argument
30 assertSame(foo.argument(), grpFoo.argument());
31 // The statements' key substatement should be reused
32 assertSame(foo.findFirstEffectiveSubstatement(KeyEffectiveStatement.class).orElseThrow(),
33 grpFoo.findFirstEffectiveSubstatement(KeyEffectiveStatement.class).orElseThrow());