2 * Copyright (c) 2016 Cisco Systems, Inc. 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.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertSame;
14 import org.junit.Test;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.common.Revision;
17 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.Module;
20 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
21 import org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement;
22 import org.opendaylight.yangtools.yang.model.api.stmt.UnitsEffectiveStatement;
24 public class Bug6972Test extends AbstractYangTest {
26 public void allUnitsShouldBeTheSameInstance() {
27 final var schemaContext = assertEffectiveModelDir("/bugs/bug6972");
28 assertEquals(3, schemaContext.getModules().size());
30 final Revision revision = Revision.of("2016-10-20");
31 final Module foo = schemaContext.findModule("foo", revision).get();
32 final Module bar = schemaContext.findModule("bar", revision).get();
33 final Module baz = schemaContext.findModule("baz", revision).get();
35 final QName barExportCont = QName.create("bar-ns", "bar-export", revision);
36 final QName barFooCont = QName.create("bar-ns", "bar-foo", revision);
37 final QName barFooLeaf = QName.create("bar-ns", "foo", revision);
39 final UnitsEffectiveStatement unitsBar1 = getEffectiveUnits(bar, barExportCont, barFooLeaf);
40 assertSame(unitsBar1, getEffectiveUnits(bar, barFooCont, barFooLeaf));
42 final QName bazExportCont = QName.create("baz-ns", "baz-export", revision);
43 final QName bazFooCont = QName.create("baz-ns", "baz-foo", revision);
44 final QName bazFooLeaf = QName.create("baz-ns", "foo", revision);
46 assertSame(unitsBar1, getEffectiveUnits(baz, bazExportCont, bazFooLeaf));
47 assertSame(unitsBar1, getEffectiveUnits(baz, bazFooCont, bazFooLeaf));
50 private static UnitsEffectiveStatement getEffectiveUnits(final Module module, final QName containerQName,
51 final QName leafQName) {
52 UnitsEffectiveStatement units = null;
54 final ContainerSchemaNode cont = (ContainerSchemaNode) module.getDataChildByName(containerQName);
56 final LeafSchemaNode leaf = (LeafSchemaNode) cont.getDataChildByName(leafQName);
59 for (EffectiveStatement<?, ?> effStmt : ((LeafEffectiveStatement) leaf).effectiveSubstatements()) {
60 if (effStmt instanceof UnitsEffectiveStatement) {
61 units = (UnitsEffectiveStatement) effStmt;