Move Bug5437Test to yang-model-util-ut
[yangtools.git] / yang / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / StmtTestUtils.java
index a4c26fb24f22bb0a17164819e88ad2fed03ec942..9213e929a66b07829650113ca37df8e4a08b80b1 100644 (file)
@@ -7,6 +7,8 @@
  */
 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;
@@ -27,6 +29,8 @@ 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.parser.api.YangSyntaxErrorException;
 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
@@ -77,10 +81,11 @@ public final class StmtTestUtils {
         return result;
     }
 
-    public static StatementStreamSource sourceForResource(final String resourceName) {
+    public static YangStatementStreamSource 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);
         }
     }
@@ -235,6 +240,11 @@ public final class StmtTestUtils {
         return reactor.buildEffective();
     }
 
+    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 {
@@ -269,4 +279,24 @@ public final class StmtTestUtils {
         return context.findModule(requestedModuleImport.getModuleName(), requestedModuleImport.getRevision())
                 .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);
+    }
 }