$YangModuleInfoImpl not generated for only extensions model
[mdsal.git] / binding / mdsal-binding-java-api-generator / src / test / java / org / opendaylight / mdsal / binding / java / api / generator / test / CompilationTest.java
index 7499d8fe8088e3134b80ab1177ff546a6caa3aee..aa6fba71f3eec286fcc785d82b69843473c0d8f3 100644 (file)
@@ -12,9 +12,11 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
 import com.google.common.collect.Collections2;
+import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Range;
 import java.io.File;
+import java.io.IOException;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
@@ -22,21 +24,22 @@ import java.lang.reflect.Modifier;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.WildcardType;
 import java.math.BigDecimal;
-import java.math.BigInteger;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.List;
+import java.util.stream.Collectors;
 import org.junit.Test;
-import org.opendaylight.mdsal.binding.java.api.generator.GeneratorJavaFile;
-import org.opendaylight.mdsal.binding.model.api.Type;
 import org.opendaylight.yangtools.yang.binding.ChildOf;
 import org.opendaylight.yangtools.yang.binding.annotations.RoutingContext;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
+import org.opendaylight.yangtools.yang.common.Empty;
+import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint64;
+import org.opendaylight.yangtools.yang.common.Uint8;
 
 /**
  * Test correct code generation.
@@ -51,16 +54,14 @@ public class CompilationTest extends BaseCompilationTest {
      */
     private static Collection<Method> abstractMethods(final Class<?> clazz) {
         // Filter out
-        return Collections2.filter(Arrays.asList(clazz.getDeclaredMethods()), input -> Modifier.isAbstract(input.getModifiers()));
+        return Collections2.filter(Arrays.asList(clazz.getDeclaredMethods()),
+            input -> Modifier.isAbstract(input.getModifiers()));
     }
 
     @Test
     public void testListGeneration() throws Exception {
-        final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "list-gen");
-        assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir());
-        final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "list-gen");
-        assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
-
+        final File sourcesOutputDir = CompilationTestUtils.generatorOutput("list-gen");
+        final File compiledOutputDir = CompilationTestUtils.compilerOutput("list-gen");
         generateTestSources("/compilation/list-gen", sourcesOutputDir);
 
         // Test if all sources are generated
@@ -75,7 +76,7 @@ public class CompilationTest extends BaseCompilationTest {
         assertTrue(linksBuilder.exists());
         assertTrue(linksKey.exists());
         assertTrue(testData.exists());
-        CompilationTestUtils.assertFilesCount(parent, 6);
+        CompilationTestUtils.assertFilesCount(parent, 7);
 
         parent = new File(sourcesOutputDir, CompilationTestUtils.NS_TEST + CompilationTestUtils.FS + "links");
         final File level = new File(parent, "Level.java");
@@ -92,27 +93,29 @@ 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);
 
         final ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() });
-        final Class<?> keyArgsClass = Class.forName(CompilationTestUtils.BASE_PKG + ".urn.opendaylight.test.rev131008.KeyArgs", true, loader);
-        final Class<?> linksClass = Class.forName(CompilationTestUtils.BASE_PKG + ".urn.opendaylight.test.rev131008.Links", true, loader);
-        final Class<?> linksKeyClass = Class.forName(CompilationTestUtils.BASE_PKG + ".urn.opendaylight.test.rev131008.LinksKey", true, loader);
+        final Class<?> keyArgsClass = Class.forName(CompilationTestUtils.BASE_PKG
+            + ".urn.opendaylight.test.rev131008.KeyArgs", true, loader);
+        final Class<?> linksClass = Class.forName(CompilationTestUtils.BASE_PKG
+            + ".urn.opendaylight.test.rev131008.Links", true, loader);
+        final Class<?> linksKeyClass = Class.forName(CompilationTestUtils.BASE_PKG
+            + ".urn.opendaylight.test.rev131008.LinksKey", true, loader);
 
         // Test generated 'grouping key-args'
         assertTrue(keyArgsClass.isInterface());
         CompilationTestUtils.assertContainsMethod(keyArgsClass, String.class, "getName");
         CompilationTestUtils.assertContainsMethod(keyArgsClass, Integer.class, "getSize");
-        assertEquals(2, abstractMethods(keyArgsClass).size());
+        assertEquals(3, abstractMethods(keyArgsClass).size());
 
         // 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);
