Remove unused parseYangSources() methods
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / StmtTestUtils.java
index 916b8f9d5ff243737eaa3a6451e002ccd2a7363e..3a591ce650c905d2ad59182fd4cc1d2412068e92 100644 (file)
@@ -7,31 +7,23 @@
  */
 package org.opendaylight.yangtools.yang.stmt;
 
-import static org.junit.Assert.assertEquals;
-
 import com.google.common.io.Files;
 import java.io.File;
 import java.io.FileFilter;
 import java.io.IOException;
 import java.net.URISyntaxException;
 import java.net.URL;
+import java.nio.file.Path;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
-import java.util.List;
 import java.util.Set;
 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.SchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.api.Submodule;
 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
 import org.opendaylight.yangtools.yang.model.repo.api.YinTextSchemaSource;
@@ -72,48 +64,15 @@ public final class StmtTestUtils {
         }
     }
 
-    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)) {
-                result.add(module);
-            }
-        }
-        return result;
-    }
-
     public static YangStatementStreamSource sourceForResource(final String resourceName) {
         try {
-            return YangStatementStreamSource.create(YangTextSchemaSource.forFile(new File(
+            return YangStatementStreamSource.create(YangTextSchemaSource.forPath(Path.of(
                 StmtTestUtils.class.getResource(resourceName).toURI())));
         } catch (IOException | YangSyntaxErrorException | URISyntaxException e) {
             throw new IllegalArgumentException("Failed to create source", e);
         }
     }
 
-    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<? extends DataSchemaNode> childNodes, final String indent) {
-
-        for (final DataSchemaNode child : childNodes) {
-            LOG.debug("{}{} {}", indent, "Child", child.getQName().getLocalName());
-            if (child instanceof DataNodeContainer) {
-                printChilds(((DataNodeContainer) child).getChildNodes(), indent + "      ");
-            }
-        }
-    }
-
-    public static EffectiveModelContext parseYangSource(final String yangSourcePath) throws ReactorException,
-            URISyntaxException, IOException, YangSyntaxErrorException {
-        return parseYangSource(yangSourcePath, YangParserConfiguration.DEFAULT, null);
-    }
-
     public static EffectiveModelContext parseYangSource(final String yangSourcePath, final Set<QName> supportedFeatures)
             throws ReactorException, URISyntaxException, IOException, YangSyntaxErrorException {
         return parseYangSource(yangSourcePath, YangParserConfiguration.DEFAULT, supportedFeatures);
@@ -122,9 +81,8 @@ public final class StmtTestUtils {
     public static EffectiveModelContext parseYangSource(final String yangSourcePath,
             final YangParserConfiguration config, final Set<QName> supportedFeatures)
                     throws ReactorException, URISyntaxException, IOException, YangSyntaxErrorException {
-        final URL source = StmtTestUtils.class.getResource(yangSourcePath);
-        final File sourceFile = new File(source.toURI());
-        return parseYangSources(config, supportedFeatures, sourceFile);
+        return parseYangSources(config, supportedFeatures,
+            new File(StmtTestUtils.class.getResource(yangSourcePath).toURI()));
     }
 
     public static EffectiveModelContext parseYangSources(final StatementStreamSource... sources)
@@ -158,22 +116,12 @@ public final class StmtTestUtils {
 
         final Collection<YangStatementStreamSource> sources = new ArrayList<>(files.length);
         for (File file : files) {
-            sources.add(YangStatementStreamSource.create(YangTextSchemaSource.forFile(file)));
+            sources.add(YangStatementStreamSource.create(YangTextSchemaSource.forPath(file.toPath())));
         }
 
         return parseYangSources(config, supportedFeatures, sources);
     }
 
-    public static EffectiveModelContext parseYangSources(final Collection<File> files) throws ReactorException,
-            IOException, YangSyntaxErrorException {
-        return parseYangSources(files, YangParserConfiguration.DEFAULT);
-    }
-
-    public static EffectiveModelContext parseYangSources(final Collection<File> files,
-            final YangParserConfiguration config) throws ReactorException, IOException, YangSyntaxErrorException {
-        return parseYangSources(config, null, files.toArray(new File[files.size()]));
-    }
-
     public static EffectiveModelContext parseYangSources(final String yangSourcesDirectoryPath)
             throws ReactorException, URISyntaxException, IOException, YangSyntaxErrorException {
         return parseYangSources(yangSourcesDirectoryPath, YangParserConfiguration.DEFAULT);
@@ -195,49 +143,6 @@ public final class StmtTestUtils {
         return parseYangSources(config, supportedFeatures, testSourcesDir.listFiles(YANG_FILE_FILTER));
     }
 
-    public static EffectiveModelContext parseYangSources(final String yangFilesDirectoryPath,
-            final String yangLibsDirectoryPath)
-            throws URISyntaxException, ReactorException, IOException, YangSyntaxErrorException {
-        return parseYangSources(yangFilesDirectoryPath, yangLibsDirectoryPath, null);
-    }
-
-    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());
-        final File libsDir = new File(StmtTestUtils.class.getResource(yangLibsDirectoryPath).toURI());
-
-        return parseYangSources(yangsDir.listFiles(YANG_FILE_FILTER), libsDir.listFiles(YANG_FILE_FILTER),
-                supportedFeatures);
-    }
-
-    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++) {
-            yangSources[i] = YangStatementStreamSource.create(YangTextSchemaSource.forFile(yangFiles[i]));
-        }
-
-        final StatementStreamSource[] libSources = new StatementStreamSource[libFiles.length];
-        for (int i = 0; i < libFiles.length; i++) {
-            libSources[i] = YangStatementStreamSource.create(YangTextSchemaSource.forFile(libFiles[i]));
-        }
-
-        return parseYangSources(yangSources, libSources, supportedFeatures);
-    }
-
-    private static EffectiveModelContext parseYangSources(final StatementStreamSource[] yangSources,
-            final StatementStreamSource[] libSources, final Set<QName> supportedFeatures) throws ReactorException {
-
-        final BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild()
-                .addSources(yangSources).addLibSources(libSources);
-        if (supportedFeatures != null) {
-            reactor.setSupportedFeatures(supportedFeatures);
-        }
-
-        return reactor.buildEffective();
-    }
-
     public static EffectiveModelContext parseYinSources(final String yinSourcesDirectoryPath)
             throws URISyntaxException, SAXException, IOException, ReactorException {
         return parseYinSources(yinSourcesDirectoryPath, YangParserConfiguration.DEFAULT);
@@ -281,26 +186,6 @@ public final class StmtTestUtils {
                 .orElse(null);
     }
 
-    /**
-     * Assertion that a {@link SchemaNode} reports expected path. This method deals with {@link SchemaNode#getPath()}
-     * being unavailable by comparing {@link SchemaNode#getQName()} to {@link SchemaPath#getLastComponent()}.
-     *
-     * @param expected Expected
-     * @param node Node to examine
-     * @throws AssertionError if the
-     */
-    public static void assertPathEquals(final SchemaPath expected, final SchemaNode node) {
-        final SchemaPath actual;
-        try {
-            actual = node.getPath();
-        } catch (UnsupportedOperationException e) {
-            LOG.trace("Node {} does not support getPath()", node, e);
-            assertEquals(expected.getLastComponent(), node.getQName());
-            return;
-        }
-        assertEquals(expected, actual);
-    }
-
     private static CrossSourceStatementReactor getReactor(final YangParserConfiguration config) {
         return YangParserConfiguration.DEFAULT.equals(config) ? RFC7950Reactors.defaultReactor()
             : RFC7950Reactors.defaultReactorBuilder(config).build();