Bug4231 - Yang tools failing to parse Augmentations under "uses" clause.
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / parser / impl / TestUtils.java
index 8fd6c1896dc640b324acc54dedd1f232a7e2bc34..dcbaa85a065eb6e6cf626ef7d8769eec13ddaef2 100644 (file)
@@ -8,9 +8,9 @@
 package org.opendaylight.yangtools.yang.parser.impl;
 
 import static org.junit.Assert.assertEquals;
-
 import com.google.common.io.ByteSource;
 import com.google.common.io.ByteStreams;
+import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
@@ -27,7 +27,7 @@ import java.util.List;
 import java.util.Set;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
-import org.opendaylight.yangtools.yang.model.api.ChoiceNode;
+import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
@@ -46,8 +46,8 @@ final class TestUtils {
     private TestUtils() {
     }
 
-
-    public static Set<Module> loadModules(final URI resourceDirectory) throws IOException {
+    public static SchemaContext loadSchemaContext(final URI resourceDirectory)
+            throws IOException {
         final YangContextParser parser = new YangParserImpl();
         final File testDir = new File(resourceDirectory);
         final String[] fileList = testDir.list();
@@ -58,8 +58,12 @@ final class TestUtils {
         for (String fileName : fileList) {
             testFiles.add(new File(testDir, fileName));
         }
-        SchemaContext ctx = parser.parseFiles(testFiles);
-        return ctx.getModules();
+        return parser.parseFiles(testFiles);
+    }
+
+    public static Set<Module> loadModules(final URI resourceDirectory)
+            throws IOException {
+        return loadSchemaContext(resourceDirectory).getModules();
     }
 
     public static Set<Module> loadModules(final List<InputStream> input) throws IOException, YangSyntaxErrorException {
@@ -88,7 +92,12 @@ final class TestUtils {
 
         final byte[] streamContent = ByteStreams.toByteArray(stream);
 
-        ByteSource source = ByteStreams.asByteSource(streamContent);
+        ByteSource source = new ByteSource() {
+            @Override
+            public InputStream openStream() throws IOException {
+                return new ByteArrayInputStream(streamContent);
+            }
+        };
 
         final Collection<ByteSource> sources = Collections.singletonList(source);
         SchemaContext ctx = parser.parseSources(sources, context);
@@ -149,7 +158,7 @@ final class TestUtils {
     public static SchemaPath createPath(final boolean absolute, final URI namespace, final Date revision, final String prefix, final String... names) {
         List<QName> path = new ArrayList<>();
         for (String name : names) {
-            path.add(new QName(namespace, revision, prefix, name));
+            path.add(QName.create(namespace, revision, name));
         }
         return SchemaPath.create(path, absolute);
     }
@@ -180,8 +189,8 @@ final class TestUtils {
             for (DataSchemaNode child : ((DataNodeContainer) node).getChildNodes()) {
                 checkIsAugmenting(child, expected);
             }
-        } else if (node instanceof ChoiceNode) {
-            for (ChoiceCaseNode caseNode : ((ChoiceNode) node).getCases()) {
+        } else if (node instanceof ChoiceSchemaNode) {
+            for (ChoiceCaseNode caseNode : ((ChoiceSchemaNode) node).getCases()) {
                 checkIsAugmenting(caseNode, expected);
             }
         }
@@ -202,8 +211,8 @@ final class TestUtils {
             for (DataSchemaNode child : ((DataNodeContainer) node).getChildNodes()) {
                 checkIsAddedByUses(child, expected);
             }
-        } else if (node instanceof ChoiceNode) {
-            for (ChoiceCaseNode caseNode : ((ChoiceNode) node).getCases()) {
+        } else if (node instanceof ChoiceSchemaNode) {
+            for (ChoiceCaseNode caseNode : ((ChoiceSchemaNode) node).getCases()) {
                 checkIsAddedByUses(caseNode, expected);
             }
         }