*/
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 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;
return result;
}
- public static StatementStreamSource sourceForResource(final String resourceName) {
+ public static YangStatementStreamSource sourceForResource(final String resourceName) {
try {
- return YangStatementStreamSource.create(YangTextSchemaSource.forResource(
- StmtTestUtils.class, 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);
}
}
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 {
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);
+ }
}