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.SchemaContext;
21 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
22 import org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement;
23 import org.opendaylight.yangtools.yang.model.api.stmt.UnitsEffectiveStatement;
25 public class Bug6972Test {
27 public void allUnitsShouldBeTheSameInstance() throws Exception {
28 final SchemaContext schemaContext = StmtTestUtils.parseYangSources("/bugs/bug6972");
29 assertNotNull(schemaContext);
30 assertEquals(3, schemaContext.getModules().size());
32 final Revision revision = Revision.of("2016-10-20");
33 final Module foo = schemaContext.findModule("foo", revision).get();
34 final Module bar = schemaContext.findModule("bar", revision).get();
35 final Module baz = schemaContext.findModule("baz", revision).get();
37 final QName barExportCont = QName.create("bar-ns", "bar-export", revision);
38 final QName barFooCont = QName.create("bar-ns", "bar-foo", revision);
39 final QName barFooLeaf = QName.create("bar-ns", "foo", revision);
41 final UnitsEffectiveStatement unitsBar1 = getEffectiveUnits(bar, barExportCont, barFooLeaf);
42 assertSame(unitsBar1, getEffectiveUnits(bar, barFooCont, barFooLeaf));
44 final QName bazExportCont = QName.create("baz-ns", "baz-export", revision);
45 final QName bazFooCont = QName.create("baz-ns", "baz-foo", revision);
46 final QName bazFooLeaf = QName.create("baz-ns", "foo", revision);
48 assertSame(unitsBar1, getEffectiveUnits(baz, bazExportCont, bazFooLeaf));
49 assertSame(unitsBar1, getEffectiveUnits(baz, bazFooCont, bazFooLeaf));
52 private static UnitsEffectiveStatement getEffectiveUnits(final Module module, final QName containerQName,
53 final QName leafQName) {
54 UnitsEffectiveStatement units = null;
56 final ContainerSchemaNode cont = (ContainerSchemaNode) module.getDataChildByName(containerQName);
58 final LeafSchemaNode leaf = (LeafSchemaNode) cont.getDataChildByName(leafQName);
61 for (EffectiveStatement<?, ?> effStmt : ((LeafEffectiveStatement) leaf).effectiveSubstatements()) {
62 if (effStmt instanceof UnitsEffectiveStatement) {
63 units = (UnitsEffectiveStatement) effStmt;