From 112e71e50c0f2bdff0f4aaec40d080f911db7091 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Fri, 28 May 2021 00:34:47 +0200 Subject: [PATCH] Fix DataTree indexing Our indexing is broken here, as if we have a schema tree statement which is not propagated to data tree, we should be indicating a difference in maps. Fix that up. JIRA: YANGTOOLS-1292 Change-Id: I19d80a11ef7114b0908766fa19df51604ca83f2e Signed-off-by: Robert Varga --- .../spi/meta/AbstractEffectiveStatement.java | 5 +- .../yangtools/yang/model/util/YT1292Test.java | 75 +++++++++++++++++++ .../src/test/resources/yt1292.yang | 15 ++++ 3 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 model/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/YT1292Test.java create mode 100644 model/yang-model-util/src/test/resources/yt1292.yang diff --git a/model/yang-model-spi/src/main/java/org/opendaylight/yangtools/yang/model/spi/meta/AbstractEffectiveStatement.java b/model/yang-model-spi/src/main/java/org/opendaylight/yangtools/yang/model/spi/meta/AbstractEffectiveStatement.java index ffe226f74e..d46dbebbe7 100644 --- a/model/yang-model-spi/src/main/java/org/opendaylight/yangtools/yang/model/spi/meta/AbstractEffectiveStatement.java +++ b/model/yang-model-spi/src/main/java/org/opendaylight/yangtools/yang/model/spi/meta/AbstractEffectiveStatement.java @@ -123,16 +123,13 @@ abstract class AbstractEffectiveStatement> } } } - return false; } else if (stmt instanceof CaseEffectiveStatement) { // For case statements go through all their statements for (EffectiveStatement child : stmt.effectiveSubstatements()) { indexDataTree(map, child); } - return false; - } else { - return true; } + return false; } private static > void putChild(final Map map, final T child, diff --git a/model/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/YT1292Test.java b/model/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/YT1292Test.java new file mode 100644 index 0000000000..46d7e349ff --- /dev/null +++ b/model/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/YT1292Test.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2021 PANTHEON.tech, s.r.o. 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.model.util; + +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertEquals; + +import com.google.common.collect.Iterables; +import java.util.Optional; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.model.api.stmt.ActionEffectiveStatement; +import org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement; +import org.opendaylight.yangtools.yang.model.api.stmt.DataTreeEffectiveStatement; +import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement; +import org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement; +import org.opendaylight.yangtools.yang.model.api.stmt.RpcEffectiveStatement; +import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement; +import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; + +public class YT1292Test { + private static final QName FOO = QName.create("foo", "foo"); + private static final QName BAR = QName.create("foo", "bar"); + private static final QName BAZ = QName.create("foo", "baz"); + + private static ModuleEffectiveStatement module; + + private ContainerEffectiveStatement baz; + + @BeforeClass + public static void beforeClass() { + module = Iterables.getOnlyElement(YangParserTestUtils.parseYangResource("/yt1292.yang").getModuleStatements() + .values()); + } + + @Before + public void before() { + final DataTreeEffectiveStatement tmp = module.findDataTreeNode(BAZ).orElseThrow(); + assertThat(tmp, instanceOf(ContainerEffectiveStatement.class)); + baz = (ContainerEffectiveStatement) tmp; + } + + @Test + public void testRpc() { + assertEquals(Optional.empty(), module.findDataTreeNode(FOO)); + final SchemaTreeEffectiveStatement foo = module.findSchemaTreeNode(FOO).orElseThrow(); + assertThat(foo, instanceOf(RpcEffectiveStatement.class)); + } + + @Test + public void testNotification() { + assertEquals(Optional.empty(), module.findDataTreeNode(BAR)); + SchemaTreeEffectiveStatement bar = module.findSchemaTreeNode(BAR).orElseThrow(); + assertThat(bar, instanceOf(NotificationEffectiveStatement.class)); + + assertEquals(Optional.empty(), baz.findDataTreeNode(BAR)); + bar = baz.findSchemaTreeNode(BAR).orElseThrow(); + assertThat(bar, instanceOf(NotificationEffectiveStatement.class)); + } + + @Test + public void testAction() { + assertEquals(Optional.empty(), baz.findDataTreeNode(FOO)); + final SchemaTreeEffectiveStatement foo = baz.findSchemaTreeNode(FOO).orElseThrow(); + assertThat(foo, instanceOf(ActionEffectiveStatement.class)); + } +} diff --git a/model/yang-model-util/src/test/resources/yt1292.yang b/model/yang-model-util/src/test/resources/yt1292.yang new file mode 100644 index 0000000000..16a6e5667a --- /dev/null +++ b/model/yang-model-util/src/test/resources/yt1292.yang @@ -0,0 +1,15 @@ +module foo { + namespace foo; + prefix foo; + yang-version 1.1; + + rpc foo; + + notification bar; + + container baz { + action foo; + + notification bar; + } +} -- 2.36.6