Propagate EffectiveModelContext for codegen plugins
[mdsal.git] / binding / mdsal-binding-java-api-generator / src / test / java / org / opendaylight / mdsal / binding / java / api / generator / test / UnionTypedefUnusedImportTest.java
index cfa2e7a1a8646183ed37382b6766726599114edc..3ab8f602d4cd70f023ccbc0e535e835bfc939a00 100644 (file)
@@ -8,12 +8,9 @@
 package org.opendaylight.mdsal.binding.java.api.generator.test;
 
 import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.opendaylight.mdsal.binding.java.api.generator.test.CompilationTestUtils.COMPILER_OUTPUT_PATH;
 import static org.opendaylight.mdsal.binding.java.api.generator.test.CompilationTestUtils.FS;
 import static org.opendaylight.mdsal.binding.java.api.generator.test.CompilationTestUtils.GENERATOR_OUTPUT_PATH;
 import static org.opendaylight.mdsal.binding.java.api.generator.test.CompilationTestUtils.cleanUp;
-import static org.opendaylight.mdsal.binding.java.api.generator.test.CompilationTestUtils.getSourceFiles;
 import static org.opendaylight.mdsal.binding.java.api.generator.test.CompilationTestUtils.testCompilation;
 
 import java.io.File;
@@ -23,32 +20,23 @@ import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Paths;
-import java.util.HashSet;
 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;
 
 public class UnionTypedefUnusedImportTest extends BaseCompilationTest {
 
     @Test
     public void testUnionTypedefUnusedImport() throws Exception {
-        final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "union-typedef");
-        assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir());
-        final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "union-typedef");
-        assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
+        final File sourcesOutputDir = CompilationTestUtils.generatorOutput("union-typedef");
+        final List<Type> types = generateTestSources("/compilation/union-typedef", sourcesOutputDir);
 
-        final List<File> sourceFiles = getSourceFiles("/compilation/union-typedef");
-        final SchemaContext context = YangParserTestUtils.parseYangFiles(sourceFiles);
-        final List<Type> types = bindingGenerator.generateTypes(context);
-        final GeneratorJavaFile generator = new GeneratorJavaFile(new HashSet<>(types));
-        generator.generateToFile(sourcesOutputDir);
-        final boolean isUsedImport = containsImport("org.opendaylight.yang.gen.v1.org.opendaylight.yangtools.union.typedef.rev130208.TypedefUnion");
+        final boolean isUsedImport = containsImport(
+            "org.opendaylight.yang.gen.v1.org.opendaylight.yangtools.union.typedef.rev130208.TypedefUnion");
         assertFalse(String.format("Class shouldn't contain import for this type '%s'", types.get(1).getName()),
                 isUsedImport);
 
+        final File compiledOutputDir = CompilationTestUtils.compilerOutput("union-typedef");
         testCompilation(sourcesOutputDir, compiledOutputDir);
         cleanUp(sourcesOutputDir, compiledOutputDir);
     }
@@ -59,7 +47,9 @@ public class UnionTypedefUnusedImportTest extends BaseCompilationTest {
     }
 
     private static boolean containsImport(final String fullImport) throws URISyntaxException, IOException {
-        final String filePath = GENERATOR_OUTPUT_PATH + FS + "union-typedef" + FS + "org" + FS + "opendaylight" + FS + "yang" + FS + "gen" + FS + "v1" + FS + "org" + FS + "opendaylight" + FS + "yangtools" + FS + "union" + FS + "typedef" + FS + "rev141124" + FS + "TypedefUnionBuilder.java";
+        final String filePath = GENERATOR_OUTPUT_PATH + FS + "union-typedef" + FS + "org" + FS + "opendaylight" + FS
+                + "yang" + FS + "gen" + FS + "v1" + FS + "org" + FS + "opendaylight" + FS + "yangtools" + FS + "union"
+                + FS + "typedef" + FS + "rev141124" + FS + "TypedefUnionBuilder.java";
         final String fileContent = readFile(filePath, StandardCharsets.UTF_8);
 
         if (fileContent.contains(fullImport)) {