$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 / UnionWithIdentityrefTest.java
index 60d1aeecf72d75704d65de7810eaf3a563107d0e..18ba8c58cdd5da3137801b4373072a8aa1908de3 100644 (file)
@@ -7,51 +7,42 @@
  */
 package org.opendaylight.mdsal.binding.java.api.generator.test;
 
-import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
 
-import com.google.common.collect.ImmutableSet;
 import java.io.File;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
 import java.net.URL;
 import java.net.URLClassLoader;
-import java.util.List;
 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.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 
 /**
- * union constructor with indentityref
- * previously identityref was ignored so that there is no constructor
- * for indentityref
- *
+ * Union constructor with indentityref. Previously identityref was ignored so that there is no constructor for
+ * identityref.
  */
 public class UnionWithIdentityrefTest extends BaseCompilationTest {
 
     @Test
     public void test() throws Exception {
-        final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "union-with-identityref");
-        assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir());
-        final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "union-with-identityref");
-        assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
-
+        final File sourcesOutputDir = CompilationTestUtils.generatorOutput("union-with-identityref");
+        final File compiledOutputDir = CompilationTestUtils.compilerOutput("union-with-identityref");
         generateTestSources("/compilation/union-with-identityref", sourcesOutputDir);
 
         // Test if sources are compilable
         CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
 
         ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() });
-        Class<?> identBaseClass = Class.forName(CompilationTestUtils.BASE_PKG + ".urn.opendaylight.yang.union.test.rev160509.IdentBase", true, loader);
-        Class<?> identOneClass = Class.forName(CompilationTestUtils.BASE_PKG + ".urn.opendaylight.yang.union.test.rev160509.IdentOne", true, loader);
-        Class<?> unionTypeClass = Class.forName(CompilationTestUtils.BASE_PKG + ".urn.opendaylight.yang.union.test.rev160509.UnionType", true, loader);
+        Class<?> identBaseClass = Class.forName(CompilationTestUtils.BASE_PKG
+            + ".urn.opendaylight.yang.union.test.rev160509.IdentBase", true, loader);
+        Class<?> identOneClass = Class.forName(CompilationTestUtils.BASE_PKG
+            + ".urn.opendaylight.yang.union.test.rev160509.IdentOne", true, loader);
+        Class<?> unionTypeClass = Class.forName(CompilationTestUtils.BASE_PKG
+            + ".urn.opendaylight.yang.union.test.rev160509.UnionType", true, loader);
 
         // test UnionType with IdentOne argument
-        Constructor<?> unionTypeIdentBaseConstructor = CompilationTestUtils.assertContainsConstructor(unionTypeClass, Class.class);
+        Constructor<?> unionTypeIdentBaseConstructor = CompilationTestUtils.assertContainsConstructor(unionTypeClass,
+            Class.class);
         Object unionType = unionTypeIdentBaseConstructor.newInstance(identOneClass);
 
         Method getUint8 = unionTypeClass.getDeclaredMethod("getUint8");
@@ -62,18 +53,6 @@ public class UnionWithIdentityrefTest extends BaseCompilationTest {
         Object actualIdentityref = getIdentityref.invoke(unionType);
         assertEquals(identOneClass, actualIdentityref);
 
-        Method getValue = unionTypeClass.getDeclaredMethod("getValue");
-        Object actualValue = getValue.invoke(unionType);
-        assertArrayEquals(identOneClass.toString().toCharArray(), (char[])actualValue);
-
         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.parseYangSources(sourceFiles);
-        final List<Type> types = bindingGenerator.generateTypes(context);
-        final GeneratorJavaFile generator = new GeneratorJavaFile(ImmutableSet.copyOf(types));
-        generator.generateToFile(sourcesOutputDir);
-    }
 }