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 300ed776ffc10fff613dabc3ad7ae24341314ed5..dcbaa85a065eb6e6cf626ef7d8769eec13ddaef2 100644 (file)
@@ -10,6 +10,7 @@ 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;
@@ -26,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;
@@ -45,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();
@@ -57,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 {
@@ -87,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);
@@ -179,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);
             }
         }
@@ -201,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);
             }
         }