From: Peter Kajsa Date: Fri, 29 Jan 2016 12:35:40 +0000 (+0100) Subject: Bug 5101: Status deprecated must not be propagated via uses statement X-Git-Tag: release/beryllium~10 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=yangtools.git;a=commitdiff_plain;h=3cc7cab94a7d0cdde5d81b9b1ca464b50d1c23c4 Bug 5101: Status deprecated must not be propagated via uses statement Status of grouping statement is not propagated via uses statement. Change-Id: I2c2bf9d9222ea1be78b440c5c52ea675dcaeb89d Signed-off-by: Peter Kajsa (cherry picked from commit 660b3a15a0da5e2212e64f35edfdd3444d145050) --- diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/GroupingUtils.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/GroupingUtils.java index 8106aa6350..0273150679 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/GroupingUtils.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/GroupingUtils.java @@ -117,14 +117,14 @@ public final class GroupingUtils { return true; } - private static final Set NOCOPY_DEF_SET = ImmutableSet.of( - Rfc6020Mapping.USES, Rfc6020Mapping.TYPEDEF, Rfc6020Mapping.TYPE); - private static final Set NOCOPY_FROM_GROUPING_SET = ImmutableSet.of( - Rfc6020Mapping.DESCRIPTION, Rfc6020Mapping.REFERENCE); - private static final Set REUSED_DEF_SET = ImmutableSet.of( - Rfc6020Mapping.TYPEDEF, Rfc6020Mapping.TYPE, Rfc6020Mapping.USES); - private static final Set TOP_REUSED_DEF_SET = ImmutableSet.of( - Rfc6020Mapping.TYPEDEF, Rfc6020Mapping.TYPE); + private static final Set NOCOPY_DEF_SET = ImmutableSet.of(Rfc6020Mapping.USES, + Rfc6020Mapping.TYPEDEF, Rfc6020Mapping.TYPE); + private static final Set NOCOPY_FROM_GROUPING_SET = ImmutableSet.of(Rfc6020Mapping.DESCRIPTION, + Rfc6020Mapping.REFERENCE, Rfc6020Mapping.STATUS); + private static final Set REUSED_DEF_SET = ImmutableSet.of(Rfc6020Mapping.TYPEDEF, + Rfc6020Mapping.TYPE, Rfc6020Mapping.USES); + private static final Set 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 index 0000000000..38e26a2e05 --- /dev/null +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/Bug5101.java @@ -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 index 0000000000..206ec74d9c --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/bugs/bug5101/foo.yang @@ -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; +}