Bug 5481: When condition of augment added in constraints of augment target 60/36060/1
authorPeter Kajsa <pkajsa@cisco.com>
Wed, 9 Mar 2016 17:22:46 +0000 (18:22 +0100)
committerPeter Kajsa <pkajsa@cisco.com>
Thu, 10 Mar 2016 16:22:13 +0000 (17:22 +0100)
The patch excludes When, Status, Description and Reference statements
from copying of top augment's nodes.

Change-Id: I72bf65aba09e43799ac619cd4de9ed03230ad071
Signed-off-by: Peter Kajsa <pkajsa@cisco.com>
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/AugmentUtils.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug5481.java [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/bugs/bug5481/module1.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/bugs/bug5481/module2.yang [new file with mode: 0644]

index 7c83a5f0281fb72e599ae5c56e8b010b778c7486..9bcedcb22ba870bcc39e483e09da1346247017fb 100644 (file)
@@ -155,10 +155,11 @@ public final class AugmentUtils {
         return false;
     }
 
-    private static final Set<Rfc6020Mapping> NOCOPY_DEV_SET = ImmutableSet.of(Rfc6020Mapping.USES);
+    private static final Set<Rfc6020Mapping> NOCOPY_DEF_SET = ImmutableSet.of(Rfc6020Mapping.USES, Rfc6020Mapping.WHEN,
+            Rfc6020Mapping.DESCRIPTION, Rfc6020Mapping.REFERENCE, Rfc6020Mapping.STATUS);
 
     public static boolean needToCopyByAugment(final StmtContext<?, ?, ?> stmtContext) {
-        return !NOCOPY_DEV_SET.contains(stmtContext.getPublicDefinition());
+        return !NOCOPY_DEF_SET.contains(stmtContext.getPublicDefinition());
     }
 
     private static final Set<Rfc6020Mapping> REUSED_DEF_SET = ImmutableSet.of(Rfc6020Mapping.TYPEDEF);
diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug5481.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug5481.java
new file mode 100644 (file)
index 0000000..703c588
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * 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.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+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.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.util.RevisionAwareXPathImpl;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+
+public class Bug5481 {
+    @Test
+    public void test() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException {
+        SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug5481");
+        assertNotNull(context);
+
+        ContainerSchemaNode topContainer = verifyTopContainer(context);
+        verifyExtendedLeaf(topContainer);
+    }
+
+    private ContainerSchemaNode verifyTopContainer(SchemaContext context) {
+        QName top = QName.create("http://example.com/module1", "2016-03-09", "top");
+        DataSchemaNode dataChildByName = context.getDataChildByName(top);
+        assertTrue(dataChildByName instanceof ContainerSchemaNode);
+
+        ContainerSchemaNode topContainer = (ContainerSchemaNode) dataChildByName;
+        RevisionAwareXPath whenConditionTopContainer = topContainer.getConstraints().getWhenCondition();
+
+        assertNull(whenConditionTopContainer);
+        assertEquals(Status.CURRENT, topContainer.getStatus());
+        assertNull(topContainer.getDescription());
+        assertNull(topContainer.getReference());
+        return topContainer;
+    }
+
+    private void verifyExtendedLeaf(ContainerSchemaNode topContainer) {
+        DataSchemaNode dataChildByName2 = topContainer.getDataChildByName(QName.create("http://example.com/module2",
+                "2016-03-09", "extended-leaf"));
+        assertTrue(dataChildByName2 instanceof LeafSchemaNode);
+
+        LeafSchemaNode extendedLeaf = (LeafSchemaNode) dataChildByName2;
+        RevisionAwareXPath whenConditionExtendedLeaf = extendedLeaf.getConstraints().getWhenCondition();
+
+        assertEquals(new RevisionAwareXPathImpl("module1:top = 'extended'", false), whenConditionExtendedLeaf);
+        assertEquals(Status.DEPRECATED, extendedLeaf.getStatus());
+        assertEquals("text", extendedLeaf.getDescription());
+        assertEquals("ref", extendedLeaf.getReference());
+    }
+}
diff --git a/yang/yang-parser-impl/src/test/resources/bugs/bug5481/module1.yang b/yang/yang-parser-impl/src/test/resources/bugs/bug5481/module1.yang
new file mode 100644 (file)
index 0000000..5ded8cf
--- /dev/null
@@ -0,0 +1,18 @@
+module module1 {
+    yang-version 1;
+
+    namespace "http://example.com/module1";
+    prefix "module1";
+
+    description "Module 1";
+
+    revision "2016-03-09" {
+        description "Initial version.";
+    }
+
+    container top {
+        leaf top-leaf {
+            type string;
+        }
+    }
+}
diff --git a/yang/yang-parser-impl/src/test/resources/bugs/bug5481/module2.yang b/yang/yang-parser-impl/src/test/resources/bugs/bug5481/module2.yang
new file mode 100644 (file)
index 0000000..f6b1fa3
--- /dev/null
@@ -0,0 +1,28 @@
+module module2 {
+    yang-version 1;
+
+    namespace "http://example.com/module2";
+    prefix "module2";
+
+    import module1 { prefix "module1"; }
+
+    description "Module 2";
+
+    revision "2016-03-09" {
+        description "Initial version.";
+    }
+
+    augment "module1:top" {
+        when "module1:top = 'extended'";
+        description "text";
+        status deprecated;
+        reference "ref";
+        leaf extended-leaf {
+            when "module1:top = 'extended'";
+            description "text";
+            status deprecated;
+            reference "ref";
+            type string;
+        }
+    }
+}