From c20090c009bc333710678d631e180f3227cd42df Mon Sep 17 00:00:00 2001 From: Igor Foltin Date: Fri, 21 Oct 2016 09:19:26 +0200 Subject: [PATCH] Bug 6972: Preliminary unit test For now, this patch contains just a unit test which will test the actual fix once it is implemented. Therefore, the test is currently silenced with @Ignore. Change-Id: I7b7ce9e2384f942cd13d46c59f868e125ae327c7 Signed-off-by: Igor Foltin --- .../yangtools/yang/stmt/Bug6972Test.java | 90 +++++++++++++++++++ .../src/test/resources/bugs/bug6972/bar.yang | 18 ++++ .../src/test/resources/bugs/bug6972/baz.yang | 18 ++++ .../src/test/resources/bugs/bug6972/foo.yang | 17 ++++ 4 files changed, 143 insertions(+) create mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug6972Test.java create mode 100644 yang/yang-parser-impl/src/test/resources/bugs/bug6972/bar.yang create mode 100644 yang/yang-parser-impl/src/test/resources/bugs/bug6972/baz.yang create mode 100644 yang/yang-parser-impl/src/test/resources/bugs/bug6972/foo.yang diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug6972Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug6972Test.java new file mode 100644 index 0000000000..45556f3e05 --- /dev/null +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug6972Test.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.yangtools.yang.stmt; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.io.FileNotFoundException; +import java.net.URISyntaxException; +import java.text.ParseException; +import java.util.Collection; +import java.util.Date; +import org.junit.Ignore; +import org.junit.Test; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil; +import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; +import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; +import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.LeafEffectiveStatementImpl; +import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.UnitsEffectiveStatementImpl; + +public class Bug6972Test { + + @Ignore + @Test + public void allUnitsShouldBeTheSameInstance() throws ReactorException, FileNotFoundException, URISyntaxException, + ParseException { + final SchemaContext schemaContext = StmtTestUtils.parseYangSources("/bugs/bug6972"); + assertNotNull(schemaContext); + assertEquals(3, schemaContext.getModules().size()); + + final Date revision = SimpleDateFormatUtil.getRevisionFormat().parse("2016-10-20"); + + final Module foo = schemaContext.findModuleByName("foo", revision); + assertNotNull(foo); + final Module bar = schemaContext.findModuleByName("bar", revision); + assertNotNull(bar); + final Module baz = schemaContext.findModuleByName("baz", revision); + assertNotNull(baz); + + final QName barExportCont = QName.create("bar-ns", "bar-export", revision); + final QName barFooCont = QName.create("bar-ns", "bar-foo", revision); + final QName barFooLeaf= QName.create("bar-ns", "foo", revision); + + final UnitsEffectiveStatementImpl unitsBar1 = getEffectiveUnits(bar, barExportCont, barFooLeaf); + final UnitsEffectiveStatementImpl unitsBar2 = getEffectiveUnits(bar, barFooCont, barFooLeaf); + + final QName bazExportCont = QName.create("baz-ns", "baz-export", revision); + final QName bazFooCont = QName.create("baz-ns", "baz-foo", revision); + final QName bazFooLeaf= QName.create("baz-ns", "foo", revision); + + final UnitsEffectiveStatementImpl unitsBaz1 = getEffectiveUnits(baz, bazExportCont, bazFooLeaf); + final UnitsEffectiveStatementImpl unitsBaz2 = getEffectiveUnits(baz, bazFooCont, bazFooLeaf); + + assertTrue(unitsBar1 == unitsBar2 && unitsBar1 == unitsBaz1 && unitsBar1 == unitsBaz2); + } + + private static UnitsEffectiveStatementImpl getEffectiveUnits(final Module module, final QName containerQName, + final QName leafQName) { + UnitsEffectiveStatementImpl units = null; + + final ContainerSchemaNode cont = (ContainerSchemaNode) module.getDataChildByName(containerQName); + assertNotNull(cont); + final LeafSchemaNode leaf = (LeafSchemaNode) cont.getDataChildByName(leafQName); + assertNotNull(leaf); + + final Collection> effectiveSubstatements = + ((LeafEffectiveStatementImpl) leaf).effectiveSubstatements(); + + for (EffectiveStatement effStmt : effectiveSubstatements) { + if (effStmt instanceof UnitsEffectiveStatementImpl) { + units = (UnitsEffectiveStatementImpl) effStmt; + break; + } + } + + return units; + } +} \ No newline at end of file diff --git a/yang/yang-parser-impl/src/test/resources/bugs/bug6972/bar.yang b/yang/yang-parser-impl/src/test/resources/bugs/bug6972/bar.yang new file mode 100644 index 0000000000..ed7a56cd20 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/bugs/bug6972/bar.yang @@ -0,0 +1,18 @@ +module bar { + namespace bar-ns; + prefix bar-prefix; + + import foo { + prefix foo; + revision-date 2016-10-20; + } + + revision 2016-10-20; + + container bar-export { + uses foo:export; + } + container bar-foo { + uses foo:foo; + } +} \ No newline at end of file diff --git a/yang/yang-parser-impl/src/test/resources/bugs/bug6972/baz.yang b/yang/yang-parser-impl/src/test/resources/bugs/bug6972/baz.yang new file mode 100644 index 0000000000..91cec2bd45 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/bugs/bug6972/baz.yang @@ -0,0 +1,18 @@ +module baz { + namespace baz-ns; + prefix baz-prefix; + + import foo { + prefix foo; + revision-date 2016-10-20; + } + + revision 2016-10-20; + + container baz-export { + uses foo:export; + } + container baz-foo { + uses foo:foo; + } +} \ No newline at end of file diff --git a/yang/yang-parser-impl/src/test/resources/bugs/bug6972/foo.yang b/yang/yang-parser-impl/src/test/resources/bugs/bug6972/foo.yang new file mode 100644 index 0000000000..0460125dac --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/bugs/bug6972/foo.yang @@ -0,0 +1,17 @@ +module foo { + namespace foo-ns; + prefix foo-prefix; + + revision 2016-10-20; + + grouping foo { + leaf foo { + type string; + units foo; + } + } + + grouping export { + uses foo; + } +} \ No newline at end of file -- 2.36.6