Merge "Fix to maintain Java 6 compatability"
[controller.git] / opendaylight / sal / yang-prototype / code-generator / yang-model-parser-impl / src / test / java / org / opendaylight / controller / yang / parser / impl / TestUtils.java
index 5aa620df8936383392ea25d7acea995a7b65fe55..3d9df349e4ec5a390518b67fdaadb5640b51dd86 100644 (file)
@@ -8,11 +8,15 @@
 package org.opendaylight.controller.yang.parser.impl;
 
 import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
 import java.net.URI;
 import java.text.DateFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Date;
 import java.util.List;
 import java.util.Set;
@@ -29,11 +33,14 @@ final class TestUtils {
     private TestUtils() {
     }
 
-    public static Set<Module> loadModules(String resourceDirectory) {
+    public static Set<Module> loadModules(String resourceDirectory) throws FileNotFoundException {
         YangModelParser parser = new YangParserImpl();
         final File testDir = new File(resourceDirectory);
         final String[] fileList = testDir.list();
         final List<File> testFiles = new ArrayList<File>();
+        if(fileList == null) {
+            throw new FileNotFoundException(resourceDirectory);
+        }
         for (int i = 0; i < fileList.length; i++) {
             String fileName = fileList[i];
             testFiles.add(new File(testDir, fileName));
@@ -41,6 +48,28 @@ final class TestUtils {
         return parser.parseYangModels(testFiles);
     }
 
+    public static Set<Module> loadModules(String... pathToYangFile) throws IOException {
+        YangModelParser parser = new YangParserImpl();
+        List<InputStream> input = new ArrayList<InputStream>();
+        for(String path : pathToYangFile) {
+            input.add(TestUtils.class.getResourceAsStream(path));
+        }
+        Set<Module> modules = parser.parseYangModelsFromStreams(input);
+        for(InputStream stream : input) {
+            stream.close();
+        }
+        return modules;
+    }
+
+    public static Module loadModule(String pathToYangFile) throws IOException {
+        YangModelParser parser = new YangParserImpl();
+        InputStream stream = TestUtils.class.getResourceAsStream(pathToYangFile);
+        List<InputStream> input = Collections.singletonList(stream);
+        Set<Module> modules = parser.parseYangModelsFromStreams(input);
+        stream.close();
+        return modules.iterator().next();
+    }
+
     public static Module findModule(Set<Module> modules, String moduleName) {
         Module result = null;
         for (Module module : modules) {