import java.io.IOException;
import java.net.URISyntaxException;
-import java.text.ParseException;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.model.api.ElementCountConstraint;
import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
-import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
-import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
public class ElementCountConstraintsTest {
-
@Test
- public void testElementCountConstraints() throws ParseException, ReactorException, URISyntaxException, IOException,
- YangSyntaxErrorException {
- final SchemaContext schemaContext = RFC7950Reactors.defaultReactor().newBuild()
- .addSource(YangStatementStreamSource.create(
- YangTextSchemaSource.forResource("/constraint-definitions-test/foo.yang")))
- .buildEffective();
+ public void testElementCountConstraints()
+ throws YangSyntaxErrorException, ReactorException, URISyntaxException, IOException {
+ final var schemaContext = StmtTestUtils.parseYangSource("/constraint-definitions-test/foo.yang");
assertNotNull(schemaContext);
final Module testModule = schemaContext.findModule("foo", Revision.of("2016-09-20")).get();
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.yangtools.yang.stmt;
import static org.junit.Assert.assertEquals;
import org.opendaylight.yangtools.yang.model.api.Status;
import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
import org.opendaylight.yangtools.yang.model.util.SimpleSchemaContext;
import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
-import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveSchemaContext;
public class EffectiveSchemaContextTest {
-
@Test
public void testEffectiveSchemaContext() throws ReactorException, ParseException, URISyntaxException, IOException,
YangSyntaxErrorException {
final EffectiveSchemaContext schemaContext = RFC7950Reactors.defaultReactor().newBuild()
- .addSource(YangStatementStreamSource.create(YangTextSchemaSource.forResource(
- "/effective-schema-context-test/foo.yang")))
- .addSource(YangStatementStreamSource.create(YangTextSchemaSource.forResource(
- "/effective-schema-context-test/bar.yang")))
- .addSource(YangStatementStreamSource.create(YangTextSchemaSource.forResource(
- "/effective-schema-context-test/baz.yang")))
- .buildEffective();
+ .addSource(StmtTestUtils.sourceForResource("/effective-schema-context-test/foo.yang"))
+ .addSource(StmtTestUtils.sourceForResource("/effective-schema-context-test/bar.yang"))
+ .addSource(StmtTestUtils.sourceForResource("/effective-schema-context-test/baz.yang"))
+ .buildEffective();
assertNotNull(schemaContext);
final Collection<? extends DataSchemaNode> dataDefinitions = schemaContext.getDataDefinitions();
@Test
public void testOrderingNestedChildNodes3() throws Exception {
- final Module justFoo = TestUtils.loadModuleResources(getClass(), "/ordering/foo.yang")
- .getModules().iterator().next();
+ final Module justFoo = StmtTestUtils.parseYangSource("/ordering/foo.yang").getModules().iterator().next();
final ContainerSchemaNode x = (ContainerSchemaNode) justFoo
.getDataChildByName(QName.create(justFoo.getQNameModule(), "x"));
final Collection<? extends DataSchemaNode> childNodes = x.getChildNodes();
public static StatementStreamSource sourceForResource(final String resourceName) {
try {
- return YangStatementStreamSource.create(YangTextSchemaSource.forResource(resourceName));
+ return YangStatementStreamSource.create(YangTextSchemaSource.forResource(
+ StmtTestUtils.class, resourceName));
} catch (IOException | YangSyntaxErrorException e) {
throw new IllegalArgumentException("Failed to create source", e);
}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
-import java.io.IOException;
import java.util.Collection;
import org.junit.Test;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.ModuleImport;
-import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
public class YangParserIdentityTest {
// base identity name equals identity name
@Test(expected = SomeModifiersUnresolvedException.class)
- public void testParsingIdentityTestModule() throws IOException, ReactorException, YangSyntaxErrorException {
+ public void testParsingIdentityTestModule() throws Exception {
try {
- TestUtils.loadModuleResources(getClass(), "/identity/identitytest.yang");
+ StmtTestUtils.parseYangSource("/identity/identitytest.yang");
} catch (SomeModifiersUnresolvedException e) {
StmtTestUtils.log(e, " ");
throw e;
// same module prefixed base identity name equals identity name
@Test(expected = SomeModifiersUnresolvedException.class)
- public void testParsingPrefixIdentityTestModule() throws IOException, ReactorException, YangSyntaxErrorException {
+ public void testParsingPrefixIdentityTestModule() throws Exception {
try {
- TestUtils.loadModuleResources(getClass(), "/identity/prefixidentitytest.yang");
+ StmtTestUtils.parseYangSource("/identity/prefixidentitytest.yang");
} catch (SomeModifiersUnresolvedException e) {
StmtTestUtils.log(e, " ");
throw e;
// prefix differs
@Test
public void testParsingImportPrefixIdentityTestModule() throws Exception {
- Module module = TestUtils.findModule(TestUtils.loadModules(getClass().getResource("/identity/import").toURI()),
+ Module module = TestUtils.findModule(StmtTestUtils.parseYangSources("/identity/import"),
"prefiximportidentitytest").get();
Collection<? extends ModuleImport> imports = module.getImports();
assertEquals(imports.size(), 1);
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
-import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
+import org.opendaylight.yangtools.yang.stmt.StmtTestUtils;
public class ThirdPartyExtensionPluginTest {
private static final String NS = "urn:opendaylight:yang:extension:third-party";
@Test
public void test() throws URISyntaxException, ReactorException, IOException, YangSyntaxErrorException {
final CrossSourceStatementReactor.BuildAction reactor = CustomInferencePipeline.CUSTOM_REACTOR.newBuild();
- reactor.addSource(YangStatementStreamSource.create(YangTextSchemaSource.forResource("/plugin-test/foo.yang")));
+ reactor.addSource(StmtTestUtils.sourceForResource("/plugin-test/foo.yang"));
final SchemaContext schema = reactor.buildEffective();
final DataSchemaNode dataChildByName = schema.getDataChildByName(QName.create(NS, REV, "root"));