Bug 5101: Status deprecated must not be propagated via uses statement 10/33810/1
authorPeter Kajsa <pkajsa@cisco.com>
Fri, 29 Jan 2016 12:35:40 +0000 (13:35 +0100)
committerRobert Varga <nite@hq.sk>
Sat, 30 Jan 2016 12:26:04 +0000 (12:26 +0000)
Status of grouping statement is not propagated via uses statement.

Change-Id: I2c2bf9d9222ea1be78b440c5c52ea675dcaeb89d
Signed-off-by: Peter Kajsa <pkajsa@cisco.com>
(cherry picked from commit 660b3a15a0da5e2212e64f35edfdd3444d145050)

yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/GroupingUtils.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug5101.java [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/bugs/bug5101/foo.yang [new file with mode: 0644]

index 8106aa6350fd0d086d7d6ddaa2df73502e89e7b3..0273150679d206076ac213532c5a1747781eb053 100644 (file)
@@ -117,14 +117,14 @@ public final class GroupingUtils {
         return true;
     }
 
-    private static final Set<Rfc6020Mapping> NOCOPY_DEF_SET = ImmutableSet.of(
-        Rfc6020Mapping.USES, Rfc6020Mapping.TYPEDEF, Rfc6020Mapping.TYPE);
-    private static final Set<Rfc6020Mapping> NOCOPY_FROM_GROUPING_SET = ImmutableSet.of(
-        Rfc6020Mapping.DESCRIPTION, Rfc6020Mapping.REFERENCE);
-    private static final Set<Rfc6020Mapping> REUSED_DEF_SET = ImmutableSet.of(
-        Rfc6020Mapping.TYPEDEF, Rfc6020Mapping.TYPE, Rfc6020Mapping.USES);
-    private static final Set<Rfc6020Mapping> TOP_REUSED_DEF_SET = ImmutableSet.of(
-        Rfc6020Mapping.TYPEDEF, Rfc6020Mapping.TYPE);
+    private static final Set<Rfc6020Mapping> NOCOPY_DEF_SET = ImmutableSet.of(Rfc6020Mapping.USES,
+            Rfc6020Mapping.TYPEDEF, Rfc6020Mapping.TYPE);
+    private static final Set<Rfc6020Mapping> NOCOPY_FROM_GROUPING_SET = ImmutableSet.of(Rfc6020Mapping.DESCRIPTION,
+            Rfc6020Mapping.REFERENCE, Rfc6020Mapping.STATUS);
+    private static final Set<Rfc6020Mapping> REUSED_DEF_SET = ImmutableSet.of(Rfc6020Mapping.TYPEDEF,
+            Rfc6020Mapping.TYPE, Rfc6020Mapping.USES);
+    private static final Set<Rfc6020Mapping> TOP_REUSED_DEF_SET = ImmutableSet.of(Rfc6020Mapping.TYPEDEF,
+            Rfc6020Mapping.TYPE);
 
     public static boolean needToCopyByUses(final StmtContext<?, ?, ?> stmtContext) {
         final StatementDefinition def = stmtContext.getPublicDefinition();
diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug5101.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug5101.java
new file mode 100644 (file)
index 0000000..38e26a2
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2015 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.test;
+
+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 org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.SchemaNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+
+public class Bug5101 {
+    private static final String NS = "foo";
+    private static final String REV = "2016-01-29";
+
+    @Test
+    public void test() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException {
+        SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug5101");
+        assertNotNull(context);
+
+        QName grp = QName.create(NS, REV, "my-grouping");
+        QName myContainer = QName.create(NS, REV, "my-container");
+        QName root = QName.create(NS, REV, "root");
+
+        SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context,
+                SchemaPath.create(true, grp, myContainer));
+        assertTrue(findDataSchemaNode instanceof ContainerSchemaNode);
+        ContainerSchemaNode myContainerInGrouping = (ContainerSchemaNode) findDataSchemaNode;
+        assertEquals(Status.DEPRECATED, myContainerInGrouping.getStatus());
+
+        findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true, root, myContainer));
+        assertTrue(findDataSchemaNode instanceof ContainerSchemaNode);
+        ContainerSchemaNode myContainerInRoot = (ContainerSchemaNode) findDataSchemaNode;
+        assertEquals(Status.DEPRECATED, myContainerInRoot.getStatus());
+
+        findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true, myContainer));
+        assertTrue(findDataSchemaNode instanceof ContainerSchemaNode);
+        ContainerSchemaNode myContainerInModule = (ContainerSchemaNode) findDataSchemaNode;
+        assertEquals(Status.DEPRECATED, myContainerInModule.getStatus());
+
+        findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true, root));
+        assertTrue(findDataSchemaNode instanceof ContainerSchemaNode);
+        ContainerSchemaNode rootContainer = (ContainerSchemaNode) findDataSchemaNode;
+        assertEquals(Status.CURRENT, rootContainer.getStatus());
+    }
+}
diff --git a/yang/yang-parser-impl/src/test/resources/bugs/bug5101/foo.yang b/yang/yang-parser-impl/src/test/resources/bugs/bug5101/foo.yang
new file mode 100644 (file)
index 0000000..206ec74
--- /dev/null
@@ -0,0 +1,21 @@
+module foo {
+    namespace "foo";
+    prefix foo;
+
+    revision 2016-01-29 {
+        description "test";
+    }
+
+    grouping my-grouping {
+        status deprecated;
+        container my-container {
+            status deprecated;
+        }
+    }
+
+    container root {
+        uses my-grouping;
+    }
+
+    uses my-grouping;
+}