Workaround test model loading issues
[yangtools.git] / yang / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / StmtTestUtils.java
index b2042cfd2a3fb81af49980d2a0e540ca4d52f49d..2b619e0f32d3fbe87a1000b20f51c51704f6aee5 100644 (file)
@@ -5,7 +5,6 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.yangtools.yang.stmt;
 
 import com.google.common.io.Files;
@@ -23,9 +22,12 @@ import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.YangConstants;
 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
+import org.opendaylight.yangtools.yang.model.api.ModuleLike;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.Submodule;
 import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
 import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
@@ -65,7 +67,7 @@ public final class StmtTestUtils {
         }
     }
 
-    public static List<Module> findModules(final Set<Module> modules, final String moduleName) {
+    public static List<Module> findModules(final Collection<? extends Module> modules, final String moduleName) {
         final List<Module> result = new ArrayList<>();
         for (final Module module : modules) {
             if (module.getName().equals(moduleName)) {
@@ -77,22 +79,22 @@ public final class StmtTestUtils {
 
     public static StatementStreamSource sourceForResource(final String resourceName) {
         try {
-            return YangStatementStreamSource.create(YangTextSchemaSource.forResource(resourceName));
-        } catch (IOException | YangSyntaxErrorException e) {
+            return YangStatementStreamSource.create(YangTextSchemaSource.forFile(new File(
+                StmtTestUtils.class.getResource(resourceName).toURI())));
+        } catch (IOException | YangSyntaxErrorException | URISyntaxException e) {
             throw new IllegalArgumentException("Failed to create source", e);
         }
     }
 
-    public static void printReferences(final Module module, final boolean isSubmodule, final String indent) {
-        LOG.debug("{}{} {}", indent, (isSubmodule ? "Submodule" : "Module"), module.getName());
-        final Set<Module> submodules = module.getSubmodules();
-        for (final Module submodule : submodules) {
+    public static void printReferences(final ModuleLike module, final boolean isSubmodule, final String indent) {
+        LOG.debug("{}{} {}", indent, isSubmodule ? "Submodule" : "Module", module.getName());
+        for (final Submodule submodule : module.getSubmodules()) {
             printReferences(submodule, true, indent + "      ");
             printChilds(submodule.getChildNodes(), indent + "            ");
         }
     }
 
-    public static void printChilds(final Collection<DataSchemaNode> childNodes, final String indent) {
+    public static void printChilds(final Collection<? extends DataSchemaNode> childNodes, final String indent) {
 
         for (final DataSchemaNode child : childNodes) {
             LOG.debug("{}{} {}", indent, "Child", child.getQName().getLocalName());
@@ -102,17 +104,17 @@ public final class StmtTestUtils {
         }
     }
 
-    public static SchemaContext parseYangSource(final String yangSourcePath) throws ReactorException,
+    public static EffectiveModelContext parseYangSource(final String yangSourcePath) throws ReactorException,
             URISyntaxException, IOException, YangSyntaxErrorException {
         return parseYangSource(yangSourcePath, StatementParserMode.DEFAULT_MODE, null);
     }
 
-    public static SchemaContext parseYangSource(final String yangSourcePath, final Set<QName> supportedFeatures)
+    public static EffectiveModelContext parseYangSource(final String yangSourcePath, final Set<QName> supportedFeatures)
             throws ReactorException, URISyntaxException, IOException, YangSyntaxErrorException {
         return parseYangSource(yangSourcePath, StatementParserMode.DEFAULT_MODE, supportedFeatures);
     }
 
-    public static SchemaContext parseYangSource(final String yangSourcePath,
+    public static EffectiveModelContext parseYangSource(final String yangSourcePath,
             final StatementParserMode statementParserMode, final Set<QName> supportedFeatures)
                     throws ReactorException, URISyntaxException, IOException, YangSyntaxErrorException {
         final URL source = StmtTestUtils.class.getResource(yangSourcePath);
@@ -120,16 +122,17 @@ public final class StmtTestUtils {
         return parseYangSources(statementParserMode, supportedFeatures, sourceFile);
     }
 
-    public static SchemaContext parseYangSources(final StatementStreamSource... sources) throws ReactorException {
+    public static EffectiveModelContext parseYangSources(final StatementStreamSource... sources)
+            throws ReactorException {
         return parseYangSources(StatementParserMode.DEFAULT_MODE, null, sources);
     }
 
-    public static SchemaContext parseYangSources(final StatementParserMode statementParserMode,
+    public static EffectiveModelContext parseYangSources(final StatementParserMode statementParserMode,
             final Set<QName> supportedFeatures, final StatementStreamSource... sources) throws ReactorException {
         return parseYangSources(statementParserMode, supportedFeatures, Arrays.asList(sources));
     }
 
-    public static SchemaContext parseYangSources(final StatementParserMode statementParserMode,
+    public static EffectiveModelContext parseYangSources(final StatementParserMode statementParserMode,
             final Set<QName> supportedFeatures, final Collection<? extends StatementStreamSource> sources)
             throws ReactorException {
         final BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild(statementParserMode)
@@ -141,12 +144,12 @@ public final class StmtTestUtils {
         return reactor.buildEffective();
     }
 
-    public static SchemaContext parseYangSources(final File... files) throws ReactorException, IOException,
+    public static EffectiveModelContext parseYangSources(final File... files) throws ReactorException, IOException,
             YangSyntaxErrorException {
         return parseYangSources(StatementParserMode.DEFAULT_MODE, null, files);
     }
 
-    public static SchemaContext parseYangSources(final StatementParserMode statementParserMode,
+    public static EffectiveModelContext parseYangSources(final StatementParserMode statementParserMode,
             final Set<QName> supportedFeatures, final File... files) throws  ReactorException, IOException,
             YangSyntaxErrorException {
 
@@ -158,29 +161,29 @@ public final class StmtTestUtils {
         return parseYangSources(statementParserMode, supportedFeatures, sources);
     }
 
-    public static SchemaContext parseYangSources(final Collection<File> files) throws ReactorException, IOException,
-            YangSyntaxErrorException {
+    public static EffectiveModelContext parseYangSources(final Collection<File> files) throws ReactorException,
+            IOException, YangSyntaxErrorException {
         return parseYangSources(files, StatementParserMode.DEFAULT_MODE);
     }
 
-    public static SchemaContext parseYangSources(final Collection<File> files,
+    public static EffectiveModelContext parseYangSources(final Collection<File> files,
             final StatementParserMode statementParserMode) throws ReactorException, IOException,
             YangSyntaxErrorException {
         return parseYangSources(statementParserMode, null, files.toArray(new File[files.size()]));
     }
 
-    public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath) throws
-            ReactorException, URISyntaxException, IOException, YangSyntaxErrorException {
+    public static EffectiveModelContext parseYangSources(final String yangSourcesDirectoryPath)
+            throws ReactorException, URISyntaxException, IOException, YangSyntaxErrorException {
         return parseYangSources(yangSourcesDirectoryPath, StatementParserMode.DEFAULT_MODE);
     }
 
-    public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath,
+    public static EffectiveModelContext parseYangSources(final String yangSourcesDirectoryPath,
             final StatementParserMode statementParserMode) throws ReactorException, URISyntaxException, IOException,
             YangSyntaxErrorException {
         return parseYangSources(yangSourcesDirectoryPath, null, statementParserMode);
     }
 
-    public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath,
+    public static EffectiveModelContext parseYangSources(final String yangSourcesDirectoryPath,
             final Set<QName> supportedFeatures, final StatementParserMode statementParserMode) throws ReactorException,
             URISyntaxException, IOException, YangSyntaxErrorException {
 
@@ -190,13 +193,13 @@ public final class StmtTestUtils {
         return parseYangSources(statementParserMode, supportedFeatures, testSourcesDir.listFiles(YANG_FILE_FILTER));
     }
 
-    public static SchemaContext parseYangSources(final String yangFilesDirectoryPath,
+    public static EffectiveModelContext parseYangSources(final String yangFilesDirectoryPath,
             final String yangLibsDirectoryPath)
             throws URISyntaxException, ReactorException, IOException, YangSyntaxErrorException {
         return parseYangSources(yangFilesDirectoryPath, yangLibsDirectoryPath, null);
     }
 
-    public static SchemaContext parseYangSources(final String yangFilesDirectoryPath,
+    public static EffectiveModelContext parseYangSources(final String yangFilesDirectoryPath,
             final String yangLibsDirectoryPath, final Set<QName> supportedFeatures) throws URISyntaxException,
             ReactorException, IOException, YangSyntaxErrorException {
         final File yangsDir = new File(StmtTestUtils.class.getResource(yangFilesDirectoryPath).toURI());
@@ -206,7 +209,7 @@ public final class StmtTestUtils {
                 supportedFeatures);
     }
 
-    private static SchemaContext parseYangSources(final File[] yangFiles, final File[] libFiles,
+    private static EffectiveModelContext parseYangSources(final File[] yangFiles, final File[] libFiles,
             final Set<QName> supportedFeatures) throws ReactorException, IOException, YangSyntaxErrorException {
         final StatementStreamSource[] yangSources = new StatementStreamSource[yangFiles.length];
         for (int i = 0; i < yangFiles.length; i++) {
@@ -221,7 +224,7 @@ public final class StmtTestUtils {
         return parseYangSources(yangSources, libSources, supportedFeatures);
     }
 
-    private static SchemaContext parseYangSources(final StatementStreamSource[] yangSources,
+    private static EffectiveModelContext parseYangSources(final StatementStreamSource[] yangSources,
             final StatementStreamSource[] libSources, final Set<QName> supportedFeatures) throws ReactorException {
 
         final BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild()
@@ -233,7 +236,12 @@ public final class StmtTestUtils {
         return reactor.buildEffective();
     }
 
-    public static SchemaContext parseYinSources(final String yinSourcesDirectoryPath,
+    public static EffectiveModelContext parseYinSources(final String yinSourcesDirectoryPath)
+            throws URISyntaxException, SAXException, IOException, ReactorException {
+        return parseYinSources(yinSourcesDirectoryPath, StatementParserMode.DEFAULT_MODE);
+    }
+
+    public static EffectiveModelContext parseYinSources(final String yinSourcesDirectoryPath,
             final StatementParserMode statementParserMode) throws URISyntaxException, SAXException, IOException,
             ReactorException {
         final URL resourceDir = StmtTestUtils.class.getResource(yinSourcesDirectoryPath);
@@ -249,7 +257,7 @@ public final class StmtTestUtils {
         return parseYinSources(statementParserMode, sources);
     }
 
-    public static SchemaContext parseYinSources(final StatementParserMode statementParserMode,
+    public static EffectiveModelContext parseYinSources(final StatementParserMode statementParserMode,
             final StatementStreamSource... sources) throws ReactorException {
         return RFC7950Reactors.defaultReactor().newBuild(statementParserMode).addSources(sources).buildEffective();
     }
@@ -257,8 +265,7 @@ public final class StmtTestUtils {
     public static Module findImportedModule(final SchemaContext context, final Module rootModule,
             final String importedModuleName) {
         ModuleImport requestedModuleImport = null;
-        final Set<ModuleImport> rootImports = rootModule.getImports();
-        for (final ModuleImport moduleImport : rootImports) {
+        for (final ModuleImport moduleImport : rootModule.getImports()) {
             if (moduleImport.getModuleName().equals(importedModuleName)) {
                 requestedModuleImport = moduleImport;
                 break;