RFC8040 'rc:yang-data' support for mdsal binding generator
[mdsal.git] / binding / mdsal-binding-java-api-generator / src / test / java / org / opendaylight / mdsal / binding / java / api / generator / CompilationTest.java
index 4c240dd885c3c4d891d7934bf6aeb319c8ce3017..53ce2472609e67828a4f7c76927a454a3d320219 100644 (file)
@@ -792,7 +792,7 @@ public class CompilationTest extends BaseCompilationTest {
         generateTestSources("/compilation/union-string-pattern", sourcesOutputDir);
         CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
 
-        final ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() });
+        final ClassLoader loader = new URLClassLoader(new URL[]{compiledOutputDir.toURI().toURL()});
         final Class<?> fooClass = Class.forName(CompilationTestUtils.BASE_PKG + ".foo.norev.Foo", true, loader);
 
         final Field patterns = fooClass.getDeclaredField(TypeConstants.PATTERN_CONSTANT_NAME);
@@ -801,6 +801,67 @@ public class CompilationTest extends BaseCompilationTest {
         CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
     }
 
+    @Test
+    public void yangDataCompilation() throws Exception {
+        final File sourcesOutputDir = CompilationTestUtils.generatorOutput("yang-data-gen");
+        final File compiledOutputDir = CompilationTestUtils.compilerOutput("yang-data-gen");
+
+        generateTestSources("/compilation/yang-data-gen", sourcesOutputDir);
+        CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
+
+        final ClassLoader loader = new URLClassLoader(new URL[]{compiledOutputDir.toURI().toURL()});
+        final List<String> artifactNames = List.of(
+                // module with top level container
+                "$YangModuleInfoImpl", "YangDataDemoData", "RootContainer", "RootContainerBuilder",
+
+                // yang-data artifacts
+                "YangDataWithContainer", "YangDataWithContainerBuilder",
+                "YangDataWithList", "YangDataWithListBuilder",
+                "YangDataWithLeaf", "YangDataWithLeafBuilder",
+                "YangDataWithLeafList", "YangDataWithLeafListBuilder",
+                "YangDataWithAnydata", "YangDataWithAnydataBuilder",
+                "YangDataWithAnyxml", "YangDataWithAnyxmlBuilder",
+
+                // yang-data content artifacts
+                "yang.data.with.container.ContainerFromYangData",
+                "yang.data.with.container.ContainerFromYangDataBuilder",
+                "yang.data.with.list.ListFromYangData", "yang.data.with.list.ListFromYangDataBuilder",
+                "yang.data.with.anydata.AnydataFromYangData", "yang.data.with.anyxml.AnyxmlFromYangData",
+
+                // yang-data artifacts using groups
+                "YangDataWithContainerFromGroup", "YangDataWithContainerFromGroupBuilder",
+                "YangDataWithListFromGroup", "YangDataWithListFromGroupBuilder",
+                "YangDataWithLeafFromGroup", "YangDataWithLeafFromGroupBuilder",
+                "YangDataWithLeafListFromGroup", "YangDataWithLeafListFromGroupBuilder",
+                "YangDataWithAnydataFromGroup", "YangDataWithAnydataFromGroupBuilder",
+                "YangDataWithAnyxmlFromGroup", "YangDataWithAnyxmlFromGroupBuilder",
+
+                // group artifacts
+                "GrpForContainer", "GrpForList", "GrpForLeaf", "GrpForLeafList", "GrpForAnydata", "GrpForAnyxml",
+
+                // group content artifacts
+                "grp._for.container.ContainerFromGroup", "grp._for.container.ContainerFromGroupBuilder",
+                "grp._for.list.ListFromGroup", "grp._for.list.ListFromGroupBuilder",
+                "grp._for.anydata.AnydataFromGroup", "grp._for.anyxml.AnyxmlFromGroup",
+
+                // artifacts for non-ascii template naming: yang data artifact, inner container + builder
+                "$ľaľaho$20$papľuhu", "$ľaľaho$20$papľuhuBuilder",
+                "$ľaľaho$20$papľuhu$.LatinNaming", "$ľaľaho$20$papľuhu$.LatinNamingBuilder",
+                "привет", "приветBuilder", "привет$.CyrillicNaming", "привет$.CyrillicNamingBuilder"
+        );
+
+        for (String name : artifactNames) {
+            final String className = CompilationTestUtils.BASE_PKG + ".urn.test.yang.data.demo.rev220222." + name;
+            // ensure class source is generated
+            final String srcPath = className.replace('.', File.separatorChar) + ".java";
+            assertTrue(srcPath + " exists", new File(sourcesOutputDir, srcPath).exists());
+            // ensure class is loadable
+            Class.forName(className, true, loader);
+        }
+
+        CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
+    }
+
     private static void testReturnTypeIdentityref(final Class<?> clazz, final String methodName,
             final String returnTypeStr) throws NoSuchMethodException {
         Class<?> returnType = clazz.getMethod(methodName).getReturnType();