@@ -126,11 +129,8 @@ public class CompilationTest extends BaseCompilationTest {
 
     @Test
     public void testAugmentUnderUsesGeneration() throws Exception {
-        final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "augment-under-uses");
-        assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir());
-        final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "augment-under-uses");
-        assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
-
+        final File sourcesOutputDir = CompilationTestUtils.generatorOutput("augment-under-uses");
+        final File compiledOutputDir = CompilationTestUtils.compilerOutput("augment-under-uses");
         generateTestSources("/compilation/augment-under-uses", sourcesOutputDir);
 
         // Test if all sources were generated from 'module foo'
@@ -140,7 +140,7 @@ public class CompilationTest extends BaseCompilationTest {
         assertTrue(new File(parent, "OpenObject.java").exists());
         assertTrue(new File(parent, "ExplicitRouteObject.java").exists());
         assertTrue(new File(parent, "PathKeySubobject.java").exists());
-        CompilationTestUtils.assertFilesCount(parent, 9);
+        CompilationTestUtils.assertFilesCount(parent, 10);
 
         parent = new File(parent, "object");
         assertTrue(new File(parent, "Nodes.java").exists());
@@ -198,7 +198,7 @@ public class CompilationTest extends BaseCompilationTest {
         assertTrue(new File(parent, "BasicExplicitRouteSubobjects.java").exists());
         assertTrue(new File(parent, "ExplicitRouteSubobjects.java").exists());
         assertTrue(new File(parent, "RouteSubobjects.java").exists());
-        CompilationTestUtils.assertFilesCount(parent, 5);
+        CompilationTestUtils.assertFilesCount(parent, 6);
 
         parent = new File(parent, "route");
         CompilationTestUtils.assertFilesCount(parent, 1);
@@ -231,11 +231,8 @@ public class CompilationTest extends BaseCompilationTest {
 
     @Test
     public void testAugmentOfAugmentGeneration() throws Exception {
-        final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "aug-of-aug");
-        assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir());
-        final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "aug-of-aug");
-        assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
-
+        final File sourcesOutputDir = CompilationTestUtils.generatorOutput("aug-of-aug");
+        final File compiledOutputDir = CompilationTestUtils.compilerOutput("aug-of-aug");
         generateTestSources("/compilation/augment-of-augment", sourcesOutputDir);
 
         // Test if all sources were generated from 'module foo'
@@ -248,7 +245,7 @@ public class CompilationTest extends BaseCompilationTest {
         assertTrue(pathAttributes.exists());
         assertTrue(update.exists());
         assertTrue(updateBuilder.exists());
-        CompilationTestUtils.assertFilesCount(parent, 6);
+        CompilationTestUtils.assertFilesCount(parent, 7);
 
         parent = new File(sourcesOutputDir, CompilationTestUtils.NS_FOO + CompilationTestUtils.FS + "path");
         CompilationTestUtils.assertFilesCount(parent, 1);
@@ -274,7 +271,7 @@ public class CompilationTest extends BaseCompilationTest {
         assertTrue(destination.exists());
         assertTrue(pathAttributes1.exists());
         assertTrue(pathAttributes1Builder.exists());
-        CompilationTestUtils.assertFilesCount(parent, 5);
+        CompilationTestUtils.assertFilesCount(parent, 6);
 
         parent = new File(sourcesOutputDir, CompilationTestUtils.NS_BAR + CompilationTestUtils.FS + "destination");
         CompilationTestUtils.assertFilesCount(parent, 2);
@@ -314,7 +311,7 @@ public class CompilationTest extends BaseCompilationTest {
 
         // Test if all sources were generated from 'module baz'
         parent = new File(sourcesOutputDir, CompilationTestUtils.NS_BAZ);
-        CompilationTestUtils.assertFilesCount(parent, 2);
+        CompilationTestUtils.assertFilesCount(parent, 3);
         final File linkstateDestination = new File(parent, "LinkstateDestination.java");
         assertTrue(linkstateDestination.exists());
 
@@ -371,11 +368,8 @@ public class CompilationTest extends BaseCompilationTest {
 
     @Test
     public void testLeafReturnTypes() throws Exception {
-        final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "leaf-return-types");
-        assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir());
-        final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "leaf-return-types");
-        assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
-
+        final File sourcesOutputDir = CompilationTestUtils.generatorOutput("leaf-return-types");
+        final File compiledOutputDir = CompilationTestUtils.compilerOutput("leaf-return-types");
         generateTestSources("/compilation/leaf-return-types", sourcesOutputDir);
 
         final File parent = new File(sourcesOutputDir, CompilationTestUtils.NS_TEST);
@@ -384,7 +378,7 @@ public class CompilationTest extends BaseCompilationTest {
         assertTrue(new File(parent, "NodesBuilder.java").exists());
         assertTrue(new File(parent, "Alg.java").exists());
         assertTrue(new File(parent, "NodesIdUnionBuilder.java").exists());
-        CompilationTestUtils.assertFilesCount(parent, 5);
+        CompilationTestUtils.assertFilesCount(parent, 6);
 
         // Test if sources are compilable
         CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
@@ -400,7 +394,7 @@ public class CompilationTest extends BaseCompilationTest {
         CompilationTestUtils.assertContainsMethod(nodesClass, pkg + ".Nodes$IdBits", "getIdBits", loader);
         CompilationTestUtils.assertContainsMethod(nodesClass, Boolean.class, "isIdBoolean");
         CompilationTestUtils.assertContainsMethod(nodesClass, BigDecimal.class, "getIdDecimal64");
-        CompilationTestUtils.assertContainsMethod(nodesClass, Boolean.class, "isIdEmpty");
+        CompilationTestUtils.assertContainsMethod(nodesClass, Empty.class, "getIdEmpty");
         CompilationTestUtils.assertContainsMethod(nodesClass, pkg + ".Nodes$IdEnumeration", "getIdEnumeration", loader);
         testReturnTypeIdentityref(nodesClass, "getIdIdentityref", pkg + ".Alg");
         testReturnTypeInstanceIdentitifer(loader, nodesClass, "getIdInstanceIdentifier");
@@ -410,89 +404,83 @@ public class CompilationTest extends BaseCompilationTest {
         CompilationTestUtils.assertContainsMethod(nodesClass, Long.class, "getId64");
         CompilationTestUtils.assertContainsMethod(nodesClass, Long.class, "getIdLeafref");
         CompilationTestUtils.assertContainsMethod(nodesClass, String.class, "getIdString");
-        CompilationTestUtils.assertContainsMethod(nodesClass, Short.class, "getIdU8");
-        CompilationTestUtils.assertContainsMethod(nodesClass, Integer.class, "getIdU16");
-        CompilationTestUtils.assertContainsMethod(nodesClass, Long.class, "getIdU32");
-        CompilationTestUtils.assertContainsMethod(nodesClass, BigInteger.class, "getIdU64");
+        CompilationTestUtils.assertContainsMethod(nodesClass, Uint8.class, "getIdU8");
+        CompilationTestUtils.assertContainsMethod(nodesClass, Uint16.class, "getIdU16");
+        CompilationTestUtils.assertContainsMethod(nodesClass, Uint32.class, "getIdU32");
+        CompilationTestUtils.assertContainsMethod(nodesClass, Uint64.class, "getIdU64");
         CompilationTestUtils.assertContainsMethod(nodesClass, pkg + ".Nodes$IdUnion", "getIdUnion", loader);
 
-        final Object builderObj = builderClass.newInstance();
+        final Object builderObj = builderClass.getDeclaredConstructor().newInstance();
 
-        Method m = CompilationTestUtils.assertContainsMethod(builderClass, builderClass, "setIdBinary", b.getClass());
+        Method method = CompilationTestUtils.assertContainsMethod(builderClass, builderClass, "setIdBinary",
+            b.getClass());
         final List<Range<Integer>> lengthConstraints = new ArrayList<>();
         lengthConstraints.add(Range.closed(1, 10));
         byte[] arg = new byte[] {};
-        String expectedMsg = String.format("Invalid length: %s, expected: %s.", Arrays.toString(arg), lengthConstraints);
-        CompilationTestUtils.assertContainsRestrictionCheck(builderObj, m, expectedMsg, arg);
+        String expectedMsg = String.format("Invalid length: %s, expected: %s.", Arrays.toString(arg),
+            lengthConstraints);
+        CompilationTestUtils.assertContainsRestrictionCheck(builderObj, method, expectedMsg, arg);
 
-        m = CompilationTestUtils.assertContainsMethod(builderClass, builderClass, "setIdDecimal64", BigDecimal.class);
+        method = CompilationTestUtils.assertContainsMethod(builderClass, builderClass, "setIdDecimal64",
+            BigDecimal.class);
         final List<Range<BigDecimal>> rangeConstraints = new ArrayList<>();
         rangeConstraints.add(Range.closed(new BigDecimal("1.5"), new BigDecimal("5.5")));
         Object arg1 = new BigDecimal("1.4");
         expectedMsg = String.format("Invalid range: %s, expected: %s.", arg1, rangeConstraints);
-        CompilationTestUtils.assertContainsRestrictionCheck(builderObj, m, expectedMsg, arg1);
+        CompilationTestUtils.assertContainsRestrictionCheck(builderObj, method, expectedMsg, arg1);
 
         CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
     }
 
     @Test
-    public void testGenerationContextReferenceExtension() throws Exception {
-        final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "context-reference");
-        assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir());
-        final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "context-reference");
-        assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
-
+    public void testGenerationContextReferenceExtension() throws IOException, URISyntaxException,
+            ClassNotFoundException {
+        final File sourcesOutputDir = CompilationTestUtils.generatorOutput("context-reference");
+        final File compiledOutputDir = CompilationTestUtils.compilerOutput("context-reference");
         generateTestSources("/compilation/context-reference", sourcesOutputDir);
 
         // Test if all sources are generated
         final File fooParent = new File(sourcesOutputDir, CompilationTestUtils.NS_FOO);
-        CompilationTestUtils.assertFilesCount(fooParent, 3);
+        CompilationTestUtils.assertFilesCount(fooParent, 4);
         assertTrue(new File(fooParent, "FooData.java").exists());
         assertTrue(new File(fooParent, "Nodes.java").exists());
         assertTrue(new File(fooParent, "NodesBuilder.java").exists());
 
         final File barParent = new File(sourcesOutputDir, CompilationTestUtils.NS_BAR);
-        CompilationTestUtils.assertFilesCount(barParent, 1);
+        CompilationTestUtils.assertFilesCount(barParent, 2);
         assertTrue(new File(barParent, "IdentityClass.java").exists());
 
         // Test if sources are compilable
         CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
 
         final ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() });
-        final Class<?> nodesClass = Class.forName(CompilationTestUtils.BASE_PKG + ".urn.opendaylight.foo.rev131008.Nodes", true, loader);
+        final Class<?> nodesClass = Class.forName(CompilationTestUtils.BASE_PKG
+            + ".urn.opendaylight.foo.rev131008.Nodes", true, loader);
         final Class<?> identityClass = Class
                 .forName(CompilationTestUtils.BASE_PKG + ".urn.opendaylight.bar.rev131008.IdentityClass", true, loader);
 
         // test identity
-        try {
-            identityClass.getConstructor();
-            final Class<?> baseIdentity = Class.forName("org.opendaylight.yangtools.yang.binding.BaseIdentity", true, loader);
-            assertEquals(baseIdentity, identityClass.getSuperclass());
-        } catch (final NoSuchMethodException e) {
-            throw new AssertionError("IdentityClass must have no-arg constructor");
-        }
+        final Class<?> baseIdentity = Class.forName("org.opendaylight.yangtools.yang.binding.BaseIdentity", true,
+            loader);
+        assertEquals(ImmutableList.of(baseIdentity), Arrays.asList(identityClass.getInterfaces()));
 
         // Test annotation
+        final Method getId;
         try {
-            final Method getId = nodesClass.getMethod("getId");
-            final Annotation[] annotations = getId.getAnnotations();
-            assertEquals(1, annotations.length);
-            final Annotation routingContext = annotations[0];
-            assertEquals(RoutingContext.class, routingContext.annotationType());
+            getId = nodesClass.getMethod("getId");
         } catch (final NoSuchMethodException e) {
-            throw new AssertionError("Method getId() not found");
+            throw new AssertionError("Method getId() not found", e);
         }
 
+        assertEquals(ImmutableSet.of(RoutingContext.class), Arrays.stream(getId.getAnnotations())
+            .map(Annotation::annotationType).collect(Collectors.toSet()));
         CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
     }
 
     @Test
     public void compilationTest() throws Exception {
-        final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "yang");
-        assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir());
-        final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "yang");
-        assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
-
+        final File sourcesOutputDir = CompilationTestUtils.generatorOutput("yang");
+        final File compiledOutputDir = CompilationTestUtils.compilerOutput("yang");
         generateTestSources("/yang", sourcesOutputDir);
 
         // Test if sources are compilable
