DTOs for anydata/anyxml are not generated within a list 05/86605/3
authorwusandi <wusandi@163.com>
Wed, 25 Dec 2019 12:04:16 +0000 (20:04 +0800)
committerRobert Varga <nite@hq.sk>
Sat, 28 Dec 2019 21:04:52 +0000 (21:04 +0000)
Code generation for container and list statements follows different
code paths and we have missed a hook in the latter to generate
opaque objects.

JIRA: MDSAL-506
Change-Id: I25a54362ceb09937ffe796081660afe7fa1d6bb2
Signed-off-by: wusandi <wusandi@163.com>
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit e905b3d4792076251ddc276fa248e441bba157b2)

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/Mdsal506Test.java [new file with mode: 0644]
binding/mdsal-binding-generator-impl/src/test/resources/mdsal506.yang [new file with mode: 0644]
binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/mdsal/binding/java/api/generator/test/CompilationTest.java

index 05a1fedc3d8f2717c5c2694563b762fd361f90b5..59ab7e26ff6841e768be623f67c6d56e565b7edd 100644 (file)
@@ -1809,6 +1809,8 @@ abstract class AbstractTypeGenerator {
                 choiceToGeneratedType(context, typeBuilder, (ChoiceSchemaNode) schemaNode, inGrouping);
             } else if (schemaNode instanceof ListSchemaNode) {
                 listToGenType(context, typeBuilder, childOf(typeBuilder), (ListSchemaNode) schemaNode, inGrouping);
+            } else if (schemaNode instanceof AnyXmlSchemaNode || schemaNode instanceof AnyDataSchemaNode) {
+                opaqueToGeneratedType(context, typeBuilder, schemaNode);
             }
         }
     }
diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/mdsal/binding/generator/impl/Mdsal506Test.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/mdsal/binding/generator/impl/Mdsal506Test.java
new file mode 100644 (file)
index 0000000..0f1833a
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2019 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.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 Mdsal506Test extends AbstractOpaqueTest {
+    @Test
+    public void generateAnydataTest() {
+        final SchemaContext context = YangParserTestUtils.parseYangResource("/mdsal506.yang");
+
+        final List<Type> types = new BindingGeneratorImpl().generateTypes(context);
+        assertNotNull(types);
+        assertEquals(4, types.size());
+
+        assertOpaqueNode(types, "mdsal506", ".lst", "TestAnydata");
+        assertOpaqueNode(types, "mdsal506", ".lst", "TestAnyxml");
+    }
+}
diff --git a/binding/mdsal-binding-generator-impl/src/test/resources/mdsal506.yang b/binding/mdsal-binding-generator-impl/src/test/resources/mdsal506.yang
new file mode 100644 (file)
index 0000000..7de3ee0
--- /dev/null
@@ -0,0 +1,11 @@
+module mdsal506 {
+    yang-version 1.1;
+    prefix mdsal506;
+    namespace mdsal506;
+
+    list lst {
+        anydata test-anydata;
+        anyxml test-anyxml;
+    }
+}
+
index a50ac877b388de80f78c611e6607dfbdb4051418..a62dc5ad4dce0fc78f8540510e90a5dc766ed61c 100644 (file)
@@ -90,7 +90,7 @@ public class CompilationTest extends BaseCompilationTest {
         assertTrue(nodeList.exists());
         assertTrue(nodeListBuilder.exists());
         assertTrue(nodesType.exists());
-        CompilationTestUtils.assertFilesCount(parent, 7);
+        CompilationTestUtils.assertFilesCount(parent, 8);
 
         // Test if sources are compilable
         CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
@@ -112,8 +112,7 @@ public class CompilationTest extends BaseCompilationTest {
         // Test generated 'list links'
         assertTrue(linksClass.isInterface());
         CompilationTestUtils.assertImplementsIfc(linksClass, keyArgsClass);
-        // TODO: anyxml
-        assertEquals(6, abstractMethods(linksClass).size());
+        assertEquals(7, abstractMethods(linksClass).size());
 
         // Test list key constructor arguments ordering
         CompilationTestUtils.assertContainsConstructor(linksKeyClass, Byte.class, String.class, Integer.class);