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 java.util.Collection;
16 import java.util.Date;
17 import org.junit.Ignore;
18 import org.junit.Test;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
21 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.Module;
24 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
25 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
26 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.LeafEffectiveStatementImpl;
27 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.UnitsEffectiveStatementImpl;
29 public class Bug6972Test {
33 public void allUnitsShouldBeTheSameInstance() throws Exception {
34 final SchemaContext schemaContext = StmtTestUtils.parseYangSources("/bugs/bug6972");
35 assertNotNull(schemaContext);
36 assertEquals(3, schemaContext.getModules().size());
38 final Date revision = SimpleDateFormatUtil.getRevisionFormat().parse("2016-10-20");
40 final Module foo = schemaContext.findModuleByName("foo", revision);
42 final Module bar = schemaContext.findModuleByName("bar", revision);
44 final Module baz = schemaContext.findModuleByName("baz", revision);
47 final QName barExportCont = QName.create("bar-ns", "bar-export", revision);
48 final QName barFooCont = QName.create("bar-ns", "bar-foo", revision);
49 final QName barFooLeaf= QName.create("bar-ns", "foo", revision);
51 final UnitsEffectiveStatementImpl unitsBar1 = getEffectiveUnits(bar, barExportCont, barFooLeaf);
52 final UnitsEffectiveStatementImpl unitsBar2 = getEffectiveUnits(bar, barFooCont, barFooLeaf);
54 final QName bazExportCont = QName.create("baz-ns", "baz-export", revision);
55 final QName bazFooCont = QName.create("baz-ns", "baz-foo", revision);
56 final QName bazFooLeaf= QName.create("baz-ns", "foo", revision);
58 final UnitsEffectiveStatementImpl unitsBaz1 = getEffectiveUnits(baz, bazExportCont, bazFooLeaf);
59 final UnitsEffectiveStatementImpl unitsBaz2 = getEffectiveUnits(baz, bazFooCont, bazFooLeaf);
61 assertTrue(unitsBar1 == unitsBar2 && unitsBar1 == unitsBaz1 && unitsBar1 == unitsBaz2);
64 private static UnitsEffectiveStatementImpl getEffectiveUnits(final Module module, final QName containerQName,
65 final QName leafQName) {
66 UnitsEffectiveStatementImpl units = null;
68 final ContainerSchemaNode cont = (ContainerSchemaNode) module.getDataChildByName(containerQName);
70 final LeafSchemaNode leaf = (LeafSchemaNode) cont.getDataChildByName(leafQName);
73 final Collection<? extends EffectiveStatement<?, ?>> effectiveSubstatements =
74 ((LeafEffectiveStatementImpl) leaf).effectiveSubstatements();
76 for (EffectiveStatement<?, ?> effStmt : effectiveSubstatements) {
77 if (effStmt instanceof UnitsEffectiveStatementImpl) {
78 units = (UnitsEffectiveStatementImpl) effStmt;