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;
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;
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();
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 {
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);
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);
}
}
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);
}
}