@@ -503,11 +491,8 @@ public class CompilationTest extends BaseCompilationTest {
 
     @Test
     public void testBug586() throws Exception {
-        final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "bug586");
-        assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir());
-        final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "bug586");
-        assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
-
+        final File sourcesOutputDir = CompilationTestUtils.generatorOutput("bug586");
+        final File compiledOutputDir = CompilationTestUtils.compilerOutput("bug586");
         generateTestSources("/compilation/bug586", sourcesOutputDir);
 
         // Test if sources are compilable
@@ -518,11 +503,8 @@ public class CompilationTest extends BaseCompilationTest {
 
     @Test
     public void testBug4760() throws Exception {
-        final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "bug4760");
-        assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir());
-        final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "bug4760");
-        assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
-
+        final File sourcesOutputDir = CompilationTestUtils.generatorOutput("bug4760");
+        final File compiledOutputDir = CompilationTestUtils.compilerOutput("bug4760");
         generateTestSources("/compilation/bug4760", sourcesOutputDir);
 
         // Test if sources are compilable
@@ -533,16 +515,11 @@ public class CompilationTest extends BaseCompilationTest {
 
     /**
      * Test handling nested uses-augmentations.
-     *
-     * @throws Exception
      */
     @Test
     public void testBug1172() throws Exception {
-        final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "bug1172");
-        assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir());
-        final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "bug1172");
-        assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
-
+        final File sourcesOutputDir = CompilationTestUtils.generatorOutput("bug1172");
+        final File compiledOutputDir = CompilationTestUtils.compilerOutput("bug1172");
         generateTestSources("/compilation/bug1172", sourcesOutputDir);
 
         // Test if sources are compilable
