Add action tests 82/73982/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 12 Jul 2018 14:56:51 +0000 (16:56 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 12 Jul 2018 15:01:14 +0000 (17:01 +0200)
This adds a very basic test, which uncovered a failure to deal
with actions being multiply-inherited -- and fixes that issue.

Also a test model is added, so higher-layer components can be
tested.

Change-Id: I775341e2860e06f360fd4c6c6f6449e96ed92c64
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/ActionsTest.java [new file with mode: 0644]
binding/mdsal-binding-generator-impl/src/test/resources/actions.yang [new file with mode: 0644]
binding/mdsal-binding-test-model/src/main/yang/actions.yang [new file with mode: 0644]

index 579ca1c24f897424b5704610eeaf2388aec6b9ab..115299052a0a4cd1e89b537cc6c5b0475d98c675 100644 (file)
@@ -409,7 +409,7 @@ abstract class AbstractTypeGenerator {
             final GeneratedType input;
             final GeneratedType output;
             if (action.isAddedByUses()) {
-                final ActionDefinition orig = findAction(parentSchema, action).get();
+                final ActionDefinition orig = findOrigAction(parentSchema, action).get();
                 input = context.getChildNode(orig.getInput().getPath()).build();
                 output = context.getChildNode(orig.getOutput().getPath()).build();
             } else {
@@ -435,11 +435,18 @@ abstract class AbstractTypeGenerator {
         }
     }
 
-    private Optional<ActionDefinition> findAction(final DataNodeContainer parent, final ActionDefinition action) {
-        return parent.getUses().stream()
-                .flatMap(uses -> findUsedGrouping(uses).getActions().stream())
-                .filter(act -> action.getQName().equals(act.getQName()))
-                .findFirst();
+    private Optional<ActionDefinition> findOrigAction(final DataNodeContainer parent, final ActionDefinition action) {
+        for (UsesNode uses : parent.getUses()) {
+            final GroupingDefinition grp = findUsedGrouping(uses);
+            final Optional<ActionDefinition> found = grp.getActions().stream()
+                    .filter(act -> action.getQName().equals(act.getQName())).findFirst();
+            if (found.isPresent()) {
+                final ActionDefinition result = found.get();
+                return result.isAddedByUses() ? findOrigAction(grp, result) : found;
+            }
+        }
+
+        return Optional.empty();
     }
 
     private GeneratedType actionContainer(final ModuleContext context, final Type baseInterface,
diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/mdsal/binding/generator/impl/ActionsTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/mdsal/binding/generator/impl/ActionsTest.java
new file mode 100644 (file)
index 0000000..fd1ffda
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2018 Pantheon Technologies, 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.mdsal.binding.generator.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.List;
+import org.junit.Test;
+import org.opendaylight.mdsal.binding.model.api.Type;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
+
+public class ActionsTest {
+    @Test
+    public void actionsTypeTest() {
+        SchemaContext context = YangParserTestUtils.parseYangResource("/actions.yang");
+
+        List<Type> generateTypes = new BindingGeneratorImpl().generateTypes(context);
+        assertNotNull(generateTypes);
+        assertEquals(13, generateTypes.size());
+    }
+}
diff --git a/binding/mdsal-binding-generator-impl/src/test/resources/actions.yang b/binding/mdsal-binding-generator-impl/src/test/resources/actions.yang
new file mode 100644 (file)
index 0000000..4ea4a54
--- /dev/null
@@ -0,0 +1,30 @@
+module actions {
+    yang-version 1.1;
+    prefix act;
+    namespace "urn:odl:actions";
+
+    container cont {
+        action foo {
+        
+        }
+    }
+
+    grouping grp {
+        action bar {
+
+        }
+    }
+
+    grouping other {
+        uses grp;
+    }
+
+    container grpcont {
+        uses grp;
+    }
+
+    container othercont {
+        uses other;
+    }
+}
+
diff --git a/binding/mdsal-binding-test-model/src/main/yang/actions.yang b/binding/mdsal-binding-test-model/src/main/yang/actions.yang
new file mode 100644 (file)
index 0000000..4ea4a54
--- /dev/null
@@ -0,0 +1,30 @@
+module actions {
+    yang-version 1.1;
+    prefix act;
+    namespace "urn:odl:actions";
+
+    container cont {
+        action foo {
+        
+        }
+    }
+
+    grouping grp {
+        action bar {
+
+        }
+    }
+
+    grouping other {
+        uses grp;
+    }
+
+    container grpcont {
+        uses grp;
+    }
+
+    container othercont {
+        uses other;
+    }
+}
+