Fix IPv6 + subnet flow installation
[controller.git] / opendaylight / sal / yang-prototype / code-generator / yang-model-parser-impl / src / test / java / org / opendaylight / controller / yang / parser / impl / TestUtils.java
index d14c54219e0fd5e1c1d9f3cdae3b0512f8dd654c..fed8cde9655c8dc2232cd068501b523ae69777fa 100644 (file)
@@ -25,6 +25,7 @@ import java.util.Set;
 import org.opendaylight.controller.yang.common.QName;
 import org.opendaylight.controller.yang.model.api.Module;
 import org.opendaylight.controller.yang.model.api.ModuleImport;
+import org.opendaylight.controller.yang.model.api.SchemaContext;
 import org.opendaylight.controller.yang.model.api.SchemaPath;
 import org.opendaylight.controller.yang.model.api.TypeDefinition;
 import org.opendaylight.controller.yang.model.parser.api.YangModelParser;
@@ -49,13 +50,9 @@ 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 = new HashSet<Module>(
+    public static Set<Module> loadModules(List<InputStream> input) throws IOException {
+        final YangModelParser parser = new YangParserImpl();
+        final Set<Module> modules = new HashSet<Module>(
                 parser.parseYangModelsFromStreams(input));
         for(InputStream stream : input) {
             stream.close();
@@ -63,16 +60,35 @@ final class TestUtils {
         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 = new HashSet<Module>(
+    public static Module loadModule(final InputStream stream) throws
+            IOException {
+        final YangModelParser parser = new YangParserImpl();
+        final List<InputStream> input = Collections.singletonList(stream);
+        final Set<Module> modules = new HashSet<Module>(
                 parser.parseYangModelsFromStreams(input));
         stream.close();
         return modules.iterator().next();
     }
 
+    public static Module loadModuleWithContext(final InputStream stream, final SchemaContext context) throws IOException {
+        final YangModelParser parser = new YangParserImpl();
+        final List<InputStream> input = Collections.singletonList(stream);
+        final Set<Module> modules = new HashSet<Module>(parser.parseYangModelsFromStreams(input, context));
+        stream.close();
+        return modules.iterator().next();
+    }
+
+    public static Set<Module> loadModulesWithContext(final List<InputStream> input, final SchemaContext context) throws IOException {
+        final YangModelParser parser = new YangParserImpl();
+        final Set<Module> modules = new HashSet<Module>(parser.parseYangModelsFromStreams(input, context));
+        for(InputStream is : input) {
+            if(is != null) {
+                is.close();
+            }
+        }
+        return modules;
+    }
+
     public static Module findModule(Set<Module> modules, String moduleName) {
         Module result = null;
         for (Module module : modules) {