@@ -553,11 +530,8 @@ public class CompilationTest extends BaseCompilationTest {
 
     @Test
     public void testBug5461() throws Exception {
-        final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "bug5461");
-        assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir());
-        final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "bug5461");
-        assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
-
+        final File sourcesOutputDir = CompilationTestUtils.generatorOutput("bug5461");
+        final File compiledOutputDir = CompilationTestUtils.compilerOutput("bug5461");
         generateTestSources("/compilation/bug5461", sourcesOutputDir);
 
         // Test if sources are compilable
@@ -568,10 +542,8 @@ public class CompilationTest extends BaseCompilationTest {
 
     @Test
     public void testBug5882() throws Exception {
-        final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "bug5882");
-        assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir());
-        final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "bug5882");
-        assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
+        final File sourcesOutputDir = CompilationTestUtils.generatorOutput("bug5882");
+        final File compiledOutputDir = CompilationTestUtils.compilerOutput("bug5882");
         generateTestSources("/compilation/bug5882", sourcesOutputDir);
 
         // Test if sources are compilable
@@ -582,56 +554,53 @@ public class CompilationTest extends BaseCompilationTest {
         assertTrue(new File(parent, "TypedefCurrent.java").exists());
         assertTrue(new File(parent, "TypedefDeprecated.java").exists());
 
-        final String pkg = CompilationTestUtils.BASE_PKG + ".urn.yang.foo.rev160102";
-        final ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() });
-        final Class<?> cls = loader.loadClass(pkg + ".FooData");
-        final Class<?> clsContainer = loader.loadClass(pkg + ".ContainerMain");
-        final Class<?> clsTypedefDepr = loader.loadClass(pkg + ".TypedefDeprecated");
-        final Class<?> clsTypedefCur = loader.loadClass(pkg + ".TypedefCurrent");
-        final Class<?> clsGroupingDepr = loader.loadClass(pkg + ".GroupingDeprecated");
-        final Class<?> clsGroupingCur = loader.loadClass(pkg + ".GroupingCurrent");
-        final Class<?> clsTypeDef1 = loader.loadClass(pkg + ".Typedef1");
-        final Class<?> clsTypeDef2 = loader.loadClass(pkg + ".Typedef2");
-        final Class<?> clsTypeDef3 = loader.loadClass(pkg + ".Typedef3");
-        assertTrue(clsTypedefDepr.getAnnotations()[0].toString().contains("Deprecated"));
-        assertTrue(clsTypedefCur.getAnnotations().length == 0);
-        assertTrue(clsGroupingDepr.getAnnotations()[0].toString().contains("Deprecated"));
-        assertTrue(clsGroupingCur.getAnnotations().length == 0);
-        assertTrue(clsTypeDef1.getAnnotations().length == 0);
-        assertTrue(clsTypeDef3.getAnnotations().length == 0);
-        assertTrue(clsTypeDef2.getAnnotations()[0].toString().contains("Deprecated"));
-
-        /*methods inside container*/
-        assertTrue(clsContainer.getMethod("getContainerMainLeafDepr").isAnnotationPresent(Deprecated.class));
-        assertTrue(clsContainer.getMethod("getContainerMainListDepr").isAnnotationPresent(Deprecated.class));
-        assertTrue(clsContainer.getMethod("getContainerMainChoiceDepr").isAnnotationPresent(Deprecated.class));
-        assertFalse(clsContainer.getMethod("getContainerMainLeafCurrent").isAnnotationPresent(Deprecated.class));
-        assertFalse(clsContainer.getMethod("getContainerMainListCurrent").isAnnotationPresent(Deprecated.class));
-        assertFalse(clsContainer.getMethod("getContainerMainChoiceCur").isAnnotationPresent(Deprecated.class));
-
-        /*methods inside module*/
-        assertTrue(cls.getMethod("getContainerMainLeafDepr").isAnnotationPresent(Deprecated.class));
-        assertTrue(cls.getMethod("getContainerMainListDepr").isAnnotationPresent(Deprecated.class));
-        assertTrue(cls.getMethod("getContainerMainChoiceDepr").isAnnotationPresent(Deprecated.class));
-        assertFalse(cls.getMethod("getContainerMainLeafCurrent").isAnnotationPresent(Deprecated.class));
-        assertFalse(cls.getMethod("getContainerMainListCurrent").isAnnotationPresent(Deprecated.class));
-        assertFalse(cls.getMethod("getContainerMainChoiceCur").isAnnotationPresent(Deprecated.class));
-        assertTrue(cls.getMethod("getLeafDeprecated").isAnnotationPresent(Deprecated.class));
+        try (URLClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() })) {
+            final String pkg = CompilationTestUtils.BASE_PKG + ".urn.yang.foo.rev160102";
+            final Class<?> cls = loader.loadClass(pkg + ".FooData");
+            final Class<?> clsContainer = loader.loadClass(pkg + ".ContainerMain");
+            final Class<?> clsTypedefDepr = loader.loadClass(pkg + ".TypedefDeprecated");
+            final Class<?> clsTypedefCur = loader.loadClass(pkg + ".TypedefCurrent");
+            final Class<?> clsGroupingDepr = loader.loadClass(pkg + ".GroupingDeprecated");
+            final Class<?> clsGroupingCur = loader.loadClass(pkg + ".GroupingCurrent");
+            final Class<?> clsTypeDef1 = loader.loadClass(pkg + ".Typedef1");
+            final Class<?> clsTypeDef2 = loader.loadClass(pkg + ".Typedef2");
+            final Class<?> clsTypeDef3 = loader.loadClass(pkg + ".Typedef3");
+            assertTrue(clsTypedefDepr.getAnnotations()[0].toString().contains("Deprecated"));
+            assertTrue(clsTypedefCur.getAnnotations().length == 0);
+            assertTrue(clsGroupingDepr.getAnnotations()[0].toString().contains("Deprecated"));
+            assertTrue(clsGroupingCur.getAnnotations().length == 0);
+            assertTrue(clsTypeDef1.getAnnotations().length == 0);
+            assertTrue(clsTypeDef3.getAnnotations().length == 0);
+            assertTrue(clsTypeDef2.getAnnotations()[0].toString().contains("Deprecated"));
+
+            /*methods inside container*/
+            assertTrue(clsContainer.getMethod("getContainerMainLeafDepr").isAnnotationPresent(Deprecated.class));
+            assertTrue(clsContainer.getMethod("getContainerMainListDepr").isAnnotationPresent(Deprecated.class));
+            assertTrue(clsContainer.getMethod("getContainerMainChoiceDepr").isAnnotationPresent(Deprecated.class));
+            assertFalse(clsContainer.getMethod("getContainerMainLeafCurrent").isAnnotationPresent(Deprecated.class));
+            assertFalse(clsContainer.getMethod("getContainerMainListCurrent").isAnnotationPresent(Deprecated.class));
+            assertFalse(clsContainer.getMethod("getContainerMainChoiceCur").isAnnotationPresent(Deprecated.class));
+
+            /*methods inside module*/
+            assertTrue(cls.getMethod("getContainerMainLeafDepr").isAnnotationPresent(Deprecated.class));
+            assertTrue(cls.getMethod("getContainerMainListDepr").isAnnotationPresent(Deprecated.class));
+            assertTrue(cls.getMethod("getContainerMainChoiceDepr").isAnnotationPresent(Deprecated.class));
+            assertFalse(cls.getMethod("getContainerMainLeafCurrent").isAnnotationPresent(Deprecated.class));
+            assertFalse(cls.getMethod("getContainerMainListCurrent").isAnnotationPresent(Deprecated.class));
+            assertFalse(cls.getMethod("getContainerMainChoiceCur").isAnnotationPresent(Deprecated.class));
+            assertTrue(cls.getMethod("getLeafDeprecated").isAnnotationPresent(Deprecated.class));
+        }
 
         CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
     }
 
     /**
      * Test if class generated for node from grouping implements ChildOf.
-     *
-     * @throws Exception
      */
     @Test
     public void testBug1377() throws Exception {
-        final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "bug1377");
-        assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir());
-        final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "bug1377");
-        assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
+        final File sourcesOutputDir = CompilationTestUtils.generatorOutput("bug1377");
+        final File compiledOutputDir = CompilationTestUtils.compilerOutput("bug1377");
 
         generateTestSources("/compilation/bug1377", sourcesOutputDir);
 
@@ -641,77 +610,127 @@ public class CompilationTest extends BaseCompilationTest {
         final ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() });
         final Class<?> outputActionClass = Class.forName(CompilationTestUtils.BASE_PKG
                 + ".urn.test.foo.rev140717.action.action.output.action._case.OutputAction", true, loader);
-        final Class<?> actionClass = Class.forName(CompilationTestUtils.BASE_PKG + ".urn.test.foo.rev140717.Action", true, loader);
+        final Class<?> actionClass = Class.forName(CompilationTestUtils.BASE_PKG + ".urn.test.foo.rev140717.Action",
+            true, loader);
 
         // Test generated 'container output-action'
         assertTrue(outputActionClass.isInterface());
-        CompilationTestUtils.assertImplementsParameterizedIfc(outputActionClass, ChildOf.class.toString(), actionClass.getCanonicalName());
+        CompilationTestUtils.assertImplementsParameterizedIfc(outputActionClass, ChildOf.class.toString(),
+            actionClass.getCanonicalName());
 
         CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
     }
 
     @Test
-    public void classNamesColisionTest() throws Exception {
-        final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "class-name-collision");
-        assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir());
-        final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "class-name-collision");
-        assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
+    public void testMdsal327() throws Exception {
+        final File sourcesOutputDir = CompilationTestUtils.generatorOutput("mdsal327");
+        final File compiledOutputDir = CompilationTestUtils.compilerOutput("mdsal327");
+        generateTestSources("/compilation/mdsal327", sourcesOutputDir);
+        CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
+        CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
+    }
+
+    @Test
+    public void testMdsal365() throws Exception {
+        final File sourcesOutputDir = CompilationTestUtils.generatorOutput("mdsal365");
+        final File compiledOutputDir = CompilationTestUtils.compilerOutput("mdsal365");
+        generateTestSources("/compilation/mdsal365", sourcesOutputDir);
+        CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
+        CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
+    }
 
+    @Test
+    public void testMdsal395() throws Exception {
+        final File sourcesOutputDir = CompilationTestUtils.generatorOutput("mdsal395");
+        final File compiledOutputDir = CompilationTestUtils.compilerOutput("mdsal395");
+        generateTestSources("/compilation/mdsal395", sourcesOutputDir);
+        CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
+        CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
+    }
+
+    @Test
+    public void classNamesColisionTest() throws Exception {
+        final File sourcesOutputDir = CompilationTestUtils.generatorOutput("class-name-collision");
+        final File compiledOutputDir = CompilationTestUtils.compilerOutput("class-name-collision");
         generateTestSources("/compilation/class-name-collision", sourcesOutputDir);
         CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
         CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
     }
 
-    private void generateTestSources(final String resourceDirPath, final File sourcesOutputDir) throws Exception {
-        final List<File> sourceFiles = CompilationTestUtils.getSourceFiles(resourceDirPath);
-        final SchemaContext context = YangParserTestUtils.parseYangFiles(sourceFiles);
-        final List<Type> types = bindingGenerator.generateTypes(context);
-        Collections.sort(types, (o1, o2) -> o2.getName().compareTo(o1.getName()));
-        final GeneratorJavaFile generator = new GeneratorJavaFile(ImmutableSet.copyOf(types));
-        generator.generateToFile(sourcesOutputDir);
+    @Test
+    public void innerEnumerationNameCollisionTest() throws Exception {
+        final File sourcesOutputDir = CompilationTestUtils.generatorOutput("mdsal321");
+        final File compiledOutputDir = CompilationTestUtils.compilerOutput("mdsal321");
+        generateTestSources("/compilation/mdsal321", sourcesOutputDir);
+        CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
+        CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
     }
 
-    private static void testReturnTypeIdentityref(final Class<?> clazz, final String methodName, final String returnTypeStr) throws Exception {
-        Method method;
-        java.lang.reflect.Type returnType;
-        try {
-            method = clazz.getMethod(methodName);
-            assertEquals(java.lang.Class.class, method.getReturnType());
-            returnType = method.getGenericReturnType();
-            assertTrue(returnType instanceof ParameterizedType);
-            final ParameterizedType pt = (ParameterizedType) returnType;
-            final java.lang.reflect.Type[] parameters = pt.getActualTypeArguments();
-            assertEquals(1, parameters.length);
-            final java.lang.reflect.Type parameter = parameters[0];
-            assertTrue(parameter instanceof WildcardType);
-            final WildcardType wildcardType = (WildcardType) parameter;
-            assertEquals("? extends " + returnTypeStr, wildcardType.toString());
-        } catch (final NoSuchMethodException e) {
-            throw new AssertionError("Method '" + methodName + "' not found");
-        }
+    @Test
+    public void twoNestedUnionsTest() throws Exception {
+        final File sourcesOutputDir = CompilationTestUtils.generatorOutput("mdsal320");
+        final File compiledOutputDir = CompilationTestUtils.compilerOutput("mdsal320");
+        generateTestSources("/compilation/mdsal320", sourcesOutputDir);
+        CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
+        CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
     }
 
-    private static void testReturnTypeInstanceIdentitifer(final ClassLoader loader, final Class<?> clazz, final String methodName)
-            throws Exception {
-        Method method;
-        Class<?> rawReturnType;
-        java.lang.reflect.Type returnType;
-        try {
-            method = clazz.getMethod(methodName);
-            rawReturnType = Class.forName("org.opendaylight.yangtools.yang.binding.InstanceIdentifier", true, loader);
-            assertEquals(rawReturnType, method.getReturnType());
-            returnType = method.getGenericReturnType();
-            assertTrue(returnType instanceof ParameterizedType);
-            final ParameterizedType pt = (ParameterizedType) returnType;
-            final java.lang.reflect.Type[] parameters = pt.getActualTypeArguments();
-            assertEquals(1, parameters.length);
-            final java.lang.reflect.Type parameter = parameters[0];
-            assertTrue(parameter instanceof WildcardType);
-            final WildcardType wildcardType = (WildcardType) parameter;
-            assertEquals("?", wildcardType.toString());
-        } catch (final NoSuchMethodException e) {
-            throw new AssertionError("Method '" + methodName + "' not found");
-        }
+    @Test
+    public void testMdsal425() throws Exception {
+        final File sourcesOutputDir = CompilationTestUtils.generatorOutput("mdsal425");
+        final File compiledOutputDir = CompilationTestUtils.compilerOutput("mdsal425");
+        generateTestSources("/compilation/mdsal425", sourcesOutputDir);
+        CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
+        CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
+    }
+
+    @Test
+    public void testMdsal529() throws Exception {
+        final File sourcesOutputDir = CompilationTestUtils.generatorOutput("mdsal529");
+        final File compiledOutputDir = CompilationTestUtils.compilerOutput("mdsal529");
+        generateTestSources("/compilation/mdsal529", sourcesOutputDir);
+        CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
+        CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
     }
 
+    @Test
+    public void testMdsal589() throws Exception {
+        final File sourcesOutputDir = CompilationTestUtils.generatorOutput("mdsal589");
+        final File compiledOutputDir = CompilationTestUtils.compilerOutput("mdsal589");
+        generateTestSources("/compilation/mdsal589", sourcesOutputDir);
+        CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
+        CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
+    }
+
+    private static void testReturnTypeIdentityref(final Class<?> clazz, final String methodName,
+            final String returnTypeStr) throws NoSuchMethodException {
+        Method method = clazz.getMethod(methodName);
+        assertEquals(java.lang.Class.class, method.getReturnType());
+        java.lang.reflect.Type returnType = method.getGenericReturnType();
+        assertTrue(returnType instanceof ParameterizedType);
+        final ParameterizedType pt = (ParameterizedType) returnType;
+        final java.lang.reflect.Type[] parameters = pt.getActualTypeArguments();
+        assertEquals(1, parameters.length);
+        final java.lang.reflect.Type parameter = parameters[0];
+        assertTrue(parameter instanceof WildcardType);
+        final WildcardType wildcardType = (WildcardType) parameter;
+        assertEquals("? extends " + returnTypeStr, wildcardType.toString());
+    }
+
+    private static void testReturnTypeInstanceIdentitifer(final ClassLoader loader, final Class<?> clazz,
+            final String methodName) throws ClassNotFoundException, NoSuchMethodException, SecurityException {
+        final Method method = clazz.getMethod(methodName);
+        final Class<?> rawReturnType = Class.forName("org.opendaylight.yangtools.yang.binding.InstanceIdentifier", true,
+            loader);
+        assertEquals(rawReturnType, method.getReturnType());
+        final java.lang.reflect.Type returnType = method.getGenericReturnType();
+        assertTrue(returnType instanceof ParameterizedType);
+        final ParameterizedType pt = (ParameterizedType) returnType;
+        final java.lang.reflect.Type[] parameters = pt.getActualTypeArguments();
+        assertEquals(1, parameters.length);
+        final java.lang.reflect.Type parameter = parameters[0];
+        assertTrue(parameter instanceof WildcardType);
+        final WildcardType wildcardType = (WildcardType) parameter;
+        assertEquals("?", wildcardType.toString());
+    }
 }