From: Robert Varga Date: Wed, 21 Oct 2020 20:59:15 +0000 (+0200) Subject: Workaround test model loading issues X-Git-Tag: v6.0.1~49 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=e33920b9525f898e1db493f98aa2f97785005894;p=yangtools.git Workaround test model loading issues Going to a JPMS module means our resources are subject to encapsulation -- which means things like YangTextSchemaSource.forResource() actually depend on where the resource if located. If its location ends up being in a valid package, that request will fail, as JRE will consider the resource encapsulated and will reject external module's attempt to meddle with it (such as yang.model.api). As it turns out some of models are matching this check and we load them through such facilities. In some cases we can re-route in a way which makes things less verbose -- and we do that in this patch. JIRA: YANGTOOLS-1151 Change-Id: Ib55cadd9eba840980eeba3b9004d8f9c4101e33d Signed-off-by: Robert Varga --- diff --git a/yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5693Test.java b/yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5693Test.java index 292a6c753b..509bb38151 100644 --- a/yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5693Test.java +++ b/yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5693Test.java @@ -5,17 +5,16 @@ * 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 static org.junit.Assert.assertNotNull; import java.io.IOException; +import java.net.URISyntaxException; import org.junit.Before; import org.junit.Test; import org.opendaylight.yangtools.yang.model.api.Module; -import org.opendaylight.yangtools.yang.model.repo.api.YinTextSchemaSource; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.xml.sax.SAXException; @@ -27,8 +26,8 @@ public class Bug5693Test { * Use input stream to load Yin module. */ @Before - public void initTest() throws ReactorException, SAXException, IOException { - foo = TestUtils.loadYinModule(YinTextSchemaSource.forResource(getClass(), "/bugs/bug5693/foo.yin")); + public void initTest() throws ReactorException, SAXException, IOException, URISyntaxException { + foo = StmtTestUtils.parseYinSources("/bugs/bug5693").getModules().iterator().next(); } /** diff --git a/yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/ChoiceStmtTest.java b/yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/ChoiceStmtTest.java index 23d504c51e..f604cc8df3 100644 --- a/yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/ChoiceStmtTest.java +++ b/yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/ChoiceStmtTest.java @@ -9,8 +9,9 @@ package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource; +import java.io.IOException; +import java.net.URISyntaxException; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode; @@ -18,22 +19,13 @@ import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode; import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors; +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.source.StatementStreamSource; public class ChoiceStmtTest { - - private static final StatementStreamSource CHOICE_MODULE = sourceForResource("/model/foo.yang"); - private static final StatementStreamSource IMPORTED_MODULE1 = sourceForResource("/model/bar.yang"); - private static final StatementStreamSource IMPORTED_MODULE2 = sourceForResource("/model/baz.yang"); - private static final StatementStreamSource INCLUDED_MODULE = sourceForResource("/model/subfoo.yang"); - @Test - public void choiceAndCaseTest() throws ReactorException { - final SchemaContext result = RFC7950Reactors.defaultReactor().newBuild() - .addSources(CHOICE_MODULE, IMPORTED_MODULE1, IMPORTED_MODULE2, INCLUDED_MODULE) - .buildEffective(); + public void choiceAndCaseTest() throws ReactorException, YangSyntaxErrorException, URISyntaxException, IOException { + final SchemaContext result = StmtTestUtils.parseYangSources("/model"); assertNotNull(result); final Module testModule = result.findModules("foo").iterator().next(); diff --git a/yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/StmtTestUtils.java b/yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/StmtTestUtils.java index 13a1e12a98..2b619e0f32 100644 --- a/yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/StmtTestUtils.java +++ b/yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/StmtTestUtils.java @@ -236,6 +236,11 @@ public final class StmtTestUtils { 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 {