From: Robert Varga Date: Fri, 28 Feb 2020 17:39:51 +0000 (+0100) Subject: Expand test suite to cover uses-augment of actions X-Git-Tag: v4.0.12~4 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F46%2F88146%2F1;p=mdsal.git Expand test suite to cover uses-augment of actions Augment can also target a relative path from uses context, this expands the testing model to cover that case, too. The test case flushes out the problem of not handling action/notification nodes when targeted in this manner, leading to an obvious hiccup. JIRA: MDSAL-517 Change-Id: If389440622c31f544917b04e3825fe6e08e08244 Signed-off-by: Robert Varga --- diff --git a/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/impl/AbstractTypeGenerator.java b/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/impl/AbstractTypeGenerator.java index f536e84bcd..447ba7cb80 100644 --- a/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/impl/AbstractTypeGenerator.java +++ b/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/impl/AbstractTypeGenerator.java @@ -916,11 +916,37 @@ abstract class AbstractTypeGenerator { private DataSchemaNode findOriginalTargetFromGrouping(final SchemaPath targetPath, final UsesNode parentUsesNode) { SchemaNode result = findUsedGrouping(parentUsesNode); for (final QName node : targetPath.getPathFromRoot()) { + // FIXME: this dispatch is rather ugly, we probably want to refactor it a bit if (result instanceof DataNodeContainer) { final QName resultNode = node.withModule(result.getQName().getModule()); - result = ((DataNodeContainer) result).getDataChildByName(resultNode); + + SchemaNode found = ((DataNodeContainer) result).getDataChildByName(resultNode); + if (found == null) { + if (result instanceof ActionNodeContainer) { + found = ((ActionNodeContainer) result).findAction(resultNode).orElse(null); + } + if (found == null && result instanceof NotificationNodeContainer) { + found = ((NotificationNodeContainer) result).findNotification(resultNode).orElse(null); + } + } + result = found; } else if (result instanceof ChoiceSchemaNode) { result = findNamedCase((ChoiceSchemaNode) result, node.getLocalName()); + } else if (result instanceof ActionDefinition) { + final ActionDefinition action = (ActionDefinition) result; + final QName resultNode = node.withModule(result.getQName().getModule()); + + final ContainerSchemaNode input = action.getInput(); + final ContainerSchemaNode output = action.getOutput(); + if (resultNode.equals(input.getQName())) { + result = input; + } else if (resultNode.equals(output.getQName())) { + result = output; + } else { + result = null; + } + } else if (result != null) { + throw new IllegalStateException("Cannot handle " + result); } } if (result == null) { diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/mdsal/binding/generator/impl/Mdsal517Test.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/mdsal/binding/generator/impl/Mdsal517Test.java index b667da3249..1901a75c74 100644 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/mdsal/binding/generator/impl/Mdsal517Test.java +++ b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/mdsal/binding/generator/impl/Mdsal517Test.java @@ -21,6 +21,6 @@ public class Mdsal517Test extends AbstractOpaqueTest { final List types = new BindingGeneratorImpl().generateTypes( YangParserTestUtils.parseYangResourceDirectory("/mdsal-517")); assertNotNull(types); - assertEquals(7, types.size()); + assertEquals(11, types.size()); } } diff --git a/binding/mdsal-binding-generator-impl/src/test/resources/mdsal-517/baz.yang b/binding/mdsal-binding-generator-impl/src/test/resources/mdsal-517/baz.yang new file mode 100644 index 0000000000..7fe190421e --- /dev/null +++ b/binding/mdsal-binding-generator-impl/src/test/resources/mdsal-517/baz.yang @@ -0,0 +1,19 @@ +module baz { + yang-version 1.1; + namespace "baz"; + prefix baz; + + import foo { + prefix foo; + } + + container baz-cont { + uses foo:foo-grp { + augment foo-act/input { + leaf baz-aug-leaf { + type string; + } + } + } + } +}