Fix submodule resource resolution 86/96286/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 15:17:39 +0000 (17:17 +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>
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 5506cc26d3915243e011f1af4c8c743e06c489ef..d3459d1a98d7794b54319ed0914651c000c27fd8 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);
     }