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