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
9 package org.opendaylight.yangtools.yang.stmt;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertTrue;
15 import org.junit.Ignore;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.common.Revision;
19 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.Module;
22 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
23 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
24 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.LeafEffectiveStatementImpl;
25 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.UnitsEffectiveStatementImpl;
27 public class Bug6972Test {
31 public void allUnitsShouldBeTheSameInstance() throws Exception {
32 final SchemaContext schemaContext = StmtTestUtils.parseYangSources("/bugs/bug6972");
33 assertNotNull(schemaContext);
34 assertEquals(3, schemaContext.getModules().size());
36 final Revision revision = Revision.valueOf("2016-10-20");
37 final Module foo = schemaContext.findModule("foo", revision).get();
38 final Module bar = schemaContext.findModule("bar", revision).get();
39 final Module baz = schemaContext.findModule("baz", revision).get();
41 final QName barExportCont = QName.create("bar-ns", "bar-export", revision);
42 final QName barFooCont = QName.create("bar-ns", "bar-foo", revision);
43 final QName barFooLeaf= QName.create("bar-ns", "foo", revision);
45 final UnitsEffectiveStatementImpl unitsBar1 = getEffectiveUnits(bar, barExportCont, barFooLeaf);
46 final UnitsEffectiveStatementImpl unitsBar2 = getEffectiveUnits(bar, barFooCont, barFooLeaf);
48 final QName bazExportCont = QName.create("baz-ns", "baz-export", revision);
49 final QName bazFooCont = QName.create("baz-ns", "baz-foo", revision);
50 final QName bazFooLeaf= QName.create("baz-ns", "foo", revision);
52 final UnitsEffectiveStatementImpl unitsBaz1 = getEffectiveUnits(baz, bazExportCont, bazFooLeaf);
53 final UnitsEffectiveStatementImpl unitsBaz2 = getEffectiveUnits(baz, bazFooCont, bazFooLeaf);
55 assertTrue(unitsBar1 == unitsBar2 && unitsBar1 == unitsBaz1 && unitsBar1 == unitsBaz2);
58 private static UnitsEffectiveStatementImpl getEffectiveUnits(final Module module, final QName containerQName,
59 final QName leafQName) {
60 UnitsEffectiveStatementImpl units = null;
62 final ContainerSchemaNode cont = (ContainerSchemaNode) module.getDataChildByName(containerQName);
64 final LeafSchemaNode leaf = (LeafSchemaNode) cont.getDataChildByName(leafQName);
67 for (EffectiveStatement<?, ?> effStmt : ((LeafEffectiveStatementImpl) leaf).effectiveSubstatements()) {
68 if (effStmt instanceof UnitsEffectiveStatementImpl) {
69 units = (UnitsEffectiveStatementImpl) effStmt;