Expand test suite to cover uses-augment of actions 46/88146/1
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 28 Feb 2020 17:39:51 +0000 (18:39 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sat, 29 Feb 2020 08:15:22 +0000 (09:15 +0100)
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 <robert.varga@pantheon.tech>
binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/mdsal/binding/generator/impl/AbstractTypeGenerator.java
binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/mdsal/binding/generator/impl/Mdsal517Test.java
binding/mdsal-binding-generator-impl/src/test/resources/mdsal-517/baz.yang [new file with mode: 0644]

index f536e84bcdec3393482d0b197be211dc508c1ed0..447ba7cb804a0a02e22bd449b7243de00ea5d440 100644 (file)
@@ -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) {
index b667da32499b783c8ecefb2363bedb5d3b43fa1d..1901a75c743ebd1a8f9a2c05695c0d02adb2222b 100644 (file)
@@ -21,6 +21,6 @@ public class Mdsal517Test extends AbstractOpaqueTest {
         final List<Type> 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 (file)
index 0000000..7fe1904
--- /dev/null
@@ -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;
+        }
+      }
+    }
+  }
+}