Fix submodule resource resolution 06/96306/5
authorIvan Hrasko <ivan.hrasko@pantheon.tech>
Thu, 20 May 2021 10:25:37 +0000 (12:25 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 20 May 2021 18:33:14 +0000 (20:33 +0200)
Initial integration with yangtools-6.0.0 has changed the resource
resolution logic. Unfortunately the lambda instroduced in
Ifa9780fbdfb411b4613df0ee18407d85e81bd517 incorrectly passed 'module'
and not the requested entity to the resolver -- leading to all
submodules to open their module's resource instead.

Fix the lambda and also add proper asserts to check resources are being
open correctly.

JIRA: MDSAL-663
Change-Id: I293f20c15426490a97bb70b4303f0c7b23114c82
Signed-off-by: Ivan Hrasko <ivan.hrasko@pantheon.tech>
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 18ac80f3b2ff56bc734d236ba38d9cd14c5f06d7)

binding/maven-sal-api-gen-plugin/src/main/java/org/opendaylight/mdsal/binding/maven/api/gen/plugin/CodeGeneratorImpl.java
binding/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/mdsal/binding/yang/unified/doc/generator/maven/YangModuleInfoCompilationTest.java

index 4fa2004d095bbff94dc826b3d92f454c100ceb5a..a48cb6286560adf4b054f6fd47e532b1645c0f8b 100644 (file)
@@ -220,7 +220,7 @@ public final class CodeGeneratorImpl implements BasicCodeGenerator, BuildContext
         Builder<File> generatedFiles = ImmutableSet.builder();
 
         final YangModuleInfoTemplate template = new YangModuleInfoTemplate(module, ctx,
-            mod -> moduleResourcePathResolver.findModuleResourcePath(module, YangTextSchemaSource.class));
+            mod -> moduleResourcePathResolver.findModuleResourcePath(mod, YangTextSchemaSource.class));
         String moduleInfoSource = template.generate();
         if (moduleInfoSource.isEmpty()) {
             throw new IllegalStateException("Generated code should not be empty!");
index fbb4da42118ecb3ea381c434b254c5d8961dc70b..0b7c6825537aba5960d10bdbb5c1ebcf6b69c86f 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.mdsal.binding.yang.unified.doc.generator.maven;
 
+import static org.hamcrest.CoreMatchers.startsWith;
+import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
@@ -135,9 +137,13 @@ public class YangModuleInfoCompilationTest {
             }
         }
         assertNotNull(infoImport);
+        assertThat(infoImport.getYangTextCharSource().readFirstLine(), startsWith("module import-module"));
         assertNotNull(infoSub1);
+        assertThat(infoSub1.getYangTextCharSource().readFirstLine(), startsWith("submodule submodule1"));
         assertNotNull(infoSub2);
+        assertThat(infoSub2.getYangTextCharSource().readFirstLine(), startsWith("submodule submodule2"));
         assertNotNull(infoSub3);
+        assertThat(infoSub3.getYangTextCharSource().readFirstLine(), startsWith("submodule submodule3"));
 
         cleanUp(sourcesOutputDir, compiledOutputDir);
     }