From 78cbd44f2617ed955064036b94f88603bc3de826 Mon Sep 17 00:00:00 2001 From: Peter Kajsa Date: Wed, 9 Mar 2016 18:22:46 +0100 Subject: [PATCH] Bug 5481: When condition of augment added in constraints of augment target The patch excludes When, Status, Description and Reference statements from copying of top augment's nodes. Change-Id: I72bf65aba09e43799ac619cd4de9ed03230ad071 Signed-off-by: Peter Kajsa --- .../parser/stmt/rfc6020/AugmentUtils.java | 5 +- .../yangtools/yang/stmt/test/Bug5481.java | 67 +++++++++++++++++++ .../test/resources/bugs/bug5481/module1.yang | 18 +++++ .../test/resources/bugs/bug5481/module2.yang | 28 ++++++++ 4 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug5481.java create mode 100644 yang/yang-parser-impl/src/test/resources/bugs/bug5481/module1.yang create mode 100644 yang/yang-parser-impl/src/test/resources/bugs/bug5481/module2.yang diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/AugmentUtils.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/AugmentUtils.java index 7c83a5f028..9bcedcb22b 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/AugmentUtils.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/AugmentUtils.java @@ -155,10 +155,11 @@ public final class AugmentUtils { return false; } - private static final Set NOCOPY_DEV_SET = ImmutableSet.of(Rfc6020Mapping.USES); + private static final Set 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 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 index 0000000000..703c5884bb --- /dev/null +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug5481.java @@ -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 index 0000000000..5ded8cf192 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/bugs/bug5481/module1.yang @@ -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 index 0000000000..f6b1fa3450 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/bugs/bug5481/module2.yang @@ -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; + } + } +} -- 2.36.6