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.Date;
16 import org.junit.Ignore;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
20 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.Module;
23 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
24 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
25 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.LeafEffectiveStatementImpl;
26 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.UnitsEffectiveStatementImpl;
28 public class Bug6972Test {
32 public void allUnitsShouldBeTheSameInstance() throws Exception {
33 final SchemaContext schemaContext = StmtTestUtils.parseYangSources("/bugs/bug6972");
34 assertNotNull(schemaContext);
35 assertEquals(3, schemaContext.getModules().size());
37 final Date revision = SimpleDateFormatUtil.getRevisionFormat().parse("2016-10-20");
39 final Module foo = schemaContext.findModuleByName("foo", revision);
41 final Module bar = schemaContext.findModuleByName("bar", revision);
43 final Module baz = schemaContext.findModuleByName("baz", revision);
46 final QName barExportCont = QName.create("bar-ns", "bar-export", revision);
47 final QName barFooCont = QName.create("bar-ns", "bar-foo", revision);
48 final QName barFooLeaf= QName.create("bar-ns", "foo", revision);
50 final UnitsEffectiveStatementImpl unitsBar1 = getEffectiveUnits(bar, barExportCont, barFooLeaf);
51 final UnitsEffectiveStatementImpl unitsBar2 = getEffectiveUnits(bar, barFooCont, barFooLeaf);
53 final QName bazExportCont = QName.create("baz-ns", "baz-export", revision);
54 final QName bazFooCont = QName.create("baz-ns", "baz-foo", revision);
55 final QName bazFooLeaf= QName.create("baz-ns", "foo", revision);
57 final UnitsEffectiveStatementImpl unitsBaz1 = getEffectiveUnits(baz, bazExportCont, bazFooLeaf);
58 final UnitsEffectiveStatementImpl unitsBaz2 = getEffectiveUnits(baz, bazFooCont, bazFooLeaf);
60 assertTrue(unitsBar1 == unitsBar2 && unitsBar1 == unitsBaz1 && unitsBar1 == unitsBaz2);
63 private static UnitsEffectiveStatementImpl getEffectiveUnits(final Module module, final QName containerQName,
64 final QName leafQName) {
65 UnitsEffectiveStatementImpl units = null;
67 final ContainerSchemaNode cont = (ContainerSchemaNode) module.getDataChildByName(containerQName);
69 final LeafSchemaNode leaf = (LeafSchemaNode) cont.getDataChildByName(leafQName);
72 for (EffectiveStatement<?, ?> effStmt : ((LeafEffectiveStatementImpl) leaf).effectiveSubstatements()) {
73 if (effStmt instanceof UnitsEffectiveStatementImpl) {
74 units = (UnitsEffectiveStatementImpl) effStmt;