Bug 6972: Preliminary unit test 12/47312/3
authorIgor Foltin <ifoltin@cisco.com>
Fri, 21 Oct 2016 07:19:26 +0000 (09:19 +0200)
committerRobert Varga <nite@hq.sk>
Fri, 21 Oct 2016 11:31:22 +0000 (11:31 +0000)
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 <ifoltin@cisco.com>
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug6972Test.java [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/bugs/bug6972/bar.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/bugs/bug6972/baz.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/bugs/bug6972/foo.yang [new file with mode: 0644]

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 (file)
index 0000000..45556f3
--- /dev/null
@@ -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<? extends EffectiveStatement<?, ?>> 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 (file)
index 0000000..ed7a56c
--- /dev/null
@@ -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 (file)
index 0000000..91cec2b
--- /dev/null
@@ -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 (file)
index 0000000..0460125
--- /dev/null
@@ -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