From: Robert Varga Date: Fri, 1 Sep 2017 09:46:18 +0000 (+0200) Subject: Remove deprecated Yin/YangStatementSourceImpl X-Git-Tag: v2.0.0~225 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=02d724c5ef8e51e7981a97f8418e4d6804aafe22;p=yangtools.git Remove deprecated Yin/YangStatementSourceImpl These classes have been superseded by Yin/YangStatementStreamSource, which have better semantics. Remove them and fixup former call sites. Change-Id: I9f16e62da8cf38ce35703de6a93b1d5d9dcdf2e8 Signed-off-by: Robert Varga --- diff --git a/yang-validation-tool/src/main/java/org/opendaylight/yangtools/yang/validation/tool/Main.java b/yang-validation-tool/src/main/java/org/opendaylight/yangtools/yang/validation/tool/Main.java index 5eab866e83..3703f496ab 100644 --- a/yang-validation-tool/src/main/java/org/opendaylight/yangtools/yang/validation/tool/Main.java +++ b/yang-validation-tool/src/main/java/org/opendaylight/yangtools/yang/validation/tool/Main.java @@ -9,7 +9,6 @@ package org.opendaylight.yangtools.yang.validation.tool; import java.io.File; import java.net.URISyntaxException; -import java.util.Arrays; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -28,7 +27,7 @@ public final class Main { final File[] yangModels = params.getYangSourceDir().listFiles(); try { - YangParserTestUtils.parseYangSources(Arrays.asList(yangModels)); + YangParserTestUtils.parseYangFiles(yangModels); } catch (Exception e) { LOG.error("Yang files could not be parsed.", e); } diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/AnyXmlSupportTest.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/AnyXmlSupportTest.java index 0970dde218..28ffdb8a7e 100644 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/AnyXmlSupportTest.java +++ b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/AnyXmlSupportTest.java @@ -37,7 +37,6 @@ import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeS import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.SchemaPath; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -53,8 +52,8 @@ public class AnyXmlSupportTest { private static SchemaContext schemaContext; @BeforeClass - public static void setup() throws IOException, URISyntaxException, ReactorException { - schemaContext = YangParserTestUtils.parseYangSources("/complexjson/yang"); + public static void setup() { + schemaContext = YangParserTestUtils.parseYangResourceDirectory("/complexjson/yang"); } @Test diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug4501Test.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug4501Test.java index f4157ea535..da3da85999 100644 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug4501Test.java +++ b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug4501Test.java @@ -30,7 +30,6 @@ import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStre import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter; import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; public class Bug4501Test { @@ -38,8 +37,8 @@ public class Bug4501Test { private static SchemaContext schemaContext; @BeforeClass - public static void initialization() throws IOException, URISyntaxException, ReactorException { - schemaContext = YangParserTestUtils.parseYangSources("/bug-4501/yang"); + public static void initialization() { + schemaContext = YangParserTestUtils.parseYangResourceDirectory("/bug-4501/yang"); } @Test diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug4969Test.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug4969Test.java index 945cd3c55e..0077fb575f 100644 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug4969Test.java +++ b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug4969Test.java @@ -13,7 +13,6 @@ import static org.junit.Assert.assertTrue; import com.google.common.base.Optional; import com.google.gson.stream.JsonReader; -import java.io.File; import java.io.IOException; import java.io.StringReader; import java.net.URISyntaxException; @@ -29,16 +28,13 @@ import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStre import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter; import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; public class Bug4969Test { @Test - public void newParserLeafRefTest() throws SourceException, ReactorException, URISyntaxException, IOException { - File sourceDir = new File(Bug4969Test.class.getResource("/bug-4969/yang").toURI()); - SchemaContext context = YangParserTestUtils.parseYangSources(sourceDir.listFiles()); + public void newParserLeafRefTest() throws IOException, URISyntaxException { + SchemaContext context = YangParserTestUtils.parseYangResourceDirectory("/bug-4969/yang"); assertNotNull(context); verifyNormalizedNodeResult(context); @@ -95,9 +91,8 @@ public class Bug4969Test { } @Test - public void newParserLeafRefTest2() throws SourceException, ReactorException, URISyntaxException, IOException { - File sourceDir = new File(Bug4969Test.class.getResource("/leafref/yang").toURI()); - SchemaContext context = YangParserTestUtils.parseYangSources(sourceDir.listFiles()); + public void newParserLeafRefTest2() throws URISyntaxException, IOException { + SchemaContext context = YangParserTestUtils.parseYangResourceDirectory("/leafref/yang"); assertNotNull(context); parseJsonToNormalizedNodes(context); diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug5446Test.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug5446Test.java index 4c937f2fcb..55ce9c74a2 100644 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug5446Test.java +++ b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug5446Test.java @@ -54,8 +54,7 @@ public class Bug5446Test { rootQName = QName.create(fooModuleQName, "root"); ipAddressQName = QName.create(fooModuleQName, "ip-address"); - schemaContext = YangParserTestUtils.parseYangSources( - new File(Bug5446Test.class.getResource("/bug5446/yang/foo.yang").toURI())); + schemaContext = YangParserTestUtils.parseYangResources(Bug5446Test.class, "/bug5446/yang/foo.yang"); } @Test diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug6112Test.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug6112Test.java index 8c4f14cc86..5e14e6eced 100644 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug6112Test.java +++ b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug6112Test.java @@ -28,15 +28,14 @@ import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStre import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter; import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; public class Bug6112Test { private static SchemaContext schemaContext; @BeforeClass - public static void initialization() throws IOException, URISyntaxException, ReactorException { - schemaContext = YangParserTestUtils.parseYangSources("/bug-6112/yang"); + public static void initialization() { + schemaContext = YangParserTestUtils.parseYangResourceDirectory("/bug-6112/yang"); } private static NormalizedNode readJson(final String jsonPath) throws IOException, URISyntaxException { diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug7246Test.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug7246Test.java index 511ab97bbe..912b89a334 100644 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug7246Test.java +++ b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug7246Test.java @@ -38,7 +38,7 @@ public class Bug7246Test { @Test public void test() throws Exception { - final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/bug7246/yang/rpc-test.yang"); + final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/bug7246/yang/rpc-test.yang"); final JsonParser parser = new JsonParser(); final JsonElement expextedJson = parser .parse(new FileReader(new File(getClass().getResource("/bug7246/json/expected-output.json").toURI()))); diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug8083Test.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug8083Test.java index 618dca1e55..98858d396e 100644 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug8083Test.java +++ b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug8083Test.java @@ -12,7 +12,9 @@ import static org.junit.Assert.assertNotNull; import static org.opendaylight.yangtools.yang.data.codec.gson.TestUtils.loadTextFile; import com.google.gson.stream.JsonReader; +import java.io.IOException; import java.io.StringReader; +import java.net.URISyntaxException; import org.junit.Ignore; import org.junit.Test; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; @@ -26,8 +28,8 @@ public class Bug8083Test { @Ignore("Instance-identifier codec has to be modified according to the RFC7951 to correctly parse this.") @Test - public void testRFC7951InstanceIdentifierPath() throws Exception { - final SchemaContext schemaContext = YangParserTestUtils.parseYangSources("/bug8083/yang/"); + public void testRFC7951InstanceIdentifierPath() throws IOException, URISyntaxException { + final SchemaContext schemaContext = YangParserTestUtils.parseYangResourceDirectory("/bug8083/yang/"); final String inputJson = loadTextFile("/bug8083/json/foo.json"); // deserialization @@ -41,8 +43,8 @@ public class Bug8083Test { @Ignore("JSONEmptyCodec needs to be fixed first.") @Test - public void testInstanceIdentifierPathWithEmptyListKey() throws Exception { - final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/bug8083/yang/baz.yang"); + public void testInstanceIdentifierPathWithEmptyListKey() throws IOException, URISyntaxException { + final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/bug8083/yang/baz.yang"); final String inputJson = loadTextFile("/bug8083/json/baz.json"); // deserialization @@ -55,8 +57,8 @@ public class Bug8083Test { } @Test - public void testInstanceIdentifierPathWithIdentityrefListKey() throws Exception { - final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/bug8083/yang/zab.yang"); + public void testInstanceIdentifierPathWithIdentityrefListKey() throws IOException, URISyntaxException { + final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/bug8083/yang/zab.yang"); final String inputJson = loadTextFile("/bug8083/json/zab.json"); // deserialization @@ -69,8 +71,8 @@ public class Bug8083Test { } @Test - public void testInstanceIdentifierPathWithInstanceIdentifierListKey() throws Exception { - final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/bug8083/yang/foobar.yang"); + public void testInstanceIdentifierPathWithInstanceIdentifierListKey() throws IOException, URISyntaxException { + final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/bug8083/yang/foobar.yang"); final String inputJson = loadTextFile("/bug8083/json/foobar.json"); // deserialization diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/JsonStreamToNormalizedNodeTest.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/JsonStreamToNormalizedNodeTest.java index bd852e288b..c2fb1fdcb0 100644 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/JsonStreamToNormalizedNodeTest.java +++ b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/JsonStreamToNormalizedNodeTest.java @@ -33,7 +33,6 @@ import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeS import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.SchemaNode; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; /** @@ -46,8 +45,8 @@ public class JsonStreamToNormalizedNodeTest { private static SchemaContext schemaContext; @BeforeClass - public static void initialization() throws IOException, URISyntaxException, ReactorException { - schemaContext = YangParserTestUtils.parseYangSources("/complexjson/yang"); + public static void initialization() { + schemaContext = YangParserTestUtils.parseYangResourceDirectory("/complexjson/yang"); } @Test diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/NormalizedNodeToJsonStreamTest.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/NormalizedNodeToJsonStreamTest.java index 7271c929b3..a07868646d 100644 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/NormalizedNodeToJsonStreamTest.java +++ b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/NormalizedNodeToJsonStreamTest.java @@ -39,7 +39,6 @@ import org.opendaylight.yangtools.yang.data.impl.schema.Builders; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.SchemaPath; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; /** @@ -54,8 +53,8 @@ public class NormalizedNodeToJsonStreamTest { private static SchemaContext schemaContext; @BeforeClass - public static void initialization() throws IOException, URISyntaxException, ReactorException { - schemaContext = YangParserTestUtils.parseYangSources("/complexjson/yang"); + public static void initialization() { + schemaContext = YangParserTestUtils.parseYangResourceDirectory("/complexjson/yang"); } @Test diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/StreamToNormalizedNodeTest.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/StreamToNormalizedNodeTest.java index 0cfefdcbd3..0591c5e2c7 100644 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/StreamToNormalizedNodeTest.java +++ b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/StreamToNormalizedNodeTest.java @@ -28,7 +28,6 @@ import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeS import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.SchemaPath; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,8 +38,8 @@ public class StreamToNormalizedNodeTest { private static String streamAsString; @BeforeClass - public static void initialization() throws IOException, URISyntaxException, ReactorException { - schemaContext = YangParserTestUtils.parseYangSources("/complexjson/yang"); + public static void initialization() throws IOException, URISyntaxException { + schemaContext = YangParserTestUtils.parseYangResourceDirectory("/complexjson/yang"); streamAsString = loadTextFile(new File(StreamToNormalizedNodeTest.class.getResource( "/complexjson/complex-json.json").toURI())); } diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/YangModeledAnyXmlSupportTest.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/YangModeledAnyXmlSupportTest.java index d491495957..34f9661d7f 100644 --- a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/YangModeledAnyXmlSupportTest.java +++ b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/YangModeledAnyXmlSupportTest.java @@ -43,7 +43,6 @@ 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.model.api.SchemaPath; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; import org.xml.sax.SAXException; @@ -53,9 +52,9 @@ public class YangModeledAnyXmlSupportTest { private static ContainerNode data; @BeforeClass - public static void init() throws IOException, URISyntaxException, ReactorException, SAXException, - XMLStreamException, ParserConfigurationException { - schemaContext = YangParserTestUtils.parseYangSources("/yang-modeled-anyxml/yang"); + public static void init() throws XMLStreamException, URISyntaxException, IOException, ParserConfigurationException, + SAXException { + schemaContext = YangParserTestUtils.parseYangResourceDirectory("/yang-modeled-anyxml/yang"); final Module bazModule = schemaContext.findModuleByName("baz", null); final ContainerSchemaNode bazCont = (ContainerSchemaNode) bazModule.getDataChildByName( QName.create(bazModule.getQNameModule(), "baz")); diff --git a/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Bug5396Test.java b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Bug5396Test.java index 938962e75e..75cf4b42eb 100644 --- a/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Bug5396Test.java +++ b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Bug5396Test.java @@ -45,8 +45,7 @@ public class Bug5396Test { public void setUp() throws Exception { fooModuleQName = QNameModule.create(new URI("foo"), SimpleDateFormatUtil.getRevisionFormat().parse( "2016-03-22")); - - schemaContext = YangParserTestUtils.parseYangSource("/bug5396/yang/foo.yang"); + schemaContext = YangParserTestUtils.parseYangResource("/bug5396/yang/foo.yang"); } @Test diff --git a/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Bug5446Test.java b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Bug5446Test.java index c6cfe00caf..e922752f97 100644 --- a/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Bug5446Test.java +++ b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Bug5446Test.java @@ -68,7 +68,7 @@ public class Bug5446Test extends XMLTestCase { rootQName = QName.create(fooModuleQName, "root"); ipAddressQName = QName.create(fooModuleQName, "ip-address"); - schemaContext = YangParserTestUtils.parseYangSource("/bug5446/yang/foo.yang"); + schemaContext = YangParserTestUtils.parseYangResource("/bug5446/yang/foo.yang"); } @Test diff --git a/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Bug8083Test.java b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Bug8083Test.java index 7d91be0758..83c2107c61 100644 --- a/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Bug8083Test.java +++ b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Bug8083Test.java @@ -30,7 +30,7 @@ public class Bug8083Test { @Ignore("XMLEmptyCodec needs to be fixed first.") @Test public void testInstanceIdentifierPathWithEmptyListKey() throws Exception { - final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/bug8083/yang/baz.yang"); + final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/bug8083/yang/baz.yang"); final Module bazModule = schemaContext.getModules().iterator().next(); final ContainerSchemaNode topCont = (ContainerSchemaNode) bazModule.getDataChildByName( QName.create(bazModule.getQNameModule(), "top-cont")); @@ -52,7 +52,7 @@ public class Bug8083Test { @Test public void testInstanceIdentifierPathWithIdentityrefListKey() throws Exception { - final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/bug8083/yang/zab.yang"); + final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/bug8083/yang/zab.yang"); final Module zabModule = schemaContext.getModules().iterator().next(); final ContainerSchemaNode topCont = (ContainerSchemaNode) zabModule.getDataChildByName( QName.create(zabModule.getQNameModule(), "top-cont")); @@ -74,7 +74,7 @@ public class Bug8083Test { @Test public void testInstanceIdentifierPathWithInstanceIdentifierListKey() throws Exception { - final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/bug8083/yang/foobar.yang"); + final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/bug8083/yang/foobar.yang"); final Module foobarModule = schemaContext.getModules().iterator().next(); final ContainerSchemaNode topCont = (ContainerSchemaNode) foobarModule.getDataChildByName( QName.create(foobarModule.getQNameModule(), "top-cont")); diff --git a/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Bug8675Test.java b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Bug8675Test.java index 86fa2f2c22..55e2c06cdd 100644 --- a/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Bug8675Test.java +++ b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Bug8675Test.java @@ -36,7 +36,7 @@ public class Bug8675Test { @BeforeClass public static void setup() throws Exception { - schemaContext = YangParserTestUtils.parseYangSource("/bug8675/foo.yang"); + schemaContext = YangParserTestUtils.parseYangResource("/bug8675/foo.yang"); fooModule = schemaContext.getModules().iterator().next(); } diff --git a/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Bug8745Test.java b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Bug8745Test.java index c975fb7d95..39ea5ea754 100644 --- a/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Bug8745Test.java +++ b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Bug8745Test.java @@ -44,7 +44,7 @@ public class Bug8745Test { @Test public void testParsingAttributes() throws Exception { - final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/bug8745/foo.yang"); + final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/bug8745/foo.yang"); final QName contWithAttributes = QName.create("foo", "1970-01-01", "cont-with-attributes"); final ContainerSchemaNode contWithAttr = (ContainerSchemaNode) SchemaContextUtil.findDataSchemaNode( schemaContext, SchemaPath.create(true, contWithAttributes)); diff --git a/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Bug8803Test.java b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Bug8803Test.java index d708e176d3..c0a9f657cf 100644 --- a/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Bug8803Test.java +++ b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Bug8803Test.java @@ -35,7 +35,7 @@ public class Bug8803Test { @Test public void test() throws Exception { - final SchemaContext schemaContext = YangParserTestUtils.parseYangSources("/bug8803"); + final SchemaContext schemaContext = YangParserTestUtils.parseYangResourceDirectory("/bug8803"); final SchemaPath topContPath = SchemaPath.create(true, QName.create("foo-ns", "1970-01-01", "top-cont")); final SchemaNode dataSchemaNode = SchemaContextUtil.findDataSchemaNode(schemaContext, topContPath); assertTrue(dataSchemaNode instanceof ContainerSchemaNode); diff --git a/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/DOMSourceXMLStreamReaderTest.java b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/DOMSourceXMLStreamReaderTest.java index 1165293ad2..d2b22b0327 100644 --- a/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/DOMSourceXMLStreamReaderTest.java +++ b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/DOMSourceXMLStreamReaderTest.java @@ -47,7 +47,7 @@ public class DOMSourceXMLStreamReaderTest { @Test public void test() throws Exception { - final SchemaContext schemaContext = YangParserTestUtils.parseYangSources("/dom-reader-test"); + final SchemaContext schemaContext = YangParserTestUtils.parseYangResourceDirectory("/dom-reader-test"); final ContainerSchemaNode outerContainerSchema = (ContainerSchemaNode) SchemaContextUtil .findNodeInSchemaContext(schemaContext, ImmutableList.of(QName.create("foo-ns", "1970-01-01", "top-cont"))); diff --git a/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/NormalizedNodeXmlTranslationTest.java b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/NormalizedNodeXmlTranslationTest.java index 26268bdd25..e86d1a47d5 100644 --- a/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/NormalizedNodeXmlTranslationTest.java +++ b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/NormalizedNodeXmlTranslationTest.java @@ -16,12 +16,10 @@ import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.le import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSet; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.StringWriter; import java.net.URI; -import java.net.URISyntaxException; import java.text.ParseException; import java.util.ArrayList; import java.util.Arrays; @@ -79,7 +77,6 @@ import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; import org.w3c.dom.Document; import org.w3c.dom.Node; @@ -263,8 +260,8 @@ public class NormalizedNodeXmlTranslationTest { } public NormalizedNodeXmlTranslationTest(final String yangPath, final String xmlPath, - final ContainerNode expectedNode) throws ReactorException, FileNotFoundException, URISyntaxException { - this.schema = YangParserTestUtils.parseYangSource(yangPath); + final ContainerNode expectedNode) { + this.schema = YangParserTestUtils.parseYangResource(yangPath); this.xmlPath = xmlPath; this.containerNode = (ContainerSchemaNode) getSchemaNode(schema, "test", "container"); this.expectedNode = expectedNode; diff --git a/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/NormalizedNodesToXmlTest.java b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/NormalizedNodesToXmlTest.java index cc5b9e91d5..3cacbc3eb2 100644 --- a/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/NormalizedNodesToXmlTest.java +++ b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/NormalizedNodesToXmlTest.java @@ -55,7 +55,6 @@ import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStre import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter; import org.opendaylight.yangtools.yang.data.impl.schema.Builders; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; import org.w3c.dom.Document; import org.w3c.dom.Node; @@ -118,9 +117,8 @@ public class NormalizedNodesToXmlTest { } @Test - public void testNormalizedNodeToXmlSerialization() throws ReactorException, XMLStreamException, IOException, - SAXException, URISyntaxException { - final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/baz.yang"); + public void testNormalizedNodeToXmlSerialization() throws XMLStreamException, IOException, SAXException { + final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/baz.yang"); final Document doc = loadDocument("/baz.xml"); diff --git a/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/StrictParsingModeTest.java b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/StrictParsingModeTest.java index cdc6f0a813..fd15f68ba5 100644 --- a/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/StrictParsingModeTest.java +++ b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/StrictParsingModeTest.java @@ -31,7 +31,7 @@ public class StrictParsingModeTest { @Test public void testLenientParsing() throws Exception { // unknown child nodes in the top-level-container node will be skipped when the strictParsing is set to false - final SchemaContext schemaContext = YangParserTestUtils.parseYangSource( + final SchemaContext schemaContext = YangParserTestUtils.parseYangResource( "/strict-parsing-mode-test/foo.yang"); final Module fooModule = schemaContext.getModules().iterator().next(); final ContainerSchemaNode topLevelContainer = (ContainerSchemaNode) fooModule.getDataChildByName( @@ -58,7 +58,7 @@ public class StrictParsingModeTest { public void testStrictParsing() throws Exception { // should fail because strictParsing is switched on and the top-level-container node contains child nodes // which are not defined in the provided YANG model - final SchemaContext schemaContext = YangParserTestUtils.parseYangSource( + final SchemaContext schemaContext = YangParserTestUtils.parseYangResource( "/strict-parsing-mode-test/foo.yang"); final Module fooModule = schemaContext.getModules().iterator().next(); final ContainerSchemaNode topLevelContainer = (ContainerSchemaNode) fooModule.getDataChildByName( diff --git a/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/XmlStreamUtilsTest.java b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/XmlStreamUtilsTest.java index 7868c2203a..f901a856f1 100644 --- a/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/XmlStreamUtilsTest.java +++ b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/XmlStreamUtilsTest.java @@ -57,7 +57,7 @@ public class XmlStreamUtilsTest { @BeforeClass public static void initialize() throws URISyntaxException, FileNotFoundException, ReactorException { - schemaContext = YangParserTestUtils.parseYangSource("/leafref-test.yang"); + schemaContext = YangParserTestUtils.parseYangResource("/leafref-test.yang"); assertNotNull(schemaContext); assertEquals(1, schemaContext.getModules().size()); leafRefModule = schemaContext.getModules().iterator().next(); diff --git a/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/XmlToNormalizedNodesTest.java b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/XmlToNormalizedNodesTest.java index 6ac565531e..a09362fc5b 100644 --- a/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/XmlToNormalizedNodesTest.java +++ b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/XmlToNormalizedNodesTest.java @@ -116,7 +116,7 @@ public class XmlToNormalizedNodesTest { mySecondKeyLeaf = QName.create(bazModule, "my-second-key-leaf"); myLeafInList3 = QName.create(bazModule, "my-leaf-in-list-3"); - schemaContext = YangParserTestUtils.parseYangSources("/"); + schemaContext = YangParserTestUtils.parseYangResourceDirectory("/"); parentContainerSchema = (ContainerSchemaNode) SchemaContextUtil.findNodeInSchemaContext(schemaContext, ImmutableList.of(parentContainer)); outerContainerSchema = (ContainerSchemaNode) SchemaContextUtil.findNodeInSchemaContext(schemaContext, diff --git a/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/YangModeledAnyXMLDeserializationTest.java b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/YangModeledAnyXMLDeserializationTest.java index fc062e46fa..f214feafa6 100644 --- a/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/YangModeledAnyXMLDeserializationTest.java +++ b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/YangModeledAnyXMLDeserializationTest.java @@ -75,7 +75,7 @@ public class YangModeledAnyXMLDeserializationTest { myLeaf2 = QName.create(fooModuleQName, "my-leaf-2"); myAnyXMLDataFoo = QName.create(fooModuleQName, "my-anyxml-data"); - schemaContext = YangParserTestUtils.parseYangSources("/anyxml-support/yang"); + schemaContext = YangParserTestUtils.parseYangResourceDirectory("/anyxml-support/yang"); } @Test diff --git a/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/YangModeledAnyXMLSerializationTest.java b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/YangModeledAnyXMLSerializationTest.java index 98e2a6c4d9..a6fe3062b0 100644 --- a/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/YangModeledAnyXMLSerializationTest.java +++ b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/YangModeledAnyXMLSerializationTest.java @@ -70,7 +70,7 @@ public class YangModeledAnyXMLSerializationTest extends XMLTestCase { myContainer2QName = QName.create(bazModuleQName, "my-container-2"); myAnyXMLDataBaz = QName.create(bazModuleQName, "my-anyxml-data"); - schemaContext = YangParserTestUtils.parseYangSources("/anyxml-support/serialization"); + schemaContext = YangParserTestUtils.parseYangResourceDirectory("/anyxml-support/serialization"); } @Test diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/Bug2964Test.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/Bug2964Test.java index dc8287a35a..b54848fffa 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/Bug2964Test.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/Bug2964Test.java @@ -48,7 +48,7 @@ public class Bug2964Test { @Before public void setUp() throws Exception { final File leafRefTestYang = new File(getClass().getResource("/leafref-test.yang").toURI()); - schema = YangParserTestUtils.parseYangSources(leafRefTestYang); + schema = YangParserTestUtils.parseYangFiles(leafRefTestYang); } public static Document readXmlToDocument(final String xmlContent) throws SAXException, IOException { diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/InstanceIdentifierForXmlCodecTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/InstanceIdentifierForXmlCodecTest.java index 4bf8e35875..9ccd604382 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/InstanceIdentifierForXmlCodecTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/InstanceIdentifierForXmlCodecTest.java @@ -40,7 +40,7 @@ public class InstanceIdentifierForXmlCodecTest { @Before public void setup() throws Exception { final File rpcTestYang = new File(getClass().getResource("iid-test.yang").toURI()); - this.schemaContext = YangParserTestUtils.parseYangSources(rpcTestYang); + this.schemaContext = YangParserTestUtils.parseYangFiles(rpcTestYang); final YangInstanceIdentifier.NodeIdentifier container = new YangInstanceIdentifier.NodeIdentifier( QName.create(InstanceIdentifierForXmlCodecTest.NS, InstanceIdentifierForXmlCodecTest.REVISION, "cont")); diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/XmlDocumentUtilsTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/XmlDocumentUtilsTest.java index a00976309f..ec7201b76d 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/XmlDocumentUtilsTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/XmlDocumentUtilsTest.java @@ -66,7 +66,7 @@ public class XmlDocumentUtilsTest { final File rpcTestYang1 = new File(getClass().getResource("xml-doc-test.yang").toURI()); final File rpcTestYang2 = new File(getClass().getResource("xml-doc-test2.yang").toURI()); - this.schema = YangParserTestUtils.parseYangSources(rpcTestYang1, rpcTestYang2); + this.schema = YangParserTestUtils.parseYangFiles(rpcTestYang1, rpcTestYang2); } public static Document readXmlToDocument(final String xmlContent) throws SAXException, IOException { diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/XmlStreamUtilsTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/XmlStreamUtilsTest.java index 32965e2dcc..b116753856 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/XmlStreamUtilsTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/XmlStreamUtilsTest.java @@ -59,7 +59,7 @@ public class XmlStreamUtilsTest { @BeforeClass public static void initialize() throws URISyntaxException, FileNotFoundException, ReactorException { final File file = new File(XmlStreamUtils.class.getResource("/leafref-test.yang").toURI()); - schemaContext = YangParserTestUtils.parseYangSources(file); + schemaContext = YangParserTestUtils.parseYangFiles(file); assertNotNull(schemaContext); assertEquals(1, schemaContext.getModules().size()); leafRefModule = schemaContext.getModules().iterator().next(); diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/StringPatternCheckingCodecTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/StringPatternCheckingCodecTest.java index 19e53794c8..322de0e655 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/StringPatternCheckingCodecTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/StringPatternCheckingCodecTest.java @@ -39,7 +39,7 @@ public class StringPatternCheckingCodecTest { @Test public void testStringPatternCheckingCodec() throws ReactorException, ParseException, URISyntaxException, FileNotFoundException { - final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/string-pattern-checking-codec-test.yang"); + final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/string-pattern-checking-codec-test.yang"); assertNotNull(schemaContext); final QNameModule testModuleQName = QNameModule.create(new URI("string-pattern-checking-codec-test"), diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/Bug7844Test.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/Bug7844Test.java index 1736e27360..96a8475bd9 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/Bug7844Test.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/Bug7844Test.java @@ -30,7 +30,7 @@ public class Bug7844Test { @Test public void test() throws Exception { - final SchemaContext context = YangParserTestUtils.parseYangSources("/bug7844"); + final SchemaContext context = YangParserTestUtils.parseYangResourceDirectory("/bug7844"); assertNotNull(context); final LeafRefContext leafRefContext = LeafRefContext.create(context); diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/Bug8713Test.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/Bug8713Test.java index e32335f80e..24163dadef 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/Bug8713Test.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/Bug8713Test.java @@ -31,7 +31,7 @@ public class Bug8713Test { @Test public void dataTreeCanditateValidationTest() throws Exception { - final SchemaContext context = YangParserTestUtils.parseYangSources("/bug8713/"); + final SchemaContext context = YangParserTestUtils.parseYangResourceDirectory("/bug8713/"); final LeafRefContext rootLeafRefContext = LeafRefContext.create(context); final TipProducingDataTree inMemoryDataTree = InMemoryDataTreeFactory.getInstance() .create(DataTreeConfiguration.DEFAULT_OPERATIONAL); @@ -49,7 +49,7 @@ public class Bug8713Test { inMemoryDataTree.commit(writeContributorsCandidate); } - private ContainerNode createRootContainer() { + private static ContainerNode createRootContainer() { return Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(foo("root"))) .withChild(ImmutableNodes.leafNode(bar("target"), "target value")) .withChild(ImmutableNodes.leafNode(bar("ref"), "target value")).build(); diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/DataTreeCandidateValidatorTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/DataTreeCandidateValidatorTest.java index ac6a35f389..d2663b1de9 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/DataTreeCandidateValidatorTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/DataTreeCandidateValidatorTest.java @@ -9,10 +9,9 @@ package org.opendaylight.yangtools.yang.data.impl.leafref.context; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import java.io.File; + import java.io.FileNotFoundException; import java.net.URISyntaxException; -import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -115,15 +114,8 @@ public class DataTreeCandidateValidatorTest { } - private static void initSchemaContext() throws URISyntaxException, - FileNotFoundException, ReactorException { - final File resourceFile = new File(DataTreeCandidateValidatorTest.class - .getResource("/leafref-validation/leafref-validation.yang") - .toURI()); - final File resourceDir = resourceFile.getParentFile(); - - context = YangParserTestUtils.parseYangSources(Arrays.asList(resourceDir - .listFiles())); + private static void initSchemaContext() { + context = YangParserTestUtils.parseYangResourceDirectory("/leafref-validation"); final Set modules = context.getModules(); for (final Module module : modules) { diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/DataTreeCandidateValidatorTest2.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/DataTreeCandidateValidatorTest2.java index 9f0f0b3136..a81594812d 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/DataTreeCandidateValidatorTest2.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/DataTreeCandidateValidatorTest2.java @@ -9,10 +9,9 @@ package org.opendaylight.yangtools.yang.data.impl.leafref.context; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import java.io.File; + import java.io.FileNotFoundException; import java.net.URISyntaxException; -import java.util.Arrays; import java.util.Set; import org.apache.log4j.BasicConfigurator; import org.junit.BeforeClass; @@ -153,13 +152,8 @@ public class DataTreeCandidateValidatorTest2 { desc = QName.create(rootModuleQname, "desc"); } - private static void initSchemaContext() throws URISyntaxException, FileNotFoundException, ReactorException { - - final File resourceFile = new File(DataTreeCandidateValidatorTest.class.getResource( - "/leafref-validation/leafref-validation2.yang").toURI()); - final File resourceDir = resourceFile.getParentFile(); - - context = YangParserTestUtils.parseYangSources(Arrays.asList(resourceDir.listFiles())); + private static void initSchemaContext() { + context = YangParserTestUtils.parseYangResourceDirectory("/leafref-validation"); final Set modules = context.getModules(); for (final Module module : modules) { diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/DataTreeCandidateValidatorTest3.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/DataTreeCandidateValidatorTest3.java index 7aca4447d2..736b889395 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/DataTreeCandidateValidatorTest3.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/DataTreeCandidateValidatorTest3.java @@ -9,10 +9,7 @@ package org.opendaylight.yangtools.yang.data.impl.leafref.context; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import java.io.File; -import java.io.FileNotFoundException; -import java.net.URISyntaxException; -import java.util.Arrays; + import java.util.Set; import org.apache.log4j.BasicConfigurator; import org.junit.BeforeClass; @@ -42,7 +39,6 @@ import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -84,8 +80,7 @@ public class DataTreeCandidateValidatorTest3 { } @BeforeClass - public static void init() throws FileNotFoundException, ReactorException, URISyntaxException { - + public static void init() { initSchemaContext(); initLeafRefContext(); initQnames(); @@ -200,13 +195,8 @@ public class DataTreeCandidateValidatorTest3 { desc = QName.create(rootModuleQname, "desc"); } - private static void initSchemaContext() throws URISyntaxException, FileNotFoundException, ReactorException { - - final File resourceFile = new File(DataTreeCandidateValidatorTest.class.getResource( - "/leafref-validation/leafref-validation3.yang").toURI()); - final File resourceDir = resourceFile.getParentFile(); - - context = YangParserTestUtils.parseYangSources(Arrays.asList(resourceDir.listFiles())); + private static void initSchemaContext() { + context = YangParserTestUtils.parseYangResourceDirectory("/leafref-validation"); final Set modules = context.getModules(); for (final Module module : modules) { diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/LeafRefContextTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/LeafRefContextTest.java index 35c3bc4493..b76940c5ae 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/LeafRefContextTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/LeafRefContextTest.java @@ -10,10 +10,7 @@ package org.opendaylight.yangtools.yang.data.impl.leafref.context; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import java.io.File; -import java.io.FileNotFoundException; -import java.net.URISyntaxException; -import java.util.Arrays; + import java.util.Map; import java.util.Set; import org.junit.BeforeClass; @@ -26,7 +23,6 @@ import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; public class LeafRefContextTest { @@ -37,14 +33,8 @@ public class LeafRefContextTest { private static LeafRefContext rootLeafRefContext; @BeforeClass - public static void init() throws URISyntaxException, FileNotFoundException, ReactorException { - - final File resourceFile = new File(LeafRefContextTreeBuilderTest.class.getResource( - "/leafref-context-test/correct-modules/leafref-test2.yang").toURI()); - - final File resourceDir = resourceFile.getParentFile(); - - context = YangParserTestUtils.parseYangSources(Arrays.asList(resourceDir.listFiles())); + public static void init() { + context = YangParserTestUtils.parseYangResourceDirectory("/leafref-context-test/correct-modules"); final Set modules = context.getModules(); for (final Module module : modules) { diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/LeafRefContextTreeBuilderTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/LeafRefContextTreeBuilderTest.java index 9fb1add6bc..7252e3b01b 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/LeafRefContextTreeBuilderTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/leafref/context/LeafRefContextTreeBuilderTest.java @@ -12,10 +12,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import java.io.File; -import java.io.FileNotFoundException; -import java.net.URISyntaxException; -import java.util.Arrays; + import java.util.List; import java.util.Set; import org.junit.BeforeClass; @@ -29,7 +26,6 @@ import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; public class LeafRefContextTreeBuilderTest { @@ -42,12 +38,8 @@ public class LeafRefContextTreeBuilderTest { private static LeafRefContext rootLeafRefContext; @BeforeClass - public static void init() throws URISyntaxException, FileNotFoundException, ReactorException { - final File resourceFile = new File(LeafRefContextTreeBuilderTest.class.getResource( - "/leafref-context-test/correct-modules/leafref-test.yang").toURI()); - final File resourceDir = resourceFile.getParentFile(); - - context = YangParserTestUtils.parseYangSources(Arrays.asList(resourceDir.listFiles())); + public static void init() { + context = YangParserTestUtils.parseYangResourceDirectory("/leafref-context-test/correct-modules"); final Set modules = context.getModules(); for (final Module module : modules) { @@ -239,15 +231,10 @@ public class LeafRefContextTreeBuilderTest { @Test(expected = IllegalArgumentException.class) @Ignore - public void incorrectLeafRefPathTest() throws URISyntaxException, FileNotFoundException, ReactorException { - final File resourceFile = new File(getClass().getResource( - "/leafref-context-test/incorrect-modules/leafref-test.yang").toURI()); - final File resourceDir = resourceFile.getParentFile(); - - final SchemaContext context = YangParserTestUtils.parseYangSources(Arrays.asList(resourceDir.listFiles())); - + public void incorrectLeafRefPathTest() { + final SchemaContext context = YangParserTestUtils.parseYangResourceDirectory( + "/leafref-context-test/incorrect-modules"); LeafRefContext.create(context); - } } diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/BuilderTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/BuilderTest.java index e4ede1f76e..864ecd8d85 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/BuilderTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/BuilderTest.java @@ -93,7 +93,7 @@ public class BuilderTest { public void setup() throws FileNotFoundException, ReactorException, URISyntaxException { final File leafRefTestYang = new File(getClass().getResource("/builder-test/immutable-ordered-map-node.yang") .toURI()); - final SchemaContext schema = YangParserTestUtils.parseYangSources(leafRefTestYang); + final SchemaContext schema = YangParserTestUtils.parseYangFiles(leafRefTestYang); final Module module = schema.getModules().iterator().next(); final DataSchemaNode root = module.getDataChildByName(ROOT_CONTAINER); list = (ListSchemaNode)((ContainerEffectiveStatementImpl) root).getDataChildByName(LIST_MAIN); diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToNodesTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToNodesTest.java index c362d44d3b..24081209be 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToNodesTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToNodesTest.java @@ -8,8 +8,8 @@ package org.opendaylight.yangtools.yang.data.impl.schema; import static org.junit.Assert.assertEquals; -import java.io.File; -import java.io.FileNotFoundException; + +import java.io.IOException; import java.net.URISyntaxException; import java.util.Collections; import org.junit.BeforeClass; @@ -26,6 +26,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.MapNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; @@ -53,9 +54,9 @@ public class InstanceIdToNodesTest { private final NodeWithValue leafListWithValue = new NodeWithValue<>( leafList.getNodeType(), "abcd"); - static SchemaContext createTestContext() throws URISyntaxException, FileNotFoundException, ReactorException { - final File resourceFile = new File(InstanceIdToNodesTest.class.getResource("/filter-test.yang").toURI()); - return YangParserTestUtils.parseYangSources(resourceFile); + static SchemaContext createTestContext() throws URISyntaxException, ReactorException, IOException, + YangSyntaxErrorException { + return YangParserTestUtils.parseYangResources(InstanceIdToNodesTest.class, "/filter-test.yang"); } @BeforeClass diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/NormalizedDataBuilderTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/NormalizedDataBuilderTest.java index e7799ba4a1..6c3dc7f56b 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/NormalizedDataBuilderTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/NormalizedDataBuilderTest.java @@ -55,7 +55,7 @@ public class NormalizedDataBuilderTest { public void setUp() throws URISyntaxException, FileNotFoundException, ReactorException { final File resourceFile = new File(getClass().getResource( "test.yang").toURI()); - schema = YangParserTestUtils.parseYangSources(resourceFile); + schema = YangParserTestUtils.parseYangFiles(resourceFile); containerNode = (ContainerSchemaNode) getSchemaNode(schema, "test", "container"); } diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/SchemaOrderedNormalizedNodeWriterTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/SchemaOrderedNormalizedNodeWriterTest.java index 4b5e7ba2ea..982be2afc3 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/SchemaOrderedNormalizedNodeWriterTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/SchemaOrderedNormalizedNodeWriterTest.java @@ -155,7 +155,7 @@ public class SchemaOrderedNormalizedNodeWriterTest { private static SchemaContext getSchemaContext(final String filePath) throws URISyntaxException, ReactorException, FileNotFoundException { - return YangParserTestUtils.parseYangSource(filePath); + return YangParserTestUtils.parseYangResource(filePath); } private static YangInstanceIdentifier.NodeIdentifier getNodeIdentifier(final String ns, final String name) { diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/SchemaUtilsTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/SchemaUtilsTest.java index 7fb8e4aebb..9358db5866 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/SchemaUtilsTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/SchemaUtilsTest.java @@ -28,7 +28,7 @@ public class SchemaUtilsTest { @Test public void test() throws Exception { - final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/schema-utils-test/foo.yang"); + final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/schema-utils-test/foo.yang"); assertTrue(SchemaUtils.findDataParentSchemaOnPath(schemaContext, SchemaPath.create(true, qN("my-name"), qN("my-name"))) instanceof ContainerSchemaNode); assertTrue(SchemaUtils.findDataParentSchemaOnPath(schemaContext, @@ -40,7 +40,7 @@ public class SchemaUtilsTest { @Test public void testNameConflicts() throws Exception { final SchemaContext schemaContext = YangParserTestUtils - .parseYangSource("/schema-utils-test/name-conflicts.yang"); + .parseYangResource("/schema-utils-test/name-conflicts.yang"); // test my-name conflicts assertEquals(8, SchemaUtils.findParentSchemaNodesOnPath(schemaContext, SchemaPath.create(true, qN("my-name"), qN("my-name"), qN("my-name"))).size()); diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/parser/DomToNormalizedNodeParserFactoryTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/parser/DomToNormalizedNodeParserFactoryTest.java index 0891f9b43d..4e6387d5f2 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/parser/DomToNormalizedNodeParserFactoryTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/parser/DomToNormalizedNodeParserFactoryTest.java @@ -30,7 +30,7 @@ public class DomToNormalizedNodeParserFactoryTest { @Test public void testFactoryInstantiation() throws ReactorException, FileNotFoundException, URISyntaxException { - SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/foo.yang"); + SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/foo.yang"); DomToNormalizedNodeParserFactory factory = DomToNormalizedNodeParserFactory.getInstance( DomUtils.defaultValueCodecProvider(), schemaContext, diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/Bug5396.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/Bug5396.java index 83a09a8f3c..04dffb88fa 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/Bug5396.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/Bug5396.java @@ -56,7 +56,7 @@ public class Bug5396 { .parse("2016-03-22")); root = QName.create(fooModuleQName, "root"); schemaContext = YangParserTestUtils - .parseYangSources(new File(getClass().getResource("/bug5396/yang/foo.yang").toURI())); + .parseYangFiles(new File(getClass().getResource("/bug5396/yang/foo.yang").toURI())); } @Test diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/Bug5446Test.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/Bug5446Test.java index 748bfddf54..0cad600660 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/Bug5446Test.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/Bug5446Test.java @@ -70,7 +70,7 @@ public class Bug5446Test extends XMLTestCase { rootQName = QName.create(fooModuleQName, "root"); ipAddressQName = QName.create(fooModuleQName, "ip-address"); - schemaContext = YangParserTestUtils.parseYangSources(new File(getClass().getResource("/bug5446/yang/foo.yang").toURI())); + schemaContext = YangParserTestUtils.parseYangFiles(new File(getClass().getResource("/bug5446/yang/foo.yang").toURI())); } @Test diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/Bug6392Test.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/Bug6392Test.java index 12935833a7..dbefd0f9c2 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/Bug6392Test.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/Bug6392Test.java @@ -46,7 +46,7 @@ public class Bug6392Test { @Test public void testLenientParsingOfUnkeyedListEntries() throws Exception { - final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/bug6392/foo.yang"); + final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/bug6392/foo.yang"); assertNotNull(schemaContext); final Date revision = SimpleDateFormatUtil.getRevisionFormat().parse("2017-03-10"); diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/DomSerializerTestUtils.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/DomSerializerTestUtils.java index ad46a7891d..2c4c46e570 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/DomSerializerTestUtils.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/DomSerializerTestUtils.java @@ -49,7 +49,7 @@ public class DomSerializerTestUtils { public static SchemaContext getSchemaContext() throws ReactorException, IOException, YangSyntaxErrorException, URISyntaxException { - final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/dom-serializer-test/serializer-test.yang"); + final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/dom-serializer-test/serializer-test.yang"); assertNotNull("Schema context must not be null.", schemaContext); return schemaContext; diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/NormalizedNodeXmlTranslationTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/NormalizedNodeXmlTranslationTest.java index 0ff7aeda25..ca738c644c 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/NormalizedNodeXmlTranslationTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/NormalizedNodeXmlTranslationTest.java @@ -13,8 +13,6 @@ import static org.opendaylight.yangtools.yang.data.impl.schema.Builders.containe import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.leafNode; import com.google.common.base.Preconditions; -import com.google.common.collect.Collections2; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import java.io.IOException; import java.io.InputStream; @@ -27,7 +25,6 @@ import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.HashSet; -import java.util.List; import java.util.Map; import java.util.Set; import javax.xml.stream.XMLOutputFactory; @@ -74,7 +71,6 @@ import org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.parser.Dom import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.SchemaPath; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -251,8 +247,8 @@ public class NormalizedNodeXmlTranslationTest { } public NormalizedNodeXmlTranslationTest(final String yangPath, final String xmlPath, - final ContainerNode expectedNode) throws ReactorException { - schema = parseTestSchema(yangPath); + final ContainerNode expectedNode) { + schema = YangParserTestUtils.parseYangResources(NormalizedDataBuilderTest.class, yangPath); this.xmlPath = xmlPath; this.containerNode = (ContainerSchemaNode) NormalizedDataBuilderTest.getSchemaNode(schema, "test", "container"); this.expectedNode = expectedNode; @@ -262,19 +258,6 @@ public class NormalizedNodeXmlTranslationTest { private final ContainerSchemaNode containerNode; private final String xmlPath; - SchemaContext parseTestSchema(final String... yangPath) throws ReactorException { - return YangParserTestUtils.parseYangStreams(getTestYangs(yangPath)); - } - - List getTestYangs(final String... yangPaths) { - return ImmutableList.copyOf(Collections2.transform(Arrays.asList(yangPaths), - input -> { - final InputStream resourceAsStream = NormalizedDataBuilderTest.class.getResourceAsStream(input); - Preconditions.checkNotNull(resourceAsStream, "File %s was null", resourceAsStream); - return resourceAsStream; - })); - } - @Test public void testTranslation() throws Exception { final Document doc = loadDocument(xmlPath); diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/YangModeledAnyXMLDeserializationTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/YangModeledAnyXMLDeserializationTest.java index ba3a26bce9..0e79aed76b 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/YangModeledAnyXMLDeserializationTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/YangModeledAnyXMLDeserializationTest.java @@ -82,7 +82,7 @@ public class YangModeledAnyXMLDeserializationTest { myLeaf3 = QName.create(fooModuleQName, "my-leaf-3"); myLeaf2 = QName.create(fooModuleQName, "my-leaf-2"); myAnyXMLDataFoo = QName.create(fooModuleQName, "my-anyxml-data"); - schemaContext = YangParserTestUtils.parseYangSources("/anyxml-support/yang"); + schemaContext = YangParserTestUtils.parseYangResourceDirectory("/anyxml-support/yang"); } @Test diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/YangModeledAnyXMLSerializationTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/YangModeledAnyXMLSerializationTest.java index 3aadcd16f2..24fca2453f 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/YangModeledAnyXMLSerializationTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/YangModeledAnyXMLSerializationTest.java @@ -76,7 +76,7 @@ public class YangModeledAnyXMLSerializationTest extends XMLTestCase { myContainer2QName = QName.create(bazModuleQName, "my-container-2"); myAnyXMLDataBaz = QName.create(bazModuleQName, "my-anyxml-data"); - schemaContext = YangParserTestUtils.parseYangSources("/anyxml-support/serialization"); + schemaContext = YangParserTestUtils.parseYangResourceDirectory("/anyxml-support/serialization"); } @Test diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Bug2690Test.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Bug2690Test.java index 1177d49897..16af3c2517 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Bug2690Test.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Bug2690Test.java @@ -11,9 +11,8 @@ package org.opendaylight.yangtools.yang.data.impl.schema.tree; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; + import com.google.common.base.Optional; -import java.io.InputStream; -import java.util.Collections; import org.junit.Before; import org.junit.Test; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; @@ -44,16 +43,8 @@ public class Bug2690Test { inMemoryDataTree.setSchemaContext(schemaContext); } - public static InputStream getDatastoreTestInputStream() { - return getInputStream(ODL_DATASTORE_TEST_YANG); - } - - private static InputStream getInputStream(final String resourceName) { - return TestModel.class.getResourceAsStream(ODL_DATASTORE_TEST_YANG); - } - public static SchemaContext createTestContext() throws ReactorException { - return YangParserTestUtils.parseYangStreams(Collections.singletonList(getDatastoreTestInputStream())); + return YangParserTestUtils.parseYangResource(ODL_DATASTORE_TEST_YANG); } @Test @@ -89,7 +80,5 @@ public class Bug2690Test { final Optional> readNode = modificationAfterTx.readNode(TestModel.OUTER_LIST_PATH); assertTrue(readNode.isPresent()); assertEquals(2, ((NormalizedNodeContainer)readNode.get()).getValue().size()); - } - } diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Bug3674Test.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Bug3674Test.java index 479f7658f3..8769d23659 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Bug3674Test.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Bug3674Test.java @@ -8,6 +8,8 @@ package org.opendaylight.yangtools.yang.data.impl.schema.tree; import static org.junit.Assert.assertEquals; + +import java.io.IOException; import org.junit.Before; import org.junit.Test; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree; @@ -17,6 +19,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType; import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; +import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; /** @@ -28,7 +31,7 @@ public class Bug3674Test { private DataTree tree; @Before - public void setUp() throws ReactorException { + public void setUp() throws ReactorException, IOException, YangSyntaxErrorException { tree = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL); tree.setSchemaContext(TestModel.createTestContext()); diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Bug4295Test.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Bug4295Test.java index 4801cb79de..2751882a45 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Bug4295Test.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Bug4295Test.java @@ -51,7 +51,7 @@ public class Bug4295Test { public void init() throws Exception { final File resourceFile = new File(Bug4295Test.class.getResource("/bug-4295/foo.yang") .toURI()); - context = YangParserTestUtils.parseYangSources(resourceFile); + context = YangParserTestUtils.parseYangFiles(resourceFile); foo = QNameModule.create(new URI("foo"), SimpleDateFormatUtil.getRevisionFormat().parse("1970-01-01")); root = QName.create(foo, "root"); subRoot = QName.create(foo, "sub-root"); diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Bug4454Test.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Bug4454Test.java index 6d5d808919..5313144dd0 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Bug4454Test.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Bug4454Test.java @@ -122,7 +122,7 @@ public class Bug4454Test { public static SchemaContext createTestContext() throws IOException, YangSyntaxErrorException, ReactorException, URISyntaxException { - return YangParserTestUtils.parseYangSource("/bug-4454-test.yang"); + return YangParserTestUtils.parseYangResource("/bug-4454-test.yang"); } @Test diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Bug5830Test.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Bug5830Test.java index 8d956a363b..f16bdc5630 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Bug5830Test.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Bug5830Test.java @@ -205,7 +205,7 @@ public class Bug5830Test { inMemoryDataTree.commit(prepare); } - private static void testMandatoryLeaf2IsPresent(final SchemaContext schemaContext, boolean withPresenceContianer) + private static void testMandatoryLeaf2IsPresent(final SchemaContext schemaContext, final boolean withPresenceContianer) throws DataValidationFailedException { final InMemoryDataTree inMemoryDataTree = initDataTree(schemaContext); @@ -226,7 +226,7 @@ public class Bug5830Test { inMemoryDataTree.commit(prepare); } - private static DataContainerChild createTaskDataContainer(boolean withMandatoryNode) { + private static DataContainerChild createTaskDataContainer(final boolean withMandatoryNode) { DataContainerNodeAttrBuilder taskDataBuilder = Builders.containerBuilder() .withNodeIdentifier(new NodeIdentifier(TASK_DATA)) .withChild(ImmutableNodes.leafNode(OTHER_DATA, "foo")); @@ -236,7 +236,7 @@ public class Bug5830Test { return taskDataBuilder.build(); } - private static DataContainerChild createTaskDataMultipleContainer(boolean withPresenceContianer) { + private static DataContainerChild createTaskDataMultipleContainer(final boolean withPresenceContianer) { DataContainerNodeAttrBuilder nonPresenceContainerBuilder = Builders .containerBuilder() .withNodeIdentifier(new NodeIdentifier(NON_PRESENCE_CONTAINER)) diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/DataTreeCandidatesTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/DataTreeCandidatesTest.java index c1ccfebfcb..e3160a839c 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/DataTreeCandidatesTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/DataTreeCandidatesTest.java @@ -26,7 +26,6 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafNodeBuilder; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,15 +33,7 @@ public class DataTreeCandidatesTest { private static final Logger LOG = LoggerFactory.getLogger(DataTreeCandidates.class); - private static final SchemaContext SCHEMA_CONTEXT; - - static { - try { - SCHEMA_CONTEXT = TestModel.createTestContext(); - } catch (ReactorException e) { - throw new ExceptionInInitializerError(e); - } - } + private static final SchemaContext SCHEMA_CONTEXT = TestModel.createTestContext(); private DataTree dataTree; diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ListConstraintsValidation.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ListConstraintsValidation.java index 244fda31c5..539e90f84d 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ListConstraintsValidation.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ListConstraintsValidation.java @@ -9,10 +9,9 @@ package org.opendaylight.yangtools.yang.data.impl.schema.tree; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; + import com.google.common.base.Optional; -import java.io.InputStream; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import org.junit.Before; import org.junit.Test; @@ -38,7 +37,6 @@ import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLe import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUnkeyedListEntryNodeBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUnkeyedListNodeBuilder; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -77,7 +75,7 @@ public class ListConstraintsValidation { .builder(MASTER_CONTAINER_PATH).node(UNKEYED_LIST_QNAME).build(); @Before - public void prepare() throws ReactorException { + public void prepare() { schemaContext = createTestContext(); assertNotNull("Schema context must not be null.", schemaContext); inMemoryDataTree = (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL); @@ -90,16 +88,8 @@ public class ListConstraintsValidation { inMemoryDataTree.commit(inMemoryDataTree.prepare(modificationTree)); } - public static InputStream getDatastoreTestInputStream() { - return getInputStream(CONSTRAINTS_VALIDATION_TEST_YANG); - } - - private static InputStream getInputStream(final String resourceName) { - return TestModel.class.getResourceAsStream(CONSTRAINTS_VALIDATION_TEST_YANG); - } - - public static SchemaContext createTestContext() throws ReactorException { - return YangParserTestUtils.parseYangStreams(Collections.singletonList(getDatastoreTestInputStream())); + public static SchemaContext createTestContext() { + return YangParserTestUtils.parseYangResource(CONSTRAINTS_VALIDATION_TEST_YANG); } @Test diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/OrderedListTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/OrderedListTest.java index b6bf61b7b2..8ac4fe86bb 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/OrderedListTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/OrderedListTest.java @@ -60,7 +60,7 @@ public class OrderedListTest { public void setup() throws Exception { final File resourceFile = new File(Bug4295Test.class.getResource("/ordered-list-modification-test.yang") .toURI()); - context = YangParserTestUtils.parseYangSources(resourceFile); + context = YangParserTestUtils.parseYangFiles(resourceFile); testModule = QNameModule.create(new URI("ordered-list-modification-test"), SimpleDateFormatUtil.getRevisionFormat().parse("1970-01-01")); parentContainer = QName.create(testModule, "parent-container"); diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/TestModel.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/TestModel.java index 669f46cbcc..b325136f39 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/TestModel.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/TestModel.java @@ -7,14 +7,9 @@ */ package org.opendaylight.yangtools.yang.data.impl.schema.tree; -import java.io.InputStream; -import java.util.Arrays; -import java.util.Collections; - import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; public class TestModel { @@ -39,16 +34,11 @@ public class TestModel { public static final QName TWO_QNAME = QName.create(TEST_QNAME, "two"); public static final QName THREE_QNAME = QName.create(TEST_QNAME, "three"); - public static InputStream getDatastoreTestInputStream() { - return TestModel.class.getResourceAsStream(DATASTORE_TEST_YANG); - } - - public static SchemaContext createTestContext() throws ReactorException { - return YangParserTestUtils.parseYangStreams(Arrays.asList(getDatastoreTestInputStream())); + public static SchemaContext createTestContext() { + return createTestContext(DATASTORE_TEST_YANG); } - public static SchemaContext createTestContext(String resourcePath) throws ReactorException { - InputStream yangStream = TestModel.class.getResourceAsStream(resourcePath); - return YangParserTestUtils.parseYangStreams(Collections.singletonList(yangStream)); + public static SchemaContext createTestContext(final String resourcePath) { + return YangParserTestUtils.parseYangResources(TestModel.class, resourcePath); } } diff --git a/yang/yang-data-jaxen/src/test/java/org/opendaylight/yangtools/yang/data/jaxen/BitIsSetXPathFunctionTest.java b/yang/yang-data-jaxen/src/test/java/org/opendaylight/yangtools/yang/data/jaxen/BitIsSetXPathFunctionTest.java index 687472518d..d1c61840f3 100644 --- a/yang/yang-data-jaxen/src/test/java/org/opendaylight/yangtools/yang/data/jaxen/BitIsSetXPathFunctionTest.java +++ b/yang/yang-data-jaxen/src/test/java/org/opendaylight/yangtools/yang/data/jaxen/BitIsSetXPathFunctionTest.java @@ -70,7 +70,7 @@ public class BitIsSetXPathFunctionTest { public void testBitIsSetFunction() throws Exception { final Set setOfBits = ImmutableSet.of("UP", "PROMISCUOUS"); - final SchemaContext schemaContext = YangParserTestUtils.parseYangSource( + final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(BitIsSetXPathFunctionTest.class, "/yang-xpath-functions-test/bit-is-set-function/foo.yang"); assertNotNull(schemaContext); @@ -100,7 +100,7 @@ public class BitIsSetXPathFunctionTest { public void testInvalidTypeOfCorrespondingSchemaNode() throws Exception { final Set setOfBits = ImmutableSet.of("UP", "PROMISCUOUS"); - final SchemaContext schemaContext = YangParserTestUtils.parseYangSource( + final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(BitIsSetXPathFunctionTest.class, "/yang-xpath-functions-test/bit-is-set-function/foo-invalid.yang"); assertNotNull(schemaContext); @@ -126,7 +126,7 @@ public class BitIsSetXPathFunctionTest { public void testInvalidNormalizedNodeValueType() throws Exception { final String invalidNodeValueType = "value of invalid type"; - final SchemaContext schemaContext = YangParserTestUtils.parseYangSource( + final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(BitIsSetXPathFunctionTest.class, "/yang-xpath-functions-test/bit-is-set-function/foo.yang"); assertNotNull(schemaContext); @@ -153,7 +153,7 @@ public class BitIsSetXPathFunctionTest { public void shouldFailOnUnknownBitArgument() throws Exception { final Set setOfBits = ImmutableSet.of("UP", "PROMISCUOUS"); - final SchemaContext schemaContext = YangParserTestUtils.parseYangSource( + final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(BitIsSetXPathFunctionTest.class, "/yang-xpath-functions-test/bit-is-set-function/foo.yang"); assertNotNull(schemaContext); diff --git a/yang/yang-data-jaxen/src/test/java/org/opendaylight/yangtools/yang/data/jaxen/DerefXPathFunctionTest.java b/yang/yang-data-jaxen/src/test/java/org/opendaylight/yangtools/yang/data/jaxen/DerefXPathFunctionTest.java index 507b522b91..4ec1e25a34 100644 --- a/yang/yang-data-jaxen/src/test/java/org/opendaylight/yangtools/yang/data/jaxen/DerefXPathFunctionTest.java +++ b/yang/yang-data-jaxen/src/test/java/org/opendaylight/yangtools/yang/data/jaxen/DerefXPathFunctionTest.java @@ -84,7 +84,7 @@ public class DerefXPathFunctionTest { @Test public void testDerefFunctionForInstanceIdentifier() throws Exception { - final SchemaContext schemaContext = YangParserTestUtils.parseYangSource( + final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(DerefXPathFunctionTest.class, "/yang-xpath-functions-test/deref-function-iid/foo.yang"); assertNotNull(schemaContext); @@ -116,7 +116,7 @@ public class DerefXPathFunctionTest { @Test public void testDerefFunctionForLeafref() throws Exception { // tests absolute and relative leafref that references a leaf node - final SchemaContext schemaContext = YangParserTestUtils.parseYangSource( + final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(DerefXPathFunctionTest.class, "/yang-xpath-functions-test/deref-function-leafref/foo.yang"); assertNotNull(schemaContext); @@ -156,7 +156,7 @@ public class DerefXPathFunctionTest { @Test public void testDerefFunctionForLeafref2() throws Exception { // tests leafref that references a leaf-list node - final SchemaContext schemaContext = YangParserTestUtils.parseYangSource( + final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(DerefXPathFunctionTest.class, "/yang-xpath-functions-test/deref-function-leafref/foo.yang"); assertNotNull(schemaContext); diff --git a/yang/yang-data-jaxen/src/test/java/org/opendaylight/yangtools/yang/data/jaxen/DerivedFromXPathFunctionTest.java b/yang/yang-data-jaxen/src/test/java/org/opendaylight/yangtools/yang/data/jaxen/DerivedFromXPathFunctionTest.java index b53de5aae1..7598cc3cb2 100644 --- a/yang/yang-data-jaxen/src/test/java/org/opendaylight/yangtools/yang/data/jaxen/DerivedFromXPathFunctionTest.java +++ b/yang/yang-data-jaxen/src/test/java/org/opendaylight/yangtools/yang/data/jaxen/DerivedFromXPathFunctionTest.java @@ -69,9 +69,9 @@ public class DerivedFromXPathFunctionTest { @Test public void testDerivedFromFunction() throws Exception { // also includes test for derived-from-or-self function - final SchemaContext schemaContext = YangParserTestUtils.parseYangSources(ImmutableList.of( + final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(DerivedFromXPathFunctionTest.class, "/yang-xpath-functions-test/derived-from-function/foo.yang", - "/yang-xpath-functions-test/derived-from-function/bar.yang")); + "/yang-xpath-functions-test/derived-from-function/bar.yang"); assertNotNull(schemaContext); final XPathSchemaContext jaxenSchemaContext = jaxenSchemaContextFactory.createContext(schemaContext); @@ -108,7 +108,7 @@ public class DerivedFromXPathFunctionTest { @Test public void testInvalidTypeOfCorrespondingSchemaNode() throws Exception { - final SchemaContext schemaContext = YangParserTestUtils.parseYangSource( + final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(DerivedFromXPathFunctionTest.class, "/yang-xpath-functions-test/derived-from-function/bar-invalid.yang"); assertNotNull(schemaContext); @@ -132,9 +132,9 @@ public class DerivedFromXPathFunctionTest { @Test public void testInvalidNormalizedNodeValueType() throws Exception { - final SchemaContext schemaContext = YangParserTestUtils.parseYangSources(ImmutableList.of( + final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(DerivedFromXPathFunctionTest.class, "/yang-xpath-functions-test/derived-from-function/foo.yang", - "/yang-xpath-functions-test/derived-from-function/bar.yang")); + "/yang-xpath-functions-test/derived-from-function/bar.yang"); assertNotNull(schemaContext); final XPathSchemaContext jaxenSchemaContext = jaxenSchemaContextFactory.createContext(schemaContext); @@ -157,9 +157,9 @@ public class DerivedFromXPathFunctionTest { @Test public void shouldFailOnUnknownPrefixOfIdentity() throws Exception { - final SchemaContext schemaContext = YangParserTestUtils.parseYangSources(ImmutableList.of( + final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(DerivedFromXPathFunctionTest.class, "/yang-xpath-functions-test/derived-from-function/foo.yang", - "/yang-xpath-functions-test/derived-from-function/bar.yang")); + "/yang-xpath-functions-test/derived-from-function/bar.yang"); assertNotNull(schemaContext); final XPathSchemaContext jaxenSchemaContext = jaxenSchemaContextFactory.createContext(schemaContext); @@ -188,9 +188,9 @@ public class DerivedFromXPathFunctionTest { @Test public void shouldFailOnMalformedIdentityArgument() throws Exception { - final SchemaContext schemaContext = YangParserTestUtils.parseYangSources(ImmutableList.of( + final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(DerivedFromXPathFunctionTest.class, "/yang-xpath-functions-test/derived-from-function/foo.yang", - "/yang-xpath-functions-test/derived-from-function/bar.yang")); + "/yang-xpath-functions-test/derived-from-function/bar.yang"); assertNotNull(schemaContext); final XPathSchemaContext jaxenSchemaContext = jaxenSchemaContextFactory.createContext(schemaContext); @@ -218,9 +218,9 @@ public class DerivedFromXPathFunctionTest { @Test public void shouldFailOnUnknownIdentityArgument() throws Exception { - final SchemaContext schemaContext = YangParserTestUtils.parseYangSources(ImmutableList.of( + final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(DerivedFromXPathFunctionTest.class, "/yang-xpath-functions-test/derived-from-function/foo.yang", - "/yang-xpath-functions-test/derived-from-function/bar.yang")); + "/yang-xpath-functions-test/derived-from-function/bar.yang"); assertNotNull(schemaContext); final XPathSchemaContext jaxenSchemaContext = jaxenSchemaContextFactory.createContext(schemaContext); diff --git a/yang/yang-data-jaxen/src/test/java/org/opendaylight/yangtools/yang/data/jaxen/EnumValueXPathFunctionTest.java b/yang/yang-data-jaxen/src/test/java/org/opendaylight/yangtools/yang/data/jaxen/EnumValueXPathFunctionTest.java index 0e42f875e5..3a860d84b8 100644 --- a/yang/yang-data-jaxen/src/test/java/org/opendaylight/yangtools/yang/data/jaxen/EnumValueXPathFunctionTest.java +++ b/yang/yang-data-jaxen/src/test/java/org/opendaylight/yangtools/yang/data/jaxen/EnumValueXPathFunctionTest.java @@ -65,7 +65,7 @@ public class EnumValueXPathFunctionTest { @Test public void testEnumValueFunction() throws Exception { - final SchemaContext schemaContext = YangParserTestUtils.parseYangSource( + final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(EnumValueXPathFunctionTest.class, "/yang-xpath-functions-test/enum-value-function/foo.yang"); assertNotNull(schemaContext); @@ -89,7 +89,7 @@ public class EnumValueXPathFunctionTest { @Test public void testInvalidTypeOfCorrespondingSchemaNode() throws Exception { - final SchemaContext schemaContext = YangParserTestUtils.parseYangSource( + final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(EnumValueXPathFunctionTest.class, "/yang-xpath-functions-test/enum-value-function/foo-invalid.yang"); assertNotNull(schemaContext); @@ -113,7 +113,7 @@ public class EnumValueXPathFunctionTest { @Test public void testInvalidNormalizedNodeValueType() throws Exception { - final SchemaContext schemaContext = YangParserTestUtils.parseYangSource( + final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(EnumValueXPathFunctionTest.class, "/yang-xpath-functions-test/enum-value-function/foo.yang"); assertNotNull(schemaContext); @@ -137,7 +137,7 @@ public class EnumValueXPathFunctionTest { @Test public void shouldFailOnUnknownEnumNodeValue() throws Exception { - final SchemaContext schemaContext = YangParserTestUtils.parseYangSource( + final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(EnumValueXPathFunctionTest.class, "/yang-xpath-functions-test/enum-value-function/foo.yang"); assertNotNull(schemaContext); diff --git a/yang/yang-data-jaxen/src/test/java/org/opendaylight/yangtools/yang/data/jaxen/JaxenTest.java b/yang/yang-data-jaxen/src/test/java/org/opendaylight/yangtools/yang/data/jaxen/JaxenTest.java index d7c62fdd7b..1578c2cdff 100644 --- a/yang/yang-data-jaxen/src/test/java/org/opendaylight/yangtools/yang/data/jaxen/JaxenTest.java +++ b/yang/yang-data-jaxen/src/test/java/org/opendaylight/yangtools/yang/data/jaxen/JaxenTest.java @@ -212,7 +212,7 @@ public class JaxenTest { } private static SchemaContext createSchemaContext() throws IOException, URISyntaxException, ReactorException { - return YangParserTestUtils.parseYangSources("/test/documentTest"); + return YangParserTestUtils.parseYangResourceDirectory("/test/documentTest"); } private static NormalizedNode createNormalizedNodes() { diff --git a/yang/yang-maven-plugin/src/test/java/org/opendaylight/yangtools/yang2sources/plugin/UtilTest.java b/yang/yang-maven-plugin/src/test/java/org/opendaylight/yangtools/yang2sources/plugin/UtilTest.java index a6df5bdb25..088a440cec 100644 --- a/yang/yang-maven-plugin/src/test/java/org/opendaylight/yangtools/yang2sources/plugin/UtilTest.java +++ b/yang/yang-maven-plugin/src/test/java/org/opendaylight/yangtools/yang2sources/plugin/UtilTest.java @@ -134,9 +134,7 @@ public class UtilTest { @Test public void contextHolderTest() throws Exception { - final File testYang1 = new File(getClass().getResource("/test.yang").toURI()); - final File testYang2 = new File(getClass().getResource("/test2.yang").toURI()); - final SchemaContext context = YangParserTestUtils.parseYangSources(testYang1, testYang2); + final SchemaContext context = YangParserTestUtils.parseYangResources(getClass(), "/test.yang", "/test2.yang"); final Set yangModules = new HashSet<>(); final ContextHolder cxH = new ContextHolder(context, yangModules, ImmutableSet.of()); assertEquals(context, cxH.getContext()); diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaContext.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaContext.java index dbc2c8e17a..f56e67ef0d 100644 --- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaContext.java +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaContext.java @@ -80,6 +80,10 @@ public interface SchemaContext extends ContainerSchemaNode { */ Module findModuleByName(String name, Date revision); + default Optional findAnyModuleByName(final String name) { + return Optional.fromNullable(findModuleByName(name, null)); + } + /** * Returns module instance (from the context) with concrete namespace. * diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/ResourceYangTextSchemaSource.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/ResourceYangTextSchemaSource.java index 6e870689e6..a488c5731d 100644 --- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/ResourceYangTextSchemaSource.java +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/ResourceYangTextSchemaSource.java @@ -16,7 +16,7 @@ import java.util.Optional; import org.opendaylight.yangtools.concepts.Delegator; /** - * A resource-backed {@link YangTextSchemaSource}. + * A resource-backed {@link YinTextSchemaSource}. */ final class ResourceYangTextSchemaSource extends YangTextSchemaSource implements Delegator { private final URL url; diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/ResourceYinTextSchemaSource.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/ResourceYinTextSchemaSource.java new file mode 100644 index 0000000000..b548ebb73b --- /dev/null +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/ResourceYinTextSchemaSource.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * 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.model.repo.api; + +import com.google.common.base.MoreObjects.ToStringHelper; +import com.google.common.base.Preconditions; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.Optional; +import org.opendaylight.yangtools.concepts.Delegator; + +/** + * A resource-backed {@link YangTextSchemaSource}. + */ +final class ResourceYinTextSchemaSource extends YinTextSchemaSource implements Delegator { + private final URL url; + + ResourceYinTextSchemaSource(final SourceIdentifier identifier, final URL url) { + super(identifier); + this.url = Preconditions.checkNotNull(url); + } + + @Override + public URL getDelegate() { + return url; + } + + @Override + protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) { + return toStringHelper.add("url", url); + } + + @Override + public InputStream openStream() throws IOException { + return url.openStream(); + } + + @Override + public Optional getSymbolicName() { + return Optional.of(url.toString()); + } +} diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YangTextSchemaSource.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YangTextSchemaSource.java index 1b424c8714..24c921eb56 100644 --- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YangTextSchemaSource.java +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YangTextSchemaSource.java @@ -81,7 +81,7 @@ public abstract class YangTextSchemaSource extends ByteSource implements YangSch * @throws NullPointerException if file is null */ public static YangTextSchemaSource forFile(final File file) { - Preconditions.checkArgument(file.isFile(), "Supplied file %s is not a file"); + Preconditions.checkArgument(file.isFile(), "Supplied file %s is not a file", file); return new YangTextFileSchemaSource(identifierFromFilename(file.getName()), file); } diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YinTextFileSchemaSource.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YinTextFileSchemaSource.java new file mode 100644 index 0000000000..5beabfaa6b --- /dev/null +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YinTextFileSchemaSource.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2017 Pantheon Technologies, s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * 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.model.repo.api; + +import com.google.common.base.MoreObjects.ToStringHelper; +import com.google.common.base.Preconditions; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.util.Optional; +import org.opendaylight.yangtools.concepts.Delegator; + +/** + * A {@link YinTextSchemaSource} backed by a file. + * + * @author Robert Varga + */ +final class YinTextFileSchemaSource extends YinTextSchemaSource implements Delegator { + private final File file; + + YinTextFileSchemaSource(final SourceIdentifier identifier, final File file) { + super(identifier); + this.file = Preconditions.checkNotNull(file); + } + + @Override + public File getDelegate() { + return file; + } + + @Override + public InputStream openStream() throws IOException { + return Files.newInputStream(file.toPath()); + } + + @Override + protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) { + return toStringHelper.add("file", file); + } + + @Override + public Optional getSymbolicName() { + return Optional.of(file.toString()); + } +} diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YinTextSchemaSource.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YinTextSchemaSource.java index 0b64f6ef37..20ce3b6ff6 100644 --- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YinTextSchemaSource.java +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/YinTextSchemaSource.java @@ -13,8 +13,11 @@ import com.google.common.base.MoreObjects.ToStringHelper; import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.io.ByteSource; +import com.google.common.io.Resources; +import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.net.URL; import java.util.Map.Entry; import javax.annotation.Nonnull; import org.opendaylight.yangtools.concepts.Delegator; @@ -93,6 +96,18 @@ public abstract class YinTextSchemaSource extends ByteSource implements YinSchem return new DelegatedYinTextSchemaSource(identifier, delegate); } + public static YinTextSchemaSource forFile(final File file) { + Preconditions.checkArgument(file.isFile(), "Supplied file %s is not a file", file); + return new YinTextFileSchemaSource(identifierFromFilename(file.getName()), file); + } + + public static YinTextSchemaSource forResource(final Class clazz, final String resourceName) { + final String fileName = resourceName.substring(resourceName.lastIndexOf('/') + 1); + final SourceIdentifier identifier = identifierFromFilename(fileName); + final URL url = Resources.getResource(clazz, resourceName); + return new ResourceYinTextSchemaSource(identifier, url); + } + private static final class DelegatedYinTextSchemaSource extends YinTextSchemaSource implements Delegator { private final ByteSource delegate; diff --git a/yang/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/test/Bug2444Test.java b/yang/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/test/Bug2444Test.java index f629b96b97..c9bbcc6a3f 100644 --- a/yang/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/test/Bug2444Test.java +++ b/yang/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/test/Bug2444Test.java @@ -32,7 +32,7 @@ import org.xml.sax.SAXException; public class Bug2444Test { @Test public void test() throws Exception { - final SchemaContext schema = YangParserTestUtils.parseYangSources("/bugs/bug2444/yang"); + final SchemaContext schema = YangParserTestUtils.parseYangResourceDirectory("/bugs/bug2444/yang"); assertNotNull(schema); final File outDir = new File("target/bug2444-export"); diff --git a/yang/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/test/Bug4504Test.java b/yang/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/test/Bug4504Test.java index 72514b4e5a..c4d0a7b498 100644 --- a/yang/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/test/Bug4504Test.java +++ b/yang/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/test/Bug4504Test.java @@ -8,6 +8,7 @@ package org.opendaylight.yangtools.yang.model.export.test; import static org.junit.Assert.assertNotNull; + import java.io.File; import java.io.FileOutputStream; import java.io.OutputStream; @@ -20,7 +21,7 @@ import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; public class Bug4504Test { @Test public void test() throws Exception { - SchemaContext schema = YangParserTestUtils.parseYangSources("/bugs/bug4504"); + SchemaContext schema = YangParserTestUtils.parseYangResourceDirectory("/bugs/bug4504"); assertNotNull(schema); final File outDir = new File("target/bug4504-export"); outDir.mkdirs(); diff --git a/yang/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/test/Bug5531Test.java b/yang/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/test/Bug5531Test.java index 39e4eeba86..0f79efca0b 100644 --- a/yang/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/test/Bug5531Test.java +++ b/yang/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/test/Bug5531Test.java @@ -23,7 +23,7 @@ import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; public class Bug5531Test { @Test public void test() throws Exception { - SchemaContext schema = YangParserTestUtils.parseYangSources("/bugs/bug5531"); + SchemaContext schema = YangParserTestUtils.parseYangResourceDirectory("/bugs/bug5531"); assertNotNull(schema); assertNotNull(schema.getModules()); diff --git a/yang/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/test/Bug6856Test.java b/yang/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/test/Bug6856Test.java index 2b6cc409b2..1f56603869 100644 --- a/yang/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/test/Bug6856Test.java +++ b/yang/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/test/Bug6856Test.java @@ -27,7 +27,8 @@ public class Bug6856Test { @Test public void testImplicitInputAndOutputInRpc() throws Exception { - final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/bugs/bug6856/foo.yang"); + final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(Bug6856Test.class, + "/bugs/bug6856/foo.yang"); assertNotNull(schemaContext); final OutputStream byteArrayOutputStream = new ByteArrayOutputStream(); @@ -48,7 +49,8 @@ public class Bug6856Test { @Test public void testExplicitInputAndOutputInRpc() throws Exception { - final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/bugs/bug6856/bar.yang"); + final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(Bug6856Test.class, + "/bugs/bug6856/bar.yang"); assertNotNull(schemaContext); final OutputStream byteArrayOutputStream = new ByteArrayOutputStream(); diff --git a/yang/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/test/SchemaContextEmitterTest.java b/yang/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/test/SchemaContextEmitterTest.java index 1b421f793f..1ef59e0b9f 100644 --- a/yang/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/test/SchemaContextEmitterTest.java +++ b/yang/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/test/SchemaContextEmitterTest.java @@ -36,7 +36,8 @@ public class SchemaContextEmitterTest { @Test public void testSchemaContextEmitter() throws ReactorException, IOException, URISyntaxException, XMLStreamException, SAXException { - final SchemaContext schemaContext = YangParserTestUtils.parseYangSources("/schema-context-emitter-test"); + final SchemaContext schemaContext = YangParserTestUtils.parseYangResourceDirectory( + "/schema-context-emitter-test"); assertNotNull(schemaContext); assertEquals(1, schemaContext.getModules().size()); diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/util/YangModelDependencyInfo.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/util/YangModelDependencyInfo.java index c0cc5ba9d4..f8c6a229d3 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/util/YangModelDependencyInfo.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/util/YangModelDependencyInfo.java @@ -11,7 +11,7 @@ import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.base.Strings; import com.google.common.collect.ImmutableSet; -import java.io.InputStream; +import java.io.IOException; import java.util.Date; import java.util.HashSet; import java.util.Objects; @@ -24,12 +24,12 @@ import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.ModuleImport; import org.opendaylight.yangtools.yang.model.api.YangStmtMapping; import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException; +import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource; +import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YangStatementStreamSource; import org.opendaylight.yangtools.yang.parser.spi.source.DeclarationInTextSource; import org.opendaylight.yangtools.yang.parser.spi.source.StatementSourceReference; import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.SupportedExtensionsMapping; import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl; -import org.opendaylight.yangtools.yang.parser.util.NamedInputStream; /** * Helper transfer object which holds basic and dependency information for YANG @@ -204,13 +204,21 @@ public abstract class YangModelDependencyInfo { * Extracts {@link YangModelDependencyInfo} from input stream containing a YANG model. This parsing does not * validate full YANG module, only parses header up to the revisions and imports. * - * @param yangStream Opened Input stream containing text source of YANG model + * @param refClass Base search class + * @param resourceName resource name, relative to refClass * @return {@link YangModelDependencyInfo} - * @throws IllegalArgumentException If input stream is not valid YANG stream + * @throws YangSyntaxErrorException If the resource does not pass syntactic analysis + * @throws IOException When the resource cannot be read + * @throws IllegalArgumentException + * If input stream is not valid YANG stream */ - public static YangModelDependencyInfo fromInputStream(final InputStream yangStream) { - final StatementContext yangAST = new YangStatementSourceImpl(yangStream).getYangAST(); - return parseAST(yangAST, yangStream instanceof NamedInputStream ? yangStream.toString() : null); + public static YangModelDependencyInfo forResource(final Class refClass, final String resourceName) + throws IOException, YangSyntaxErrorException { + final YangStatementStreamSource source = YangStatementStreamSource.create( + YangTextSchemaSource.forResource(refClass, resourceName)); + final ParserRuleContext ast = source.getYangAST(); + Preconditions.checkArgument(ast instanceof StatementContext); + return parseAST((StatementContext) ast, source.getIdentifier().toYangFilename()); } private static YangModelDependencyInfo parseModuleContext(final StatementContext module, final String sourceName) { @@ -232,7 +240,7 @@ public abstract class YangModelDependencyInfo { getReference(sourceName, subStatementContext)); final Date revisionDate = revisionDateStr == null ? null : QName.parseRevision(revisionDateStr); final Optional importSemVer = Optional.fromNullable(findSemanticVersion(subStatementContext, - sourceName)); + sourceName)); result.add(new ModuleImportImpl(importedModuleName, revisionDate, importSemVer)); } } diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/repo/SharedSchemaContextFactory.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/repo/SharedSchemaContextFactory.java index ce9ed35776..c5c6bdec5d 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/repo/SharedSchemaContextFactory.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/repo/SharedSchemaContextFactory.java @@ -42,10 +42,10 @@ import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceFilter; import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier; import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode; import org.opendaylight.yangtools.yang.parser.impl.util.YangModelDependencyInfo; +import org.opendaylight.yangtools.yang.parser.rfc6020.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.parser.stmt.rfc6020.YangInferencePipeline; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl; import org.opendaylight.yangtools.yang.parser.util.ASTSchemaSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -214,16 +214,17 @@ final class SharedSchemaContextFactory implements SchemaContextFactory { res.getResolvedSources(), res.getUnsatisfiedImports()); } - final Map asts = Maps.transformValues(srcs, ASTSchemaSource::getAST); final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild( statementParserMode, supportedFeatures); - for (final Entry e : asts.entrySet()) { - final ParserRuleContext parserRuleCtx = e.getValue(); + for (final Entry e : srcs.entrySet()) { + final ASTSchemaSource ast = e.getValue(); + final ParserRuleContext parserRuleCtx = ast.getAST(); Preconditions.checkArgument(parserRuleCtx instanceof StatementContext, "Unsupported context class %s for source %s", parserRuleCtx.getClass(), e.getKey()); - reactor.addSource(new YangStatementSourceImpl(e.getKey(), (StatementContext) parserRuleCtx)); + reactor.addSource(YangStatementStreamSource.create(e.getKey(), (StatementContext) parserRuleCtx, + ast.getSymbolicName().orElse(null))); } final SchemaContext schemaContext; diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/rfc6020/repo/YangStatementStreamSource.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/rfc6020/repo/YangStatementStreamSource.java index ada4ca21b4..d7388e03c0 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/rfc6020/repo/YangStatementStreamSource.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/rfc6020/repo/YangStatementStreamSource.java @@ -87,6 +87,11 @@ public final class YangStatementStreamSource implements Identifiable { - - @Deprecated - public static final Transformation TRANSFORMATION = input -> { - final Document doc = UntrustedXML.newDocumentBuilder().newDocument(); - final SAXParser parser = UntrustedXML.newSAXParser(); - final DefaultHandler handler = new StatementSourceReferenceHandler(doc, null); - parser.parse(input.openStream(), handler); - - return Futures.immediateCheckedFuture(YinDomSchemaSource.create(input.getIdentifier(), new DOMSource(doc))); - }; - private YinTextToDomTransformer(final SchemaRepository provider, final SchemaSourceRegistry consumer) { - super(provider, YinTextSchemaSource.class, consumer, YinDomSchemaSource.class, TRANSFORMATION); + super(provider, YinTextSchemaSource.class, consumer, YinDomSchemaSource.class, + input -> Futures.immediateCheckedFuture(transformSource(input))); } public static YinTextToDomTransformer create(final SchemaRepository provider, final SchemaSourceRegistry consumer) { return new YinTextToDomTransformer(provider, consumer); } + public static YinDomSchemaSource transformSource(final YinTextSchemaSource source) throws SAXException, IOException { + final Document doc = UntrustedXML.newDocumentBuilder().newDocument(); + final SAXParser parser = UntrustedXML.newSAXParser(); + final DefaultHandler handler = new StatementSourceReferenceHandler(doc, null); + parser.parse(source.openStream(), handler); + return YinDomSchemaSource.create(source.getIdentifier(), new DOMSource(doc)); + } + } diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/CrossSourceStatementReactor.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/CrossSourceStatementReactor.java index 3e4ff41640..7ac2bc6c12 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/CrossSourceStatementReactor.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/CrossSourceStatementReactor.java @@ -9,30 +9,21 @@ package org.opendaylight.yangtools.yang.parser.stmt.reactor; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; -import com.google.common.io.ByteSource; -import java.io.IOException; -import java.io.InputStream; import java.util.Arrays; import java.util.Collection; import java.util.EnumMap; -import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; import javax.annotation.Nonnull; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.QNameModule; -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.StatementParserMode; -import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource; -import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YangStatementStreamSource; import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupportBundle; import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource; import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace.ValidationBundleType; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl; public final class CrossSourceStatementReactor { private final Map supportedTerminology; @@ -276,42 +267,5 @@ public final class CrossSourceStatementReactor { public EffectiveSchemaContext buildEffective() throws ReactorException { return context.buildEffective(); } - - /** - * Add specified sources and assemble the resulting SchemaContext. - * - * @deprecated Use {@link #addSources(Collection)} and {@link #buildEffective()} instead. - */ - @Deprecated - public SchemaContext buildEffective(final Collection yangByteSources) throws ReactorException, - IOException { - for (final ByteSource source : yangByteSources) { - if (source instanceof YangTextSchemaSource) { - try { - addSource(YangStatementStreamSource.create((YangTextSchemaSource) source)); - } catch (YangSyntaxErrorException e) { - throw new IOException("Source " + source + " failed to parse", e); - } - } else { - addSource(new YangStatementSourceImpl(source.openStream())); - } - } - - return buildEffective(); - } - - /** - * Add specified sources and assemble the resulting SchemaContext. - * - * @deprecated Use {@link #addSources(Collection)} and {@link #buildEffective()} instead. - */ - @Deprecated - public SchemaContext buildEffective(final List yangInputStreams) throws ReactorException { - for (final InputStream yangInputStream : yangInputStreams) { - addSource(new YangStatementSourceImpl(yangInputStream)); - } - - return buildEffective(); - } } } diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/YangStatementSourceImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/YangStatementSourceImpl.java deleted file mode 100644 index 8463c816ad..0000000000 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/YangStatementSourceImpl.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * 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.parser.stmt.rfc6020; - -import com.google.common.base.Throwables; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.URISyntaxException; -import org.antlr.v4.runtime.tree.ParseTreeWalker; -import org.opendaylight.yangtools.antlrv4.code.gen.YangStatementParser.StatementContext; -import org.opendaylight.yangtools.yang.common.YangVersion; -import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException; -import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier; -import org.opendaylight.yangtools.yang.parser.impl.YangStatementParserListenerImpl; -import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YangStatementStreamSource; -import org.opendaylight.yangtools.yang.parser.spi.source.PrefixToModule; -import org.opendaylight.yangtools.yang.parser.spi.source.QNameToStatementDefinition; -import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource; -import org.opendaylight.yangtools.yang.parser.spi.source.StatementWriter; -import org.opendaylight.yangtools.yang.parser.util.NamedFileInputStream; -import org.opendaylight.yangtools.yang.parser.util.NamedInputStream; - -/** - * This class represents implementation of StatementStreamSource in order to emit YANG statements using supplied - * StatementWriter. - * - * @deprecated Use {@link YangStatementStreamSource} instead. - */ -@Deprecated -public final class YangStatementSourceImpl implements StatementStreamSource { - private final YangStatementParserListenerImpl yangStatementModelParser; - private final StatementContext statementContext; - private final String sourceName; - - public YangStatementSourceImpl(final String fileName, final boolean isAbsolute) { - try { - final NamedFileInputStream is = loadFile(fileName, isAbsolute); - sourceName = is.toString(); - statementContext = YangStatementStreamSource.parseYangSource(is); - yangStatementModelParser = new YangStatementParserListenerImpl(sourceName); - } catch (IOException | URISyntaxException | YangSyntaxErrorException e) { - throw Throwables.propagate(e); - } - } - - public YangStatementSourceImpl(final InputStream inputStream) { - try { - sourceName = inputStream instanceof NamedInputStream ? inputStream.toString() : null; - statementContext = YangStatementStreamSource.parseYangSource(inputStream); - yangStatementModelParser = new YangStatementParserListenerImpl(sourceName); - } catch (IOException | YangSyntaxErrorException e) { - throw Throwables.propagate(e); - } - } - - public YangStatementSourceImpl(final SourceIdentifier identifier, final StatementContext statementContext) { - this.statementContext = statementContext; - this.sourceName = identifier.getName(); - yangStatementModelParser = new YangStatementParserListenerImpl(sourceName); - } - - @Override - public void writePreLinkage(final StatementWriter writer, final QNameToStatementDefinition stmtDef) { - yangStatementModelParser.setAttributes(writer, stmtDef); - ParseTreeWalker.DEFAULT.walk(yangStatementModelParser, statementContext); - } - - @Override - public void writeLinkage(final StatementWriter writer, final QNameToStatementDefinition stmtDef, - final PrefixToModule preLinkagePrefixes) { - writeLinkage(writer, stmtDef, preLinkagePrefixes, YangVersion.VERSION_1); - } - - @Override - public void writeLinkage(final StatementWriter writer, final QNameToStatementDefinition stmtDef, - final PrefixToModule preLinkagePrefixes, final YangVersion yangVersion) { - yangStatementModelParser.setAttributes(writer, stmtDef, preLinkagePrefixes, yangVersion); - ParseTreeWalker.DEFAULT.walk(yangStatementModelParser, statementContext); - } - - @Override - public void writeLinkageAndStatementDefinitions(final StatementWriter writer, - final QNameToStatementDefinition stmtDef, final PrefixToModule prefixes) { - writeLinkageAndStatementDefinitions(writer, stmtDef, prefixes, YangVersion.VERSION_1); - } - - @Override - public void writeLinkageAndStatementDefinitions(final StatementWriter writer, - final QNameToStatementDefinition stmtDef, final PrefixToModule prefixes, final YangVersion yangVersion) { - yangStatementModelParser.setAttributes(writer, stmtDef, prefixes, yangVersion); - ParseTreeWalker.DEFAULT.walk(yangStatementModelParser, statementContext); - } - - @Override - public void writeFull(final StatementWriter writer, final QNameToStatementDefinition stmtDef, - final PrefixToModule prefixes) { - writeFull(writer, stmtDef, prefixes, YangVersion.VERSION_1); - } - - @Override - public void writeFull(final StatementWriter writer, final QNameToStatementDefinition stmtDef, - final PrefixToModule prefixes, final YangVersion yangVersion) { - yangStatementModelParser.setAttributes(writer, stmtDef, prefixes, yangVersion); - ParseTreeWalker.DEFAULT.walk(yangStatementModelParser, statementContext); - } - - private NamedFileInputStream loadFile(final String fileName, final boolean isAbsolute) - throws URISyntaxException, IOException { - //TODO: we need absolute path first! - return isAbsolute ? new NamedFileInputStream(new File(fileName), fileName) - : new NamedFileInputStream(new File(getClass().getResource(fileName).toURI()), fileName); - } - - public StatementContext getYangAST() { - return statementContext; - } - - @Override - public String toString() { - return sourceName; - } -} diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/YinStatementSourceImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/YinStatementSourceImpl.java deleted file mode 100644 index 24dace3659..0000000000 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/YinStatementSourceImpl.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * 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.parser.stmt.rfc6020; - -import com.google.common.base.Throwables; -import com.google.common.collect.ForwardingObject; -import com.google.common.io.ByteSource; -import com.google.common.io.ByteStreams; -import com.google.common.io.Files; -import java.io.File; -import java.io.InputStream; -import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier; -import org.opendaylight.yangtools.yang.model.repo.api.YinDomSchemaSource; -import org.opendaylight.yangtools.yang.model.repo.api.YinTextSchemaSource; -import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YinStatementStreamSource; -import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YinTextToDomTransformer; -import org.opendaylight.yangtools.yang.parser.spi.source.PrefixToModule; -import org.opendaylight.yangtools.yang.parser.spi.source.QNameToStatementDefinition; -import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource; -import org.opendaylight.yangtools.yang.parser.spi.source.StatementWriter; - -/** - * This class represents implementation of StatementStreamSource - * in order to emit YIN statements using supplied StatementWriter. - * - * @deprecated Scheduled for removal. Use {@link YinStatementStreamSource} instead. - */ -@Deprecated -public final class YinStatementSourceImpl extends ForwardingObject implements StatementStreamSource { - private final StatementStreamSource delegate; - - private YinStatementSourceImpl(final YinDomSchemaSource source) { - this.delegate = YinStatementStreamSource.create(source); - } - - @Override - public StatementStreamSource delegate() { - return delegate; - } - - public YinStatementSourceImpl(final InputStream inputStream) { - this(newStreamSource(inputStream)); - } - - private static YinDomSchemaSource newStreamSource(final InputStream inputStream) { - final SourceIdentifier id = YinTextSchemaSource.identifierFromFilename(inputStream.toString()); - - try { - final YinTextSchemaSource text = YinTextSchemaSource.delegateForByteSource(id, - ByteSource.wrap(ByteStreams.toByteArray(inputStream))); - return YinTextToDomTransformer.TRANSFORMATION.apply(text).get(); - } catch (Exception e) { - throw Throwables.propagate(e); - } - } - - private static YinDomSchemaSource newStreamSource(final String fileName, final boolean isAbsolute) { - try { - final File file; - if (isAbsolute) { - file = new File(fileName); - } else { - file = new File(YinStatementSourceImpl.class.getResource(fileName).toURI()); - } - - final YinTextSchemaSource text = YinTextSchemaSource.delegateForByteSource( - YinTextSchemaSource.identifierFromFilename(file.getName()), Files.asByteSource(file)); - - return YinTextToDomTransformer.TRANSFORMATION.apply(text).get(); - } catch (Exception e) { - throw Throwables.propagate(e); - } - } - - public YinStatementSourceImpl(final String fileName, final boolean isAbsolute) { - this(newStreamSource(fileName, isAbsolute)); - } - - @Override - public void writePreLinkage(final StatementWriter writer, final QNameToStatementDefinition stmtDef) { - delegate.writePreLinkage(writer, stmtDef); - } - - @Override - public void writeLinkage(final StatementWriter writer, final QNameToStatementDefinition stmtDef, - final PrefixToModule preLinkagePrefixes) { - delegate.writeLinkage(writer, stmtDef, preLinkagePrefixes); - - } - - @Override - public void writeLinkageAndStatementDefinitions(final StatementWriter writer, final QNameToStatementDefinition stmtDef, - final PrefixToModule prefixes) { - delegate.writeLinkageAndStatementDefinitions(writer, stmtDef, prefixes); - } - - @Override - public void writeFull(final StatementWriter writer, final QNameToStatementDefinition stmtDef, - final PrefixToModule prefixes) { - delegate().writeFull(writer, stmtDef, prefixes); - } - -} diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/YangParseException.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/YangParseException.java deleted file mode 100644 index aac1bfbc50..0000000000 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/YangParseException.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * 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.parser.util; - -/** - * @deprecated This exception is not produced anywhere and is scheduled for removal. - */ -// TODO: switch to checked exception, add YangSemanticException -@Deprecated -public class YangParseException extends RuntimeException { - private static final long serialVersionUID = 1239548963471793178L; - - public YangParseException(final String errorMsg) { - super(errorMsg); - } - - public YangParseException(final String errorMsg, final Exception exception) { - super(errorMsg, exception); - } - - public YangParseException(final String moduleName, final int line, final String errorMsg) { - super("Error in module '" + moduleName + "' at line " + line + ": " + errorMsg); - } - - public YangParseException(final String moduleName, final int line, final String errorMsg, final Exception exception) { - super("Error in module '" + moduleName + "' at line " + line + ": " + errorMsg, exception); - } -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/util/YangModelDependencyInfoTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/util/YangModelDependencyInfoTest.java index de0e17ff43..c843ae7c78 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/util/YangModelDependencyInfoTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/util/YangModelDependencyInfoTest.java @@ -13,15 +13,17 @@ import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import java.io.InputStream; + +import java.io.IOException; import org.junit.Test; +import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException; public class YangModelDependencyInfoTest { @Test - public void testModuleWithNoImports() { - InputStream stream = getClass().getResourceAsStream("/ietf/ietf-inet-types@2010-09-24.yang"); - YangModelDependencyInfo info = YangModelDependencyInfo.fromInputStream(stream); + public void testModuleWithNoImports() throws IOException, YangSyntaxErrorException { + YangModelDependencyInfo info = YangModelDependencyInfo.forResource(getClass(), + "/ietf/ietf-inet-types@2010-09-24.yang"); assertNotNull(info); assertEquals("ietf-inet-types", info.getName()); assertEquals("2010-09-24", info.getFormattedRevision()); @@ -31,9 +33,9 @@ public class YangModelDependencyInfoTest { } @Test - public void testModuleWithImports() { - InputStream stream = getClass().getResourceAsStream("/parse-methods/dependencies/m2@2013-09-30.yang"); - YangModelDependencyInfo info = YangModelDependencyInfo.fromInputStream(stream); + public void testModuleWithImports() throws IOException, YangSyntaxErrorException { + YangModelDependencyInfo info = YangModelDependencyInfo.forResource(getClass(), + "/parse-methods/dependencies/m2@2013-09-30.yang"); assertNotNull(info); assertEquals("m2", info.getName()); assertEquals("2013-09-30", info.getFormattedRevision()); @@ -42,32 +44,30 @@ public class YangModelDependencyInfoTest { } @Test - public void testModuleWithoutRevision() { - InputStream stream = getClass().getResourceAsStream("/no-revision/module-without-revision.yang"); - YangModelDependencyInfo info = YangModelDependencyInfo.fromInputStream(stream); + public void testModuleWithoutRevision() throws IOException, YangSyntaxErrorException { + YangModelDependencyInfo info = YangModelDependencyInfo.forResource(getClass(), + "/no-revision/module-without-revision.yang"); assertNotNull(info); assertEquals("module-without-revision", info.getName()); assertNull(info.getFormattedRevision()); } @Test - public void testEquals() { - InputStream stream1 = getClass().getResourceAsStream("/ietf/ietf-inet-types@2010-09-24.yang"); - YangModelDependencyInfo info1 = YangModelDependencyInfo.fromInputStream(stream1); - InputStream stream2 = getClass().getResourceAsStream("/no-revision/module-without-revision.yang"); - YangModelDependencyInfo info2 = YangModelDependencyInfo.fromInputStream(stream2); + public void testEquals() throws IOException, YangSyntaxErrorException { + YangModelDependencyInfo info1 = YangModelDependencyInfo.forResource(getClass(), + "/ietf/ietf-inet-types@2010-09-24.yang"); + YangModelDependencyInfo info2 = YangModelDependencyInfo.forResource(getClass(), + "/no-revision/module-without-revision.yang"); assertTrue(info1.equals(info1)); assertFalse(info1.equals(null)); - assertFalse(info1.equals(stream1)); assertFalse(info1.equals(info2)); } @Test - public void testHashcode() { - InputStream stream = getClass().getResourceAsStream("/no-revision/module-without-revision.yang"); - YangModelDependencyInfo info = YangModelDependencyInfo.fromInputStream(stream); - + public void testHashcode() throws IOException, YangSyntaxErrorException { + YangModelDependencyInfo info = YangModelDependencyInfo.forResource(getClass(), + "/no-revision/module-without-revision.yang"); assertNotEquals("hashcode", 31, info.hashCode()); } } diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/repo/DependencyResolverTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/repo/DependencyResolverTest.java index b85d2d4cb3..1fff2ff3b4 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/repo/DependencyResolverTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/repo/DependencyResolverTest.java @@ -10,12 +10,11 @@ package org.opendaylight.yangtools.yang.parser.repo; import static org.junit.Assert.assertEquals; -import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier; - import com.google.common.base.Optional; import java.util.HashMap; import java.util.Map; import org.junit.Test; +import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier; import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier; import org.opendaylight.yangtools.yang.parser.impl.util.YangModelDependencyInfo; @@ -26,9 +25,9 @@ public class DependencyResolverTest { public void testModulesWithoutRevisionAndImport() throws Exception { final Map map = new HashMap<>(); - addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.fromInputStream(getClass().getResourceAsStream("/no-revision/imported.yang"))); - addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.fromInputStream(getClass().getResourceAsStream("/no-revision/imported@2012-12-12.yang"))); - addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.fromInputStream(getClass().getResourceAsStream("/no-revision/top@2012-10-10.yang"))); + addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.forResource(getClass(), "/no-revision/imported.yang")); + addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.forResource(getClass(), "/no-revision/imported@2012-12-12.yang")); + addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.forResource(getClass(), "/no-revision/top@2012-10-10.yang")); final DependencyResolver resolved = RevisionDependencyResolver.create(map); @@ -41,9 +40,9 @@ public class DependencyResolverTest { final Map map = new HashMap<>(); // Subfoo does not have parent in reactor - addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.fromInputStream(getClass().getResourceAsStream("/model/subfoo.yang"))); - addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.fromInputStream(getClass().getResourceAsStream("/model/bar.yang"))); - addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.fromInputStream(getClass().getResourceAsStream("/model/baz.yang"))); + addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.forResource(getClass(), "/model/subfoo.yang")); + addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.forResource(getClass(), "/model/bar.yang")); + addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.forResource(getClass(), "/model/baz.yang")); final DependencyResolver resolved = RevisionDependencyResolver.create(map); @@ -56,10 +55,10 @@ public class DependencyResolverTest { public void testSubmodule() throws Exception { final Map map = new HashMap<>(); - addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.fromInputStream(getClass().getResourceAsStream("/model/subfoo.yang"))); - addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.fromInputStream(getClass().getResourceAsStream("/model/foo.yang"))); - addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.fromInputStream(getClass().getResourceAsStream("/model/bar.yang"))); - addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.fromInputStream(getClass().getResourceAsStream("/model/baz.yang"))); + addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.forResource(getClass(), "/model/subfoo.yang")); + addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.forResource(getClass(), "/model/foo.yang")); + addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.forResource(getClass(), "/model/bar.yang")); + addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.forResource(getClass(), "/model/baz.yang")); final DependencyResolver resolved = RevisionDependencyResolver.create(map); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ConstraintDefinitionsTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ConstraintDefinitionsTest.java index e896f1c34f..3d3baa8958 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ConstraintDefinitionsTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ConstraintDefinitionsTest.java @@ -17,7 +17,6 @@ import static org.junit.Assert.assertTrue; import java.io.IOException; import java.net.URISyntaxException; import java.text.ParseException; -import java.util.Arrays; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil; @@ -27,7 +26,9 @@ import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode; import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; 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.rfc6020.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.parser.stmt.rfc6020.YangInferencePipeline; @@ -35,12 +36,13 @@ import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline public class ConstraintDefinitionsTest { @Test - public void testConstraintDefinitions() throws ParseException, ReactorException, URISyntaxException, IOException { + public void testConstraintDefinitions() throws ParseException, ReactorException, URISyntaxException, IOException, + YangSyntaxErrorException { final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(); - final YangTextSchemaSource source = YangTextSchemaSource.forResource("/constraint-definitions-test/foo.yang"); - - final SchemaContext schemaContext = reactor.buildEffective(Arrays.asList(source)); + reactor.addSource(YangStatementStreamSource.create( + YangTextSchemaSource.forResource("/constraint-definitions-test/foo.yang"))); + final SchemaContext schemaContext = reactor.buildEffective(); assertNotNull(schemaContext); final Module testModule = schemaContext.findModuleByName("foo", diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentTest.java index 495e6ee01a..5e87187f83 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentTest.java @@ -12,10 +12,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import java.io.FileNotFoundException; import java.net.URI; -import java.text.DateFormat; -import java.text.ParseException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -23,9 +20,9 @@ import java.util.Collections; import java.util.Date; import java.util.List; import java.util.Set; -import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.common.QNameModule; import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil; import org.opendaylight.yangtools.yang.common.YangConstants; import org.opendaylight.yangtools.yang.model.api.AugmentationSchema; @@ -38,45 +35,34 @@ import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.RpcDefinition; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.SchemaPath; import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils; public class AugmentTest { - private static final URI fooNS = URI.create("urn:opendaylight.foo"); - private static final URI barNS = URI.create("urn:opendaylight.bar"); - private static final URI bazNS = URI.create("urn:opendaylight.baz"); - private static Date fooRev; - private static Date barRev; - private static Date bazRev; - private static QName q0; - private static QName q1; - private static QName q2; - - private Set modules; - - @BeforeClass - public static void init() throws FileNotFoundException, ParseException { - final DateFormat simpleDateFormat = SimpleDateFormatUtil.getRevisionFormat(); - fooRev = simpleDateFormat.parse("2013-10-13"); - barRev = simpleDateFormat.parse("2013-10-14"); - bazRev = simpleDateFormat.parse("2013-10-15"); - - q0 = QName.create(barNS, barRev, "interfaces"); - q1 = QName.create(barNS, barRev, "ifEntry"); - q2 = QName.create(bazNS, bazRev, "augment-holder"); - } + private static final QNameModule FOO = QNameModule.create( + URI.create("urn:opendaylight.foo"), QName.parseRevision("2013-10-13")); + private static final QNameModule BAR = QNameModule.create( + URI.create("urn:opendaylight.bar"), QName.parseRevision("2013-10-14")); + private static final QNameModule BAZ = QNameModule.create( + URI.create("urn:opendaylight.baz"), QName.parseRevision("2013-10-15")); + + private static final QName Q0 = QName.create(BAR, "interfaces"); + private static final QName Q1 = QName.create(BAR, "ifEntry"); + private static final QName Q2 = QName.create(BAZ, "augment-holder"); @Test public void testAugmentParsing() throws Exception { - modules = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment").toURI()); + final SchemaContext context = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment") + .toURI()); SchemaPath expectedSchemaPath; final List qnames = new ArrayList<>(); - qnames.add(q0); - qnames.add(q1); - qnames.add(q2); + qnames.add(Q0); + qnames.add(Q1); + qnames.add(Q2); // foo.yang - final Module module1 = TestUtils.findModule(modules, "foo"); + final Module module1 = TestUtils.findModule(context, "foo").get(); Set augmentations = module1.getAugmentations(); assertEquals(1, augmentations.size()); final AugmentationSchema augment = augmentations.iterator().next(); @@ -106,7 +92,7 @@ public class AugmentTest { assertNotNull(odl); // leaf ds0ChannelNumber - QName qname = QName.create(fooNS, fooRev, "ds0ChannelNumber"); + QName qname = QName.create(FOO, "ds0ChannelNumber"); qnames.add(qname); assertEquals(qname, ds0ChannelNumber.getQName()); expectedSchemaPath = SchemaPath.create(qnames, true); @@ -119,7 +105,7 @@ public class AugmentTest { assertEquals(expectedSchemaPath, ds0ChannelNumber.getType().getPath()); // leaf interface-id - qname = QName.create(fooNS, fooRev, "interface-id"); + qname = QName.create(FOO, "interface-id"); assertEquals(qname, interfaceId.getQName()); qnames.set(3, qname); expectedSchemaPath = SchemaPath.create(qnames, true); @@ -127,7 +113,7 @@ public class AugmentTest { assertFalse(interfaceId.isAugmenting()); // container schemas - qname = QName.create(fooNS, fooRev, "schemas"); + qname = QName.create(FOO, "schemas"); assertEquals(qname, schemas.getQName()); qnames.set(3, qname); expectedSchemaPath = SchemaPath.create(qnames, true); @@ -135,7 +121,7 @@ public class AugmentTest { assertFalse(schemas.isAugmenting()); // choice odl - qname = QName.create(fooNS, fooRev, "odl"); + qname = QName.create(FOO, "odl"); assertEquals(qname, odl.getQName()); qnames.set(3, qname); expectedSchemaPath = SchemaPath.create(qnames, true); @@ -143,7 +129,7 @@ public class AugmentTest { assertFalse(odl.isAugmenting()); // baz.yang - final Module module3 = TestUtils.findModule(modules, "baz"); + final Module module3 = TestUtils.findModule(context, "baz").get(); augmentations = module3.getAugmentations(); assertEquals(3, augmentations.size()); AugmentationSchema augment1 = null; @@ -180,8 +166,9 @@ public class AugmentTest { @Test public void testAugmentResolving() throws Exception { - modules = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment").toURI()); - final Module module2 = TestUtils.findModule(modules, "bar"); + final SchemaContext context = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment") + .toURI()); + final Module module2 = TestUtils.findModule(context, "bar").get(); final ContainerSchemaNode interfaces = (ContainerSchemaNode) module2.getDataChildByName(QName.create( module2.getQNameModule(), "interfaces")); final ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName(QName.create( @@ -189,29 +176,28 @@ public class AugmentTest { SchemaPath expectedPath; final List qnames = new ArrayList<>(); - qnames.add(q0); - qnames.add(q1); - qnames.add(q2); + qnames.add(Q0); + qnames.add(Q1); + qnames.add(Q2); // baz.yang // augment "/br:interfaces/br:ifEntry" { - final ContainerSchemaNode augmentHolder = (ContainerSchemaNode) ifEntry.getDataChildByName(QName.create(bazNS, - bazRev, "augment-holder")); + final ContainerSchemaNode augmentHolder = (ContainerSchemaNode) ifEntry.getDataChildByName(QName.create(BAZ, + "augment-holder")); TestUtils.checkIsAugmenting(augmentHolder, true); - assertEquals(q2, augmentHolder.getQName()); + assertEquals(Q2, augmentHolder.getQName()); expectedPath = SchemaPath.create(qnames, true); assertEquals(expectedPath, augmentHolder.getPath()); // foo.yang // augment "/br:interfaces/br:ifEntry/bz:augment-holder" - final LeafSchemaNode ds0ChannelNumber = (LeafSchemaNode) augmentHolder.getDataChildByName(QName.create(fooNS, - fooRev, "ds0ChannelNumber")); - final LeafSchemaNode interfaceId = (LeafSchemaNode) augmentHolder.getDataChildByName(QName.create(fooNS, - fooRev, "interface-id")); - final ContainerSchemaNode schemas = (ContainerSchemaNode) augmentHolder.getDataChildByName(QName.create(fooNS, - fooRev, "schemas")); - final ChoiceSchemaNode odl = (ChoiceSchemaNode) augmentHolder.getDataChildByName(QName.create(fooNS, fooRev, - "odl")); + final LeafSchemaNode ds0ChannelNumber = (LeafSchemaNode) augmentHolder.getDataChildByName(QName.create(FOO, + "ds0ChannelNumber")); + final LeafSchemaNode interfaceId = (LeafSchemaNode) augmentHolder.getDataChildByName(QName.create(FOO, + "interface-id")); + final ContainerSchemaNode schemas = (ContainerSchemaNode) augmentHolder.getDataChildByName(QName.create(FOO, + "schemas")); + final ChoiceSchemaNode odl = (ChoiceSchemaNode) augmentHolder.getDataChildByName(QName.create(FOO, "odl")); assertNotNull(ds0ChannelNumber); assertNotNull(interfaceId); @@ -219,28 +205,28 @@ public class AugmentTest { assertNotNull(odl); // leaf ds0ChannelNumber - QName qname = QName.create(fooNS, fooRev, "ds0ChannelNumber"); + QName qname = QName.create(FOO, "ds0ChannelNumber"); assertEquals(qname, ds0ChannelNumber.getQName()); qnames.add(qname); expectedPath = SchemaPath.create(qnames, true); assertEquals(expectedPath, ds0ChannelNumber.getPath()); // leaf interface-id - qname = QName.create(fooNS, fooRev, "interface-id"); + qname = QName.create(FOO, "interface-id"); assertEquals(qname, interfaceId.getQName()); qnames.set(3, qname); expectedPath = SchemaPath.create(qnames, true); assertEquals(expectedPath, interfaceId.getPath()); // container schemas - qname = QName.create(fooNS, fooRev, "schemas"); + qname = QName.create(FOO, "schemas"); assertEquals(qname, schemas.getQName()); qnames.set(3, qname); expectedPath = SchemaPath.create(qnames, true); assertEquals(expectedPath, schemas.getPath()); // choice odl - qname = QName.create(fooNS, fooRev, "odl"); + qname = QName.create(FOO, "odl"); assertEquals(qname, odl.getQName()); qnames.set(3, qname); expectedPath = SchemaPath.create(qnames, true); @@ -249,20 +235,20 @@ public class AugmentTest { @Test public void testAugmentedChoice() throws Exception { - modules = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment").toURI()); - final Module module2 = TestUtils.findModule(modules, "bar"); + final SchemaContext context = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment") + .toURI()); + final Module module2 = TestUtils.findModule(context, "bar").get(); final ContainerSchemaNode interfaces = (ContainerSchemaNode) module2.getDataChildByName(QName.create( module2.getQNameModule(), "interfaces")); final ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName(QName.create( module2.getQNameModule(), "ifEntry")); final ContainerSchemaNode augmentedHolder = (ContainerSchemaNode) ifEntry.getDataChildByName(QName.create( - bazNS, bazRev, "augment-holder")); + BAZ, "augment-holder")); TestUtils.checkIsAugmenting(augmentedHolder, true); // foo.yang // augment "/br:interfaces/br:ifEntry/bz:augment-holder" - final ChoiceSchemaNode odl = (ChoiceSchemaNode) augmentedHolder.getDataChildByName(QName.create(fooNS, fooRev, - "odl")); + final ChoiceSchemaNode odl = (ChoiceSchemaNode) augmentedHolder.getDataChildByName(QName.create(FOO, "odl")); assertNotNull(odl); final Set cases = odl.getCases(); assertEquals(4, cases.size()); @@ -291,13 +277,13 @@ public class AugmentTest { SchemaPath expectedPath; final List qnames = new ArrayList<>(); - qnames.add(q0); - qnames.add(q1); - qnames.add(q2); - qnames.add(QName.create(fooNS, fooRev, "odl")); + qnames.add(Q0); + qnames.add(Q1); + qnames.add(Q2); + qnames.add(QName.create(FOO, "odl")); // case id - QName qname = QName.create(fooNS, fooRev, "id"); + QName qname = QName.create(FOO, "id"); assertEquals(qname, id.getQName()); qnames.add(qname); expectedPath = SchemaPath.create(qnames, true); @@ -306,7 +292,7 @@ public class AugmentTest { assertEquals(1, idChildren.size()); // case node1 - qname = QName.create(fooNS, fooRev, "node1"); + qname = QName.create(FOO, "node1"); assertEquals(qname, node1.getQName()); qnames.set(4, qname); expectedPath = SchemaPath.create(qnames, true); @@ -315,7 +301,7 @@ public class AugmentTest { assertTrue(node1Children.isEmpty()); // case node2 - qname = QName.create(fooNS, fooRev, "node2"); + qname = QName.create(FOO, "node2"); assertEquals(qname, node2.getQName()); qnames.set(4, qname); expectedPath = SchemaPath.create(qnames, true); @@ -324,7 +310,7 @@ public class AugmentTest { assertTrue(node2Children.isEmpty()); // case node3 - qname = QName.create(fooNS, fooRev, "node3"); + qname = QName.create(FOO, "node3"); assertEquals(qname, node3.getQName()); qnames.set(4, qname); expectedPath = SchemaPath.create(qnames, true); @@ -334,22 +320,22 @@ public class AugmentTest { // test cases qnames.clear(); - qnames.add(q0); - qnames.add(q1); - qnames.add(q2); - qnames.add(QName.create(fooNS, fooRev, "odl")); + qnames.add(Q0); + qnames.add(Q1); + qnames.add(Q2); + qnames.add(QName.create(FOO, "odl")); // case id child - qnames.add(QName.create(fooNS, fooRev, "id")); - qnames.add(QName.create(fooNS, fooRev, "id")); + qnames.add(QName.create(FOO, "id")); + qnames.add(QName.create(FOO, "id")); final LeafSchemaNode caseIdChild = (LeafSchemaNode) idChildren.iterator().next(); assertNotNull(caseIdChild); expectedPath = SchemaPath.create(qnames, true); assertEquals(expectedPath, caseIdChild.getPath()); // case node3 child - qnames.set(4, QName.create(fooNS, fooRev, "node3")); - qnames.set(5, QName.create(fooNS, fooRev, "node3")); + qnames.set(4, QName.create(FOO, "node3")); + qnames.set(5, QName.create(FOO, "node3")); final ContainerSchemaNode caseNode3Child = (ContainerSchemaNode) node3Children.iterator().next(); assertNotNull(caseNode3Child); expectedPath = SchemaPath.create(qnames, true); @@ -358,12 +344,12 @@ public class AugmentTest { @Test public void testAugmentRpc() throws Exception { - modules = TestUtils.loadModules(getClass().getResource("/augment-test/rpc").toURI()); + final SchemaContext context = TestUtils.loadModules(getClass().getResource("/augment-test/rpc").toURI()); final URI NS_BAR = URI.create("urn:opendaylight:bar"); final URI NS_FOO = URI.create("urn:opendaylight:foo"); final Date revision = SimpleDateFormatUtil.getRevisionFormat().parse("2013-10-11"); - final Module bar = TestUtils.findModule(modules, "bar"); + final Module bar = TestUtils.findModule(context, "bar").get(); final Set rpcs = bar.getRpcs(); assertEquals(2, rpcs.size()); @@ -442,10 +428,11 @@ public class AugmentTest { @Test public void testAugmentInUsesResolving() throws Exception { - modules = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-uses").toURI()); - assertEquals(1, modules.size()); + final SchemaContext context = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-uses") + .toURI()); + assertEquals(1, context.getModules().size()); - final Module test = modules.iterator().next(); + final Module test = context.getModules().iterator().next(); final DataNodeContainer links = (DataNodeContainer) test.getDataChildByName(QName.create(test.getQNameModule(), "links")); final DataNodeContainer link = (DataNodeContainer) links.getDataChildByName(QName.create(test.getQNameModule(), diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentToExtensionTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentToExtensionTest.java index 3872378faa..99ef2831d1 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentToExtensionTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/AugmentToExtensionTest.java @@ -15,15 +15,16 @@ import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.AugmentationSchema; 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.model.api.UsesNode; import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException; public class AugmentToExtensionTest { - private Set modules; + private SchemaContext context; @Test(expected = SomeModifiersUnresolvedException.class) public void testIncorrectPath() throws Exception { - modules = TestUtils.loadModules(getClass().getResource("/augment-to-extension-test/incorrect-path").toURI()); + context = TestUtils.loadModules(getClass().getResource("/augment-to-extension-test/incorrect-path").toURI()); } /* @@ -34,14 +35,14 @@ public class AugmentToExtensionTest { public void testCorrectPathIntoUnsupportedTarget() throws Exception { try { - modules = TestUtils.loadModules(getClass().getResource( + context = TestUtils.loadModules(getClass().getResource( "/augment-to-extension-test/correct-path-into-unsupported-target").toURI()); } catch (final Exception e) { StmtTestUtils.log(e, " "); throw e; } - final Module devicesModule = TestUtils.findModule(modules, "augment-module"); + final Module devicesModule = TestUtils.findModule(context, "augment-module").get(); final ContainerSchemaNode devicesContainer = (ContainerSchemaNode) devicesModule.getDataChildByName(QName .create(devicesModule.getQNameModule(), "my-container")); @@ -55,9 +56,9 @@ public class AugmentToExtensionTest { @Test public void testCorrectAugment() throws Exception { - modules = TestUtils.loadModules(getClass().getResource("/augment-to-extension-test/correct-augment").toURI()); + context = TestUtils.loadModules(getClass().getResource("/augment-to-extension-test/correct-augment").toURI()); - final Module devicesModule = TestUtils.findModule(modules, "augment-module"); + final Module devicesModule = TestUtils.findModule(context, "augment-module").get(); final ContainerSchemaNode devicesContainer = (ContainerSchemaNode) devicesModule.getDataChildByName(QName .create(devicesModule.getQNameModule(), "my-container")); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug1412Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug1412Test.java index 43f475617c..b9f5f62403 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug1412Test.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug1412Test.java @@ -13,7 +13,6 @@ import static org.junit.Assert.assertNotNull; import java.net.URI; import java.util.Date; import java.util.List; -import java.util.Set; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.QNameModule; @@ -31,15 +30,8 @@ public class Bug1412Test { @Test public void test() throws Exception { - - Set modules = null; - - - modules = TestUtils.loadModules(getClass().getResource("/bugs/bug1412").toURI()); - - - final Module bug1412 = TestUtils.findModule(modules, "bug1412"); - assertNotNull(bug1412); + final Module bug1412 = TestUtils.findModule( + TestUtils.loadModules(getClass().getResource("/bugs/bug1412").toURI()), "bug1412").get(); final ContainerSchemaNode node = (ContainerSchemaNode) bug1412.getDataChildByName(QName.create( bug1412.getQNameModule(), "node")); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug1413Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug1413Test.java index 22d196712b..f3fb19ec71 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug1413Test.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug1413Test.java @@ -12,7 +12,6 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.util.List; -import java.util.Set; import org.junit.Test; import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition; import org.opendaylight.yangtools.yang.model.api.Module; @@ -27,8 +26,8 @@ public class Bug1413Test { @Test public void test() throws Exception { - Set modules = TestUtils.loadModules(getClass().getResource("/bugs/bug1413").toURI()); - Module bug1413 = TestUtils.findModule(modules, "bug1413"); + final Module bug1413 = TestUtils.findModule( + TestUtils.loadModules(getClass().getResource("/bugs/bug1413").toURI()), "bug1413").get(); assertNotNull(bug1413); List extensions = bug1413.getExtensionSchemaNodes(); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug3859Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug3859Test.java index 012cc1fa55..a67fdae6d2 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug3859Test.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug3859Test.java @@ -9,17 +9,14 @@ package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertNotNull; -import java.util.Set; import org.junit.Test; import org.opendaylight.yangtools.yang.model.api.Module; public class Bug3859Test { - @Test public void test() throws Exception { - Set modules = TestUtils.loadModules(getClass().getResource("/bugs/bug3859").toURI()); - Module bug3859 = TestUtils.findModule(modules, "reference-in-unknown"); + final Module bug3859 = TestUtils.findModule( + TestUtils.loadModules(getClass().getResource("/bugs/bug3859").toURI()), "reference-in-unknown").get(); assertNotNull(bug3859); } - } diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug394Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug394Test.java index 27d98c6cb7..94cf0b3f0c 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug394Test.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug394Test.java @@ -12,12 +12,12 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.util.List; -import java.util.Set; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition; import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; /** @@ -27,11 +27,9 @@ public class Bug394Test { @Test public void testParseList() throws Exception { - final Set modules = TestUtils.loadModules(getClass().getResource("/bugs/bug394-retest").toURI()); - final Module bug394 = TestUtils.findModule(modules, "bug394"); - assertNotNull(bug394); - final Module bug394_ext = TestUtils.findModule(modules, "bug394-ext"); - assertNotNull(bug394_ext); + final SchemaContext context = TestUtils.loadModules(getClass().getResource("/bugs/bug394-retest").toURI()); + final Module bug394 = TestUtils.findModule(context, "bug394").get(); + final Module bug394_ext = TestUtils.findModule(context, "bug394-ext").get(); final ContainerSchemaNode logrecords = (ContainerSchemaNode) bug394.getDataChildByName(QName.create( bug394.getQNameModule(), "logrecords")); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5693Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5693Test.java index 604084d73d..292a6c753b 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5693Test.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5693Test.java @@ -11,26 +11,24 @@ package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import java.io.File; -import java.io.FileNotFoundException; +import java.io.IOException; 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.opendaylight.yangtools.yang.parser.util.NamedFileInputStream; +import org.xml.sax.SAXException; public class Bug5693Test { - private final String pathToModuleFoo = getClass().getResource("/bugs/bug5693/foo.yin").getPath(); private Module foo; /** * Use input stream to load Yin module. */ @Before - public void initTest() throws FileNotFoundException, ReactorException { - foo = TestUtils.loadYinModule(new NamedFileInputStream(new File(pathToModuleFoo), pathToModuleFoo)); - assertNotNull(foo); + public void initTest() throws ReactorException, SAXException, IOException { + foo = TestUtils.loadYinModule(YinTextSchemaSource.forResource(getClass(), "/bugs/bug5693/foo.yin")); } /** diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveSchemaContextTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveSchemaContextTest.java index f8b01a921e..8b6b1c499b 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveSchemaContextTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveSchemaContextTest.java @@ -18,7 +18,6 @@ import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.text.ParseException; -import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Set; @@ -34,7 +33,9 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.SchemaPath; 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.parser.rfc6020.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.parser.stmt.reactor.EffectiveSchemaContext; @@ -43,17 +44,19 @@ import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline public class EffectiveSchemaContextTest { @Test - public void testEffectiveSchemaContext() throws ReactorException, ParseException, URISyntaxException, IOException { + public void testEffectiveSchemaContext() throws ReactorException, ParseException, URISyntaxException, IOException, + YangSyntaxErrorException { final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(); - final YangTextSchemaSource source1 = YangTextSchemaSource.forResource( - "/effective-schema-context-test/foo.yang"); - final YangTextSchemaSource source2 = YangTextSchemaSource.forResource( - "/effective-schema-context-test/bar.yang"); - final YangTextSchemaSource source3 = YangTextSchemaSource.forResource( - "/effective-schema-context-test/baz.yang"); + final YangStatementStreamSource source1 = YangStatementStreamSource.create(YangTextSchemaSource.forResource( + "/effective-schema-context-test/foo.yang")); + final YangStatementStreamSource source2 = YangStatementStreamSource.create(YangTextSchemaSource.forResource( + "/effective-schema-context-test/bar.yang")); + final YangStatementStreamSource source3 = YangStatementStreamSource.create(YangTextSchemaSource.forResource( + "/effective-schema-context-test/baz.yang")); - final SchemaContext schemaContext = reactor.buildEffective(Arrays.asList(source1, source2, source3)); + reactor.addSources(source1, source2, source3); + final SchemaContext schemaContext = reactor.buildEffective(); assertNotNull(schemaContext); final Set dataDefinitions = schemaContext.getDataDefinitions(); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/GroupingTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/GroupingTest.java index 66000237f7..2e7ca27eb1 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/GroupingTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/GroupingTest.java @@ -13,18 +13,17 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import java.io.IOException; import java.net.URI; import java.text.ParseException; import java.util.Collection; -import java.util.Collections; -import java.util.Date; import java.util.List; import java.util.Map; import java.util.Set; import org.junit.Before; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil; +import org.opendaylight.yangtools.yang.common.QNameModule; import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode; import org.opendaylight.yangtools.yang.model.api.AugmentationSchema; import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode; @@ -36,26 +35,32 @@ import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.MustDefinition; +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.TypeDefinition; import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; import org.opendaylight.yangtools.yang.model.api.UsesNode; +import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException; import org.opendaylight.yangtools.yang.model.util.SchemaNodeUtils; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; public class GroupingTest { - private Set modules; + private SchemaContext ctx; + private Module foo; + private Module baz; @Before public void init() throws Exception { - modules = TestUtils.loadModules(getClass().getResource("/model").toURI()); - assertEquals(3, modules.size()); + ctx = TestUtils.loadModules(getClass().getResource("/model").toURI()); + foo = TestUtils.findModule(ctx, "foo").get(); + baz = TestUtils.findModule(ctx, "baz").get(); + assertEquals(3, ctx.getModules().size()); } @Test public void testRefine() { - final Module testModule = TestUtils.findModule(modules, "foo"); + final Module testModule = TestUtils.findModule(ctx, "foo").get(); final ContainerSchemaNode peer = (ContainerSchemaNode) testModule.getDataChildByName(QName.create( testModule.getQNameModule(), "peer")); final ContainerSchemaNode destination = (ContainerSchemaNode) peer.getDataChildByName(QName.create( @@ -125,7 +130,7 @@ public class GroupingTest { @Test public void testGrouping() { - final Module testModule = TestUtils.findModule(modules, "baz"); + final Module testModule = TestUtils.findModule(ctx, "baz").get(); final Set groupings = testModule.getGroupings(); assertEquals(1, groupings.size()); final GroupingDefinition grouping = groupings.iterator().next(); @@ -138,15 +143,12 @@ public class GroupingTest { // suffix _u = added by uses // suffix _g = defined in grouping - final Module baz = TestUtils.findModule(modules, "baz"); // get grouping final Set groupings = baz.getGroupings(); assertEquals(1, groupings.size()); final GroupingDefinition grouping = groupings.iterator().next(); - final Module foo = TestUtils.findModule(modules, "foo"); - // get node containing uses final ContainerSchemaNode peer = (ContainerSchemaNode) foo.getDataChildByName(QName.create( foo.getQNameModule(), "peer")); @@ -260,16 +262,11 @@ public class GroupingTest { // suffix _u = added by uses // suffix _g = defined in grouping - final Module testModule = TestUtils.findModule(modules, "baz"); - // get grouping - final Set groupings = testModule.getGroupings(); + final Set groupings = baz.getGroupings(); assertEquals(1, groupings.size()); final GroupingDefinition grouping = groupings.iterator().next(); - // get node containing uses - final Module foo = TestUtils.findModule(modules, "foo"); - // check uses final Set uses = foo.getUses(); assertEquals(1, uses.size()); @@ -281,7 +278,7 @@ public class GroupingTest { assertTrue(data_u.isAddedByUses()); final AnyXmlSchemaNode data_g = (AnyXmlSchemaNode) grouping.getDataChildByName(QName.create( - testModule.getQNameModule(), "data")); + baz.getQNameModule(), "data")); assertNotNull(data_g); assertFalse(data_g.isAddedByUses()); assertFalse(data_u.equals(data_g)); @@ -304,7 +301,7 @@ public class GroupingTest { assertFalse(intervalLeaf.isAugmenting()); final ChoiceSchemaNode how_g = (ChoiceSchemaNode) grouping.getDataChildByName(QName.create( - testModule.getQNameModule(), "how")); + baz.getQNameModule(), "how")); assertNotNull(how_g); TestUtils.checkIsAddedByUses(how_g, false); assertFalse(how_u.equals(how_g)); @@ -320,7 +317,7 @@ public class GroupingTest { assertTrue(address_u.isAddedByUses()); final LeafSchemaNode address_g = (LeafSchemaNode) grouping.getDataChildByName(QName.create( - testModule.getQNameModule(), "address")); + baz.getQNameModule(), "address")); assertNotNull(address_g); assertFalse(address_g.isAddedByUses()); assertNull(address_g.getDefault()); @@ -336,7 +333,7 @@ public class GroupingTest { TestUtils.checkIsAddedByUses(port_u, true); final ContainerSchemaNode port_g = (ContainerSchemaNode) grouping.getDataChildByName(QName.create( - testModule.getQNameModule(), "port")); + baz.getQNameModule(), "port")); assertNotNull(port_g); TestUtils.checkIsAddedByUses(port_g, false); assertFalse(port_u.equals(port_g)); @@ -348,7 +345,7 @@ public class GroupingTest { TestUtils.checkIsAddedByUses(addresses_u, true); final ListSchemaNode addresses_g = (ListSchemaNode) grouping.getDataChildByName(QName.create( - testModule.getQNameModule(), "addresses")); + baz.getQNameModule(), "addresses")); assertNotNull(addresses_g); TestUtils.checkIsAddedByUses(addresses_g, false); assertFalse(addresses_u.equals(addresses_g)); @@ -391,12 +388,11 @@ public class GroupingTest { } @Test - public void testCascadeUses() throws ReactorException, ParseException { - modules = TestUtils.loadModules(Collections.singletonList(getClass().getResourceAsStream( - "/grouping-test/cascade-uses.yang"))); - assertEquals(1, modules.size()); + public void testCascadeUses() throws ReactorException, ParseException, IOException, YangSyntaxErrorException { + ctx = TestUtils.loadModuleResources(getClass(), "/grouping-test/cascade-uses.yang"); + assertEquals(1, ctx.getModules().size()); - final Module testModule = TestUtils.findModule(modules, "cascade-uses"); + final Module testModule = TestUtils.findModule(ctx, "cascade-uses").get(); final Set groupings = testModule.getGroupings(); GroupingDefinition gu = null; @@ -435,9 +431,8 @@ public class GroupingTest { assertNotNull(gz); assertNotNull(gzz); - final URI expectedNS = URI.create("urn:grouping:cascade-uses"); - final Date expectedRev = SimpleDateFormatUtil.getRevisionFormat().parse("2013-07-18"); - final String expectedPref = "cu"; + final QNameModule expectedModule = QNameModule.create( + URI.create("urn:grouping:cascade-uses"), QName.parseRevision("2013-07-18")); SchemaPath expectedPath; // grouping-U @@ -451,7 +446,7 @@ public class GroupingTest { assertFalse(SchemaNodeUtils.getOriginalIfPossible(leafGroupingU).isPresent()); for (final DataSchemaNode childNode : childNodes) { - if (!(childNode.getQName().equals(leafGroupingU.getQName()))) { + if (!childNode.getQName().equals(leafGroupingU.getQName())) { TestUtils.checkIsAddedByUses(childNode, true); } } @@ -476,8 +471,7 @@ public class GroupingTest { // grouping-V/container-grouping-V assertNotNull(containerGroupingV); assertFalse(containerGroupingV.isAddedByUses()); - expectedPath = TestUtils.createPath(true, expectedNS, expectedRev, expectedPref, "grouping-V", - "container-grouping-V"); + expectedPath = TestUtils.createPath(true, expectedModule, "grouping-V", "container-grouping-V"); assertEquals(expectedPath, containerGroupingV.getPath()); childNodes = containerGroupingV.getChildNodes(); assertEquals(2, childNodes.size()); @@ -489,15 +483,15 @@ public class GroupingTest { final LeafSchemaNode leafXinContainerV = (LeafSchemaNode) containerGroupingV.getDataChildByName(QName.create( testModule.getQNameModule(), "leaf-grouping-X")); assertNotNull(leafXinContainerV); - expectedPath = TestUtils.createPath(true, expectedNS, expectedRev, expectedPref, "grouping-V", - "container-grouping-V", "leaf-grouping-X"); + expectedPath = TestUtils.createPath(true, expectedModule, "grouping-V", "container-grouping-V", + "leaf-grouping-X"); assertEquals(expectedPath, leafXinContainerV.getPath()); // grouping-V/container-grouping-V/leaf-grouping-Y final LeafSchemaNode leafYinContainerV = (LeafSchemaNode) containerGroupingV.getDataChildByName(QName.create( testModule.getQNameModule(), "leaf-grouping-Y")); assertNotNull(leafYinContainerV); - expectedPath = TestUtils.createPath(true, expectedNS, expectedRev, expectedPref, "grouping-V", - "container-grouping-V", "leaf-grouping-Y"); + expectedPath = TestUtils.createPath(true, expectedModule, "grouping-V", "container-grouping-V", + "leaf-grouping-Y"); assertEquals(expectedPath, leafYinContainerV.getPath()); // grouping-X @@ -509,8 +503,7 @@ public class GroupingTest { testModule.getQNameModule(), "leaf-grouping-X")); assertNotNull(leafXinGX); assertFalse(leafXinGX.isAddedByUses()); - expectedPath = TestUtils.createPath(true, expectedNS, expectedRev, expectedPref, "grouping-X", - "leaf-grouping-X"); + expectedPath = TestUtils.createPath(true, expectedModule, "grouping-X", "leaf-grouping-X"); assertEquals(expectedPath, leafXinGX.getPath()); // grouping-X/leaf-grouping-Y @@ -518,8 +511,7 @@ public class GroupingTest { testModule.getQNameModule(), "leaf-grouping-Y")); assertNotNull(leafYinGX); assertTrue(leafYinGX.isAddedByUses()); - expectedPath = TestUtils.createPath(true, expectedNS, expectedRev, expectedPref, "grouping-X", - "leaf-grouping-Y"); + expectedPath = TestUtils.createPath(true, expectedModule, "grouping-X", "leaf-grouping-Y"); assertEquals(expectedPath, leafYinGX.getPath()); // grouping-Y @@ -531,8 +523,7 @@ public class GroupingTest { testModule.getQNameModule(), "leaf-grouping-Y")); assertNotNull(leafYinGY); assertFalse(leafYinGY.isAddedByUses()); - expectedPath = TestUtils.createPath(true, expectedNS, expectedRev, expectedPref, "grouping-Y", - "leaf-grouping-Y"); + expectedPath = TestUtils.createPath(true, expectedModule, "grouping-Y", "leaf-grouping-Y"); assertEquals(expectedPath, leafYinGY.getPath()); // grouping-Z @@ -544,8 +535,7 @@ public class GroupingTest { testModule.getQNameModule(), "leaf-grouping-Z")); assertNotNull(leafZinGZ); assertFalse(leafZinGZ.isAddedByUses()); - expectedPath = TestUtils.createPath(true, expectedNS, expectedRev, expectedPref, "grouping-Z", - "leaf-grouping-Z"); + expectedPath = TestUtils.createPath(true, expectedModule, "grouping-Z", "leaf-grouping-Z"); assertEquals(expectedPath, leafZinGZ.getPath()); // grouping-ZZ @@ -557,8 +547,7 @@ public class GroupingTest { testModule.getQNameModule(), "leaf-grouping-ZZ")); assertNotNull(leafZZinGZZ); assertFalse(leafZZinGZZ.isAddedByUses()); - expectedPath = TestUtils.createPath(true, expectedNS, expectedRev, expectedPref, "grouping-ZZ", - "leaf-grouping-ZZ"); + expectedPath = TestUtils.createPath(true, expectedModule, "grouping-ZZ", "leaf-grouping-ZZ"); assertEquals(expectedPath, leafZZinGZZ.getPath()); // TEST getOriginal from grouping-U @@ -607,25 +596,11 @@ public class GroupingTest { @Test public void testAddedByUsesLeafTypeQName() throws Exception { - - final Set loadModules = TestUtils.loadModules(getClass().getResource("/added-by-uses-leaf-test") + final SchemaContext loadModules = TestUtils.loadModules(getClass().getResource("/added-by-uses-leaf-test") .toURI()); - - assertEquals(2, loadModules.size()); - - Module foo = null; - Module imp = null; - for (final Module module : loadModules) { - if (module.getName().equals("foo")) { - foo = module; - } - if (module.getName().equals("import-module")) { - imp = module; - } - } - - assertNotNull(foo); - assertNotNull(imp); + assertEquals(2, loadModules.getModules().size()); + foo = TestUtils.findModule(loadModules, "foo").get(); + final Module imp = TestUtils.findModule(loadModules, "import-module").get(); final LeafSchemaNode leaf = (LeafSchemaNode) ((ContainerSchemaNode) foo.getDataChildByName(QName.create( foo.getQNameModule(), "my-container"))) diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/OrderingTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/OrderingTest.java index bd44ddb545..612f6306bc 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/OrderingTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/OrderingTest.java @@ -11,8 +11,11 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import java.io.IOException; +import java.net.URISyntaxException; import java.util.Collection; import java.util.Set; +import org.junit.Before; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.AugmentationSchema; @@ -20,14 +23,28 @@ import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.GroupingDefinition; import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.TypeDefinition; +import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; public class OrderingTest { + private SchemaContext context; + private Module foo; + private Module bar; + private Module baz; + + @Before + public void setup() throws ReactorException, IOException, YangSyntaxErrorException, URISyntaxException { + context = TestUtils.loadModules(getClass().getResource("/model").toURI()); + foo = TestUtils.findModule(context, "foo").get(); + bar = TestUtils.findModule(context, "bar").get(); + baz = TestUtils.findModule(context, "baz").get(); + } + @Test public void testOrderingTypedef() throws Exception { - final Set modules = TestUtils.loadModules(getClass().getResource("/model").toURI()); - final Module bar = TestUtils.findModule(modules, "bar"); final Set> typedefs = bar.getTypeDefinitions(); final String[] expectedOrder = new String[] { "int32-ext1", "int32-ext2", "string-ext1", "string-ext2", "string-ext3", "string-ext4", @@ -45,8 +62,6 @@ public class OrderingTest { @Test public void testOrderingChildNodes() throws Exception { - final Set modules = TestUtils.loadModules(getClass().getResource("/model").toURI()); - final Module foo = TestUtils.findModule(modules, "foo"); AugmentationSchema augment1 = null; for (final AugmentationSchema as : foo.getAugmentations()) { if (as.getChildNodes().size() == 5) { @@ -71,9 +86,6 @@ public class OrderingTest { @Test public void testOrderingNestedChildNodes1() throws Exception { - final Set modules = TestUtils.loadModules(getClass().getResource("/model").toURI()); - final Module foo = TestUtils.findModule(modules, "foo"); - final Collection childNodes = foo.getChildNodes(); final String[] expectedOrder = new String[] { "int32-leaf", "string-leaf", "invalid-pattern-string-leaf", @@ -96,8 +108,6 @@ public class OrderingTest { @Test public void testOrderingNestedChildNodes2() throws Exception { - final Set modules = TestUtils.loadModules(getClass().getResource("/model").toURI()); - final Module baz = TestUtils.findModule(modules, "baz"); final Set groupings = baz.getGroupings(); assertEquals(1, groupings.size()); final GroupingDefinition target = groupings.iterator().next(); @@ -117,8 +127,8 @@ public class OrderingTest { @Test public void testOrderingNestedChildNodes3() throws Exception { - final Module baz = TestUtils.loadModule(getClass().getResourceAsStream( - "/ordering/foo.yang")); + final Module baz = TestUtils.loadModuleResources(getClass(), "/ordering/foo.yang") + .getModules().iterator().next(); final ContainerSchemaNode x = (ContainerSchemaNode) baz .getDataChildByName(QName.create(baz.getQNameModule(), "x")); final Collection childNodes = x.getChildNodes(); @@ -134,5 +144,4 @@ public class OrderingTest { } assertArrayEquals(expectedOrder, actualOrder); } - } diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/StmtTestUtils.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/StmtTestUtils.java index fe86a265d9..61f2615f5b 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/StmtTestUtils.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/StmtTestUtils.java @@ -8,9 +8,9 @@ package org.opendaylight.yangtools.yang.stmt; +import com.google.common.io.Files; import java.io.File; import java.io.FileFilter; -import java.io.FileNotFoundException; import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; @@ -27,18 +27,21 @@ import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.ModuleImport; 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.SourceIdentifier; import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode; import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource; +import org.opendaylight.yangtools.yang.model.repo.api.YinTextSchemaSource; import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YangStatementStreamSource; +import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YinStatementStreamSource; +import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YinTextToDomTransformer; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource; import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor; import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YinStatementSourceImpl; -import org.opendaylight.yangtools.yang.parser.util.NamedFileInputStream; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.xml.sax.SAXException; public class StmtTestUtils { @@ -191,28 +194,22 @@ public class StmtTestUtils { } public static SchemaContext parseYinSources(final String yinSourcesDirectoryPath, final StatementParserMode statementParserMode) - throws SourceException, ReactorException, FileNotFoundException, URISyntaxException { - + throws URISyntaxException, SAXException, IOException, ReactorException { final URL resourceDir = StmtTestUtils.class.getResource(yinSourcesDirectoryPath); - final File testSourcesDir = new File(resourceDir.toURI()); - - return parseYinSources(statementParserMode, testSourcesDir.listFiles(YIN_FILE_FILTER)); - } - - public static SchemaContext parseYinSources(final StatementParserMode statementParserMode, final File... files) - throws SourceException, ReactorException, FileNotFoundException { - + final File[] files = new File(resourceDir.toURI()).listFiles(YIN_FILE_FILTER); final StatementStreamSource[] sources = new StatementStreamSource[files.length]; - for (int i = 0; i < files.length; i++) { - sources[i] = new YinStatementSourceImpl(new NamedFileInputStream(files[i], files[i].getPath())); + final SourceIdentifier identifier = YinTextSchemaSource.identifierFromFilename(files[i].getName()); + + sources[i] = YinStatementStreamSource.create(YinTextToDomTransformer.transformSource( + YinTextSchemaSource.delegateForByteSource(identifier, Files.asByteSource(files[i])))); } return parseYinSources(statementParserMode, sources); } public static SchemaContext parseYinSources(final StatementParserMode statementParserMode, final StatementStreamSource... sources) - throws SourceException, ReactorException { + throws ReactorException { final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(statementParserMode); reactor.addSources(sources); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/SubstatementValidatorTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/SubstatementValidatorTest.java index 9beb2b9e29..29ee335058 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/SubstatementValidatorTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/SubstatementValidatorTest.java @@ -46,9 +46,7 @@ public class SubstatementValidatorTest { @Test public void noException() throws Exception { - final Set modules = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment") - .toURI()); - assertNotNull(modules); + assertNotNull(TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment").toURI())); } @Test @@ -83,7 +81,7 @@ public class SubstatementValidatorTest { @Test public void bug6173Test() throws Exception { final Set loadModules = TestUtils.loadModules(getClass().getResource( - "/substatement-validator/empty-element").toURI()); + "/substatement-validator/empty-element").toURI()).getModules(); assertEquals(1, loadModules.size()); } diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/TestUtils.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/TestUtils.java index 45be98ed54..0333dc2579 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/TestUtils.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/TestUtils.java @@ -11,7 +11,6 @@ import static org.junit.Assert.assertEquals; import java.io.File; import java.io.IOException; -import java.io.InputStream; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; @@ -21,8 +20,10 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.List; +import java.util.Optional; import java.util.Set; import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.common.QNameModule; import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil; import org.opendaylight.yangtools.yang.common.YangConstants; import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode; @@ -37,16 +38,19 @@ import org.opendaylight.yangtools.yang.model.api.SchemaPath; import org.opendaylight.yangtools.yang.model.api.TypeDefinition; import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException; import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource; +import org.opendaylight.yangtools.yang.model.repo.api.YinTextSchemaSource; import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YangStatementStreamSource; +import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YinStatementStreamSource; +import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YinTextToDomTransformer; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource; import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor; +import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor.BuildAction; import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YinStatementSourceImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.xml.sax.SAXException; public final class TestUtils { private static final Logger LOG = LoggerFactory.getLogger(TestUtils.class); @@ -54,8 +58,8 @@ public final class TestUtils { private TestUtils() { } - public static Set loadModules(final URI resourceDirectory) - throws SourceException, ReactorException, IOException, YangSyntaxErrorException { + public static SchemaContext loadModules(final URI resourceDirectory) + throws ReactorException, IOException, YangSyntaxErrorException { final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR .newBuild(); File[] files = new File(resourceDirectory).listFiles(); @@ -68,73 +72,44 @@ public final class TestUtils { } } - SchemaContext ctx = reactor.buildEffective(); - return ctx.getModules(); + return reactor.buildEffective(); } - public static Set loadModules(final List streams) - throws SourceException, ReactorException { - final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR - .newBuild(); - for (InputStream inputStream : streams) { - reactor.addSource(new YangStatementSourceImpl(inputStream)); + public static SchemaContext loadModuleResources(final Class refClass, final String... resourceNames) + throws IOException, ReactorException, YangSyntaxErrorException { + final BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(); + + for (String resourceName : resourceNames) { + reactor.addSource(YangStatementStreamSource.create(YangTextSchemaSource.forResource(refClass, resourceName))); } - SchemaContext ctx = reactor.buildEffective(); - return ctx.getModules(); + return reactor.buildEffective(); } - public static Set loadYinModules(final URI resourceDirectory) throws ReactorException { - final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(); + public static SchemaContext loadYinModules(final URI resourceDirectory) throws ReactorException, SAXException, + IOException { + final BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(); for (File file : new File(resourceDirectory).listFiles()) { - reactor.addSource(new YinStatementSourceImpl(file.getPath(), true)); - } - - SchemaContext ctx = reactor.buildEffective(); - return ctx.getModules(); - } - - public static Set loadYinModules(final List streams) throws SourceException, ReactorException { - final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(); - for (InputStream inputStream : streams) { - reactor.addSource(new YinStatementSourceImpl(inputStream)); + reactor.addSource(YinStatementStreamSource.create(YinTextToDomTransformer.transformSource( + YinTextSchemaSource.forFile(file)))); } - SchemaContext ctx = reactor.buildEffective(); - return ctx.getModules(); - } - - public static Module loadModule(final InputStream stream) - throws SourceException, ReactorException { - final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR - .newBuild(); - reactor.addSource(new YangStatementSourceImpl(stream)); - SchemaContext ctx = reactor.buildEffective(); - return ctx.getModules().iterator().next(); + return reactor.buildEffective(); } - public static Module loadYinModule(final InputStream stream) throws SourceException, ReactorException { + public static Module loadYinModule(final YinTextSchemaSource source) throws ReactorException, SAXException, IOException { final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(); - reactor.addSources(new YinStatementSourceImpl(stream)); + reactor.addSources(YinStatementStreamSource.create(YinTextToDomTransformer.transformSource(source))); SchemaContext ctx = reactor.buildEffective(); return ctx.getModules().iterator().next(); } - public static Module findModule(final Set modules, - final String moduleName) { - Module result = null; - for (Module module : modules) { - if (module.getName().equals(moduleName)) { - result = module; - break; - } - } - return result; + public static Optional findModule(final SchemaContext context, final String moduleName) { + return context.getModules().stream().filter(module -> moduleName.equals(module.getName())).findAny(); } - public static ModuleImport findImport(final Set imports, - final String prefix) { + public static ModuleImport findImport(final Set imports, final String prefix) { ModuleImport result = null; for (ModuleImport moduleImport : imports) { if (moduleImport.getPrefix().equals(prefix)) { @@ -145,8 +120,7 @@ public final class TestUtils { return result; } - public static TypeDefinition findTypedef( - final Set> typedefs, final String name) { + public static TypeDefinition findTypedef(final Set> typedefs, final String name) { TypeDefinition result = null; for (TypeDefinition td : typedefs) { if (td.getQName().getLocalName().equals(name)) { @@ -157,12 +131,10 @@ public final class TestUtils { return result; } - public static SchemaPath createPath(final boolean absolute, - final URI namespace, final Date revision, final String prefix, - final String... names) { - List path = new ArrayList<>(); + public static SchemaPath createPath(final boolean absolute, final QNameModule module, final String... names) { + List path = new ArrayList<>(names.length); for (String name : names) { - path.add(QName.create(namespace, revision, name)); + path.add(QName.create(module, name)); } return SchemaPath.create(path, absolute); } @@ -187,8 +159,7 @@ public final class TestUtils { * @param expected * expected value */ - public static void checkIsAugmenting(final DataSchemaNode node, - final boolean expected) { + public static void checkIsAugmenting(final DataSchemaNode node, final boolean expected) { assertEquals(expected, node.isAugmenting()); if (node instanceof DataNodeContainer) { for (DataSchemaNode child : ((DataNodeContainer) node) @@ -211,8 +182,7 @@ public final class TestUtils { * @param expected * expected value */ - public static void checkIsAddedByUses(final DataSchemaNode node, - final boolean expected) { + public static void checkIsAddedByUses(final DataSchemaNode node, final boolean expected) { assertEquals(expected, node.isAddedByUses()); if (node instanceof DataNodeContainer) { for (DataSchemaNode child : ((DataNodeContainer) node) @@ -226,8 +196,7 @@ public final class TestUtils { } } - public static void checkIsAddedByUses(final GroupingDefinition node, - final boolean expected) { + public static void checkIsAddedByUses(final GroupingDefinition node, final boolean expected) { assertEquals(expected, node.isAddedByUses()); for (DataSchemaNode child : node.getChildNodes()) { checkIsAddedByUses(child, expected); @@ -274,8 +243,7 @@ public final class TestUtils { public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath) throws SourceException, ReactorException, URISyntaxException, IOException, YangSyntaxErrorException { - URL resourceDir = StmtTestUtils.class - .getResource(yangSourcesDirectoryPath); + URL resourceDir = StmtTestUtils.class.getResource(yangSourcesDirectoryPath); File testSourcesDir = new File(resourceDir.toURI()); return parseYangSources(testSourcesDir.listFiles()); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/TwoRevisionsTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/TwoRevisionsTest.java index edd46fe848..cd1e068014 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/TwoRevisionsTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/TwoRevisionsTest.java @@ -17,7 +17,7 @@ public class TwoRevisionsTest { @Test public void testTwoRevisions() throws Exception { - Set modules = TestUtils.loadModules(getClass().getResource("/ietf").toURI()); + Set modules = TestUtils.loadModules(getClass().getResource("/ietf").toURI()).getModules(); //FIXME: following assert needs module revisions .equals() solution first assertEquals(2, TestUtils.findModules(modules, "network-topology").size()); } diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/TypesResolutionTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/TypesResolutionTest.java index 49dbba72b6..24bc9a2ba5 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/TypesResolutionTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/TypesResolutionTest.java @@ -45,7 +45,7 @@ import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementR import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline; public class TypesResolutionTest { - private Set testedModules; + private SchemaContext context; @Before public void init() throws Exception { @@ -53,15 +53,13 @@ public class TypesResolutionTest { final StatementStreamSource yangFileDependency1 = sourceForResource("/ietf/iana-timezones@2012-07-09.yang"); final StatementStreamSource yangFileDependency2 = sourceForResource("/ietf/ietf-inet-types@2010-09-24.yang"); final StatementStreamSource yangFileDependency3 = sourceForResource("/ietf/ietf-yang-types@2010-09-24.yang"); - - testedModules = TestUtils.parseYangSources(yangFile, yangFileDependency1, yangFileDependency2, - yangFileDependency3).getModules(); - assertEquals(4, testedModules.size()); + context = TestUtils.parseYangSources(yangFile, yangFileDependency1, yangFileDependency2, yangFileDependency3); + assertEquals(4, context.getModules().size()); } @Test public void testIPVersion() { - Module tested = TestUtils.findModule(testedModules, "ietf-inet-types"); + Module tested = TestUtils.findModule(context, "ietf-inet-types").get(); Set> typedefs = tested.getTypeDefinitions(); assertEquals(14, typedefs.size()); @@ -91,7 +89,7 @@ public class TypesResolutionTest { @Test public void testEnumeration() { - Module tested = TestUtils.findModule(testedModules, "custom-types-test"); + Module tested = TestUtils.findModule(context, "custom-types-test").get(); Set> typedefs = tested.getTypeDefinitions(); TypeDefinition type = TestUtils.findTypedef(typedefs, "ip-version"); @@ -122,7 +120,7 @@ public class TypesResolutionTest { @Test public void testIpAddress() { - Module tested = TestUtils.findModule(testedModules, "ietf-inet-types"); + Module tested = TestUtils.findModule(context, "ietf-inet-types").get(); Set> typedefs = tested.getTypeDefinitions(); TypeDefinition type = TestUtils.findTypedef(typedefs, "ip-address"); UnionTypeDefinition baseType = (UnionTypeDefinition) type.getBaseType(); @@ -149,7 +147,7 @@ public class TypesResolutionTest { @Test public void testDomainName() { - Module tested = TestUtils.findModule(testedModules, "ietf-inet-types"); + Module tested = TestUtils.findModule(context, "ietf-inet-types").get(); Set> typedefs = tested.getTypeDefinitions(); StringTypeDefinition type = (StringTypeDefinition) TestUtils.findTypedef(typedefs, "domain-name"); assertNotNull(type.getBaseType()); @@ -168,7 +166,7 @@ public class TypesResolutionTest { @Test public void testInstanceIdentifier1() { - Module tested = TestUtils.findModule(testedModules, "custom-types-test"); + Module tested = TestUtils.findModule(context, "custom-types-test").get(); LeafSchemaNode leaf = (LeafSchemaNode) tested.getDataChildByName( QName.create(tested.getQNameModule(), "inst-id-leaf1")); InstanceIdentifierTypeDefinition leafType = (InstanceIdentifierTypeDefinition) leaf.getType(); @@ -178,7 +176,7 @@ public class TypesResolutionTest { @Test public void testInstanceIdentifier2() { - Module tested = TestUtils.findModule(testedModules, "custom-types-test"); + Module tested = TestUtils.findModule(context, "custom-types-test").get(); LeafSchemaNode leaf = (LeafSchemaNode) tested.getDataChildByName( QName.create(tested.getQNameModule(), "inst-id-leaf2")); InstanceIdentifierTypeDefinition leafType = (InstanceIdentifierTypeDefinition) leaf.getType(); @@ -187,7 +185,7 @@ public class TypesResolutionTest { @Test public void testIdentity() { - Module tested = TestUtils.findModule(testedModules, "custom-types-test"); + Module tested = TestUtils.findModule(context, "custom-types-test").get(); Set identities = tested.getIdentities(); assertEquals(5, identities.size()); IdentitySchemaNode cryptoAlg = null; @@ -218,7 +216,7 @@ public class TypesResolutionTest { @Test public void testBitsType1() { - Module tested = TestUtils.findModule(testedModules, "custom-types-test"); + Module tested = TestUtils.findModule(context, "custom-types-test").get(); LeafSchemaNode leaf = (LeafSchemaNode) tested.getDataChildByName( QName.create(tested.getQNameModule(), "mybits")); BitsTypeDefinition leafType = (BitsTypeDefinition) leaf.getType(); @@ -240,7 +238,7 @@ public class TypesResolutionTest { @Test public void testBitsType2() { - Module tested = TestUtils.findModule(testedModules, "custom-types-test"); + Module tested = TestUtils.findModule(context, "custom-types-test").get(); Set> typedefs = tested.getTypeDefinitions(); TypeDefinition testedType = TestUtils.findTypedef(typedefs, "access-operations-type"); @@ -271,7 +269,7 @@ public class TypesResolutionTest { @Test public void testIanaTimezones() { - Module tested = TestUtils.findModule(testedModules, "iana-timezones"); + Module tested = TestUtils.findModule(context, "iana-timezones").get(); Set> typedefs = tested.getTypeDefinitions(); TypeDefinition testedType = TestUtils.findTypedef(typedefs, "iana-timezone"); @@ -302,7 +300,7 @@ public class TypesResolutionTest { @Test public void testObjectId128() { - Module tested = TestUtils.findModule(testedModules, "ietf-yang-types"); + Module tested = TestUtils.findModule(context, "ietf-yang-types").get(); Set> typedefs = tested.getTypeDefinitions(); StringTypeDefinition testedType = (StringTypeDefinition) TestUtils.findTypedef(typedefs, "object-identifier-128"); @@ -333,7 +331,7 @@ public class TypesResolutionTest { @Test public void testIdentityref() { - Module tested = TestUtils.findModule(testedModules, "custom-types-test"); + Module tested = TestUtils.findModule(context, "custom-types-test").get(); Set> typedefs = tested.getTypeDefinitions(); TypeDefinition testedType = TestUtils.findTypedef(typedefs, "service-type-ref"); IdentityrefTypeDefinition baseType = (IdentityrefTypeDefinition) testedType.getBaseType(); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/UsesAugmentTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/UsesAugmentTest.java index 4d2b1a2277..69da4c5cf4 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/UsesAugmentTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/UsesAugmentTest.java @@ -12,19 +12,17 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import java.io.FileNotFoundException; +import java.io.IOException; import java.net.URI; -import java.text.DateFormat; -import java.text.ParseException; +import java.net.URISyntaxException; import java.util.ArrayDeque; import java.util.Collection; -import java.util.Date; import java.util.Deque; import java.util.Set; import org.junit.Before; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil; +import org.opendaylight.yangtools.yang.common.QNameModule; import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode; import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; @@ -32,25 +30,27 @@ import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.NotificationDefinition; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.SchemaPath; import org.opendaylight.yangtools.yang.model.api.TypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition; +import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException; import org.opendaylight.yangtools.yang.model.util.type.BaseTypes; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; public class UsesAugmentTest { - private static final URI UG_NS = URI.create("urn:opendaylight:params:xml:ns:yang:uses-grouping"); - private static final URI GD_NS = URI.create("urn:opendaylight:params:xml:ns:yang:grouping-definitions"); - private Date UG_REV; - private Date GD_REV; - private Set modules; + private static final QNameModule UG = QNameModule.create( + URI.create("urn:opendaylight:params:xml:ns:yang:uses-grouping"), QName.parseRevision("2013-07-30")); + private static final QNameModule GD = QNameModule.create( + URI.create("urn:opendaylight:params:xml:ns:yang:grouping-definitions"), QName.parseRevision("2013-09-04")); + + private SchemaContext context; @Before - public void init() throws FileNotFoundException, ParseException { - final DateFormat simpleDateFormat = SimpleDateFormatUtil.getRevisionFormat(); - UG_REV = simpleDateFormat.parse("2013-07-30"); - GD_REV = simpleDateFormat.parse("2013-09-04"); + public void init() throws ReactorException, IOException, YangSyntaxErrorException, URISyntaxException { + context = TestUtils.loadModules(getClass().getResource("/grouping-test").toURI()); } /** @@ -111,8 +111,7 @@ public class UsesAugmentTest { */ @Test public void testAugmentInUses() throws Exception { - modules = TestUtils.loadModules(getClass().getResource("/grouping-test").toURI()); - final Module testModule = TestUtils.findModule(modules, "uses-grouping"); + final Module testModule = TestUtils.findModule(context, "uses-grouping").get(); final Deque path = new ArrayDeque<>(); @@ -121,7 +120,7 @@ public class UsesAugmentTest { assertEquals(1, notifications.size()); final NotificationDefinition pcreq = notifications.iterator().next(); assertNotNull(pcreq); - QName expectedQName = QName.create(UG_NS, UG_REV, "pcreq"); + QName expectedQName = QName.create(UG, "pcreq"); path.offer(expectedQName); SchemaPath expectedPath = SchemaPath.create(path, true); assertEquals(expectedPath, pcreq.getPath()); @@ -131,11 +130,11 @@ public class UsesAugmentTest { LeafSchemaNode version = (LeafSchemaNode) pcreq.getDataChildByName(QName.create(testModule.getQNameModule(), "version")); assertNotNull(version); - expectedQName = QName.create(UG_NS, UG_REV, "version"); + expectedQName = QName.create(UG, "version"); path.offer(expectedQName); expectedPath = SchemaPath.create(path, true); assertEquals(expectedPath, version.getPath()); - expectedQName = QName.create(UG_NS, UG_REV, "version"); + expectedQName = QName.create(UG, "version"); path.offer(expectedQName); expectedPath = SchemaPath.create(true, pcreq.getQName(), expectedQName); assertEquals(expectedPath, version.getType().getPath()); @@ -145,14 +144,14 @@ public class UsesAugmentTest { LeafSchemaNode type = (LeafSchemaNode) pcreq.getDataChildByName(QName.create(testModule.getQNameModule(), "type")); assertNotNull(type); - expectedQName = QName.create(UG_NS, UG_REV, "type"); + expectedQName = QName.create(UG, "type"); assertTrue(type.isAddedByUses()); path.pollLast(); path.pollLast(); path.offer(expectedQName); expectedPath = SchemaPath.create(path, true); assertEquals(expectedPath, type.getPath()); - expectedQName = QName.create(GD_NS, GD_REV, "int-ext"); + expectedQName = QName.create(GD, "int-ext"); path.offer(expectedQName); expectedPath = SchemaPath.create(true, expectedQName); assertEquals(expectedPath, type.getType().getPath()); @@ -163,7 +162,7 @@ public class UsesAugmentTest { final ListSchemaNode requests = (ListSchemaNode) pcreq.getDataChildByName(QName.create( testModule.getQNameModule(), "requests")); assertNotNull(requests); - expectedQName = QName.create(UG_NS, UG_REV, "requests"); + expectedQName = QName.create(UG, "requests"); assertEquals(expectedQName, requests.getQName()); path.pollLast(); path.pollLast(); @@ -177,7 +176,7 @@ public class UsesAugmentTest { final ContainerSchemaNode rp = (ContainerSchemaNode) requests.getDataChildByName(QName.create( testModule.getQNameModule(), "rp")); assertNotNull(rp); - expectedQName = QName.create(UG_NS, UG_REV, "rp"); + expectedQName = QName.create(UG, "rp"); path.offer(expectedQName); expectedPath = SchemaPath.create(path, true); assertEquals(expectedPath, rp.getPath()); @@ -188,7 +187,7 @@ public class UsesAugmentTest { LeafSchemaNode processingRule = (LeafSchemaNode) rp.getDataChildByName(QName.create( testModule.getQNameModule(), "processing-rule")); assertNotNull(processingRule); - expectedQName = QName.create(UG_NS, UG_REV, "processing-rule"); + expectedQName = QName.create(UG, "processing-rule"); assertEquals(expectedQName, processingRule.getQName()); path.offer(expectedQName); expectedPath = SchemaPath.create(path, true); @@ -199,7 +198,7 @@ public class UsesAugmentTest { LeafSchemaNode ignore = (LeafSchemaNode) rp.getDataChildByName(QName.create(testModule.getQNameModule(), "ignore")); assertNotNull(ignore); - expectedQName = QName.create(UG_NS, UG_REV, "ignore"); + expectedQName = QName.create(UG, "ignore"); assertEquals(expectedQName, ignore.getQName()); path.pollLast(); path.offer(expectedQName); @@ -211,13 +210,13 @@ public class UsesAugmentTest { final LeafSchemaNode priority = (LeafSchemaNode) rp.getDataChildByName(QName.create( testModule.getQNameModule(), "priority")); assertNotNull(priority); - expectedQName = QName.create(UG_NS, UG_REV, "priority"); + expectedQName = QName.create(UG, "priority"); assertEquals(expectedQName, priority.getQName()); path.pollLast(); path.offer(expectedQName); expectedPath = SchemaPath.create(path, true); assertEquals(expectedPath, priority.getPath()); - expectedQName = QName.create(UG_NS, UG_REV, "uint8"); + expectedQName = QName.create(UG, "uint8"); path.offer(expectedQName); expectedPath = SchemaPath.create(path, true); // TODO @@ -228,7 +227,7 @@ public class UsesAugmentTest { ContainerSchemaNode box = (ContainerSchemaNode) rp.getDataChildByName(QName.create(testModule.getQNameModule(), "box")); assertNotNull(box); - expectedQName = QName.create(UG_NS, UG_REV, "box"); + expectedQName = QName.create(UG, "box"); assertEquals(expectedQName, box.getQName()); path.pollLast(); path.pollLast(); @@ -240,7 +239,7 @@ public class UsesAugmentTest { final ContainerSchemaNode order = (ContainerSchemaNode) box.getDataChildByName(QName.create( testModule.getQNameModule(), "order")); assertNotNull(order); - expectedQName = QName.create(UG_NS, UG_REV, "order"); + expectedQName = QName.create(UG, "order"); assertEquals(expectedQName, order.getQName()); path.offer(expectedQName); expectedPath = SchemaPath.create(path, true); @@ -252,7 +251,7 @@ public class UsesAugmentTest { final LeafSchemaNode delete = (LeafSchemaNode) order.getDataChildByName(QName.create( testModule.getQNameModule(), "delete")); assertNotNull(delete); - expectedQName = QName.create(UG_NS, UG_REV, "delete"); + expectedQName = QName.create(UG, "delete"); assertEquals(expectedQName, delete.getQName()); path.offer(expectedQName); expectedPath = SchemaPath.create(path, true); @@ -263,7 +262,7 @@ public class UsesAugmentTest { final LeafSchemaNode setup = (LeafSchemaNode) order.getDataChildByName(QName.create( testModule.getQNameModule(), "setup")); assertNotNull(setup); - expectedQName = QName.create(UG_NS, UG_REV, "setup"); + expectedQName = QName.create(UG, "setup"); assertEquals(expectedQName, setup.getQName()); path.pollLast(); path.offer(expectedQName); @@ -275,7 +274,7 @@ public class UsesAugmentTest { final ContainerSchemaNode pke = (ContainerSchemaNode) requests.getDataChildByName(QName.create( testModule.getQNameModule(), "path-key-expansion")); assertNotNull(pke); - expectedQName = QName.create(UG_NS, UG_REV, "path-key-expansion"); + expectedQName = QName.create(UG, "path-key-expansion"); assertEquals(expectedQName, pke.getQName()); path.pollLast(); path.pollLast(); @@ -289,7 +288,7 @@ public class UsesAugmentTest { final ContainerSchemaNode pathKey = (ContainerSchemaNode) pke.getDataChildByName(QName.create( testModule.getQNameModule(), "path-key")); assertNotNull(pathKey); - expectedQName = QName.create(UG_NS, UG_REV, "path-key"); + expectedQName = QName.create(UG, "path-key"); assertEquals(expectedQName, pathKey.getQName()); path.offer(expectedQName); expectedPath = SchemaPath.create(path, true); @@ -300,7 +299,7 @@ public class UsesAugmentTest { processingRule = (LeafSchemaNode) pathKey.getDataChildByName(QName.create(testModule.getQNameModule(), "processing-rule")); assertNotNull(processingRule); - expectedQName = QName.create(UG_NS, UG_REV, "processing-rule"); + expectedQName = QName.create(UG, "processing-rule"); assertEquals(expectedQName, processingRule.getQName()); path.offer(expectedQName); expectedPath = SchemaPath.create(path, true); @@ -310,7 +309,7 @@ public class UsesAugmentTest { // * |-- |-- |-- |-- leaf ignore ignore = (LeafSchemaNode) pathKey.getDataChildByName(QName.create(testModule.getQNameModule(), "ignore")); assertNotNull(ignore); - expectedQName = QName.create(UG_NS, UG_REV, "ignore"); + expectedQName = QName.create(UG, "ignore"); assertEquals(expectedQName, ignore.getQName()); path.pollLast(); path.offer(expectedQName); @@ -322,7 +321,7 @@ public class UsesAugmentTest { final ListSchemaNode pathKeys = (ListSchemaNode) pathKey.getDataChildByName(QName.create( testModule.getQNameModule(), "path-keys")); assertNotNull(pathKeys); - expectedQName = QName.create(UG_NS, UG_REV, "path-keys"); + expectedQName = QName.create(UG, "path-keys"); assertEquals(expectedQName, pathKeys.getQName()); path.pollLast(); path.offer(expectedQName); @@ -334,7 +333,7 @@ public class UsesAugmentTest { // * |-- |-- |-- |-- |-- leaf version version = (LeafSchemaNode) pathKeys.getDataChildByName(QName.create(testModule.getQNameModule(), "version")); assertNotNull(version); - expectedQName = QName.create(UG_NS, UG_REV, "version"); + expectedQName = QName.create(UG, "version"); assertEquals(expectedQName, version.getQName()); path.offer(expectedQName); expectedPath = SchemaPath.create(path, true); @@ -346,7 +345,7 @@ public class UsesAugmentTest { // * |-- |-- |-- |-- |-- leaf type type = (LeafSchemaNode) pathKeys.getDataChildByName(QName.create(testModule.getQNameModule(), "type")); assertNotNull(type); - expectedQName = QName.create(UG_NS, UG_REV, "type"); + expectedQName = QName.create(UG, "type"); assertEquals(expectedQName, type.getQName()); path.pollLast(); path.offer(expectedQName); @@ -359,7 +358,7 @@ public class UsesAugmentTest { final ContainerSchemaNode sc = (ContainerSchemaNode) requests.getDataChildByName(QName.create( testModule.getQNameModule(), "segment-computation")); assertNotNull(sc); - expectedQName = QName.create(UG_NS, UG_REV, "segment-computation"); + expectedQName = QName.create(UG, "segment-computation"); assertEquals(expectedQName, sc.getQName()); path.pollLast(); path.pollLast(); @@ -373,7 +372,7 @@ public class UsesAugmentTest { final ContainerSchemaNode p2p = (ContainerSchemaNode) sc.getDataChildByName(QName.create( testModule.getQNameModule(), "p2p")); assertNotNull(p2p); - expectedQName = QName.create(UG_NS, UG_REV, "p2p"); + expectedQName = QName.create(UG, "p2p"); assertEquals(expectedQName, p2p.getQName()); path.offer(expectedQName); expectedPath = SchemaPath.create(path, true); @@ -383,7 +382,7 @@ public class UsesAugmentTest { final ContainerSchemaNode endpoints = (ContainerSchemaNode) p2p.getDataChildByName(QName.create( testModule.getQNameModule(), "endpoints")); assertNotNull(endpoints); - expectedQName = QName.create(UG_NS, UG_REV, "endpoints"); + expectedQName = QName.create(UG, "endpoints"); assertEquals(expectedQName, endpoints.getQName()); path.offer(expectedQName); expectedPath = SchemaPath.create(path, true); @@ -393,7 +392,7 @@ public class UsesAugmentTest { processingRule = (LeafSchemaNode) endpoints.getDataChildByName(QName.create(testModule.getQNameModule(), "processing-rule")); assertNotNull(processingRule); - expectedQName = QName.create(UG_NS, UG_REV, "processing-rule"); + expectedQName = QName.create(UG, "processing-rule"); assertEquals(expectedQName, processingRule.getQName()); path.offer(expectedQName); expectedPath = SchemaPath.create(path, true); @@ -403,7 +402,7 @@ public class UsesAugmentTest { // * |-- |-- |-- |-- |-- leaf ignore ignore = (LeafSchemaNode) endpoints.getDataChildByName(QName.create(testModule.getQNameModule(), "ignore")); assertNotNull(ignore); - expectedQName = QName.create(UG_NS, UG_REV, "ignore"); + expectedQName = QName.create(UG, "ignore"); assertEquals(expectedQName, ignore.getQName()); path.pollLast(); path.offer(expectedQName); @@ -414,7 +413,7 @@ public class UsesAugmentTest { // * |-- |-- |-- |-- |-- container box box = (ContainerSchemaNode) endpoints.getDataChildByName(QName.create(testModule.getQNameModule(), "box")); assertNotNull(box); - expectedQName = QName.create(UG_NS, UG_REV, "box"); + expectedQName = QName.create(UG, "box"); assertEquals(expectedQName, box.getQName()); path.pollLast(); path.offer(expectedQName); @@ -425,7 +424,7 @@ public class UsesAugmentTest { final ChoiceSchemaNode af = (ChoiceSchemaNode) endpoints.getDataChildByName(QName.create( testModule.getQNameModule(), "address-family")); assertNotNull(af); - expectedQName = QName.create(UG_NS, UG_REV, "address-family"); + expectedQName = QName.create(UG, "address-family"); assertEquals(expectedQName, af.getQName()); path.pollLast(); path.offer(expectedQName); @@ -436,7 +435,7 @@ public class UsesAugmentTest { final ContainerSchemaNode reportedRoute = (ContainerSchemaNode) p2p.getDataChildByName(QName.create( testModule.getQNameModule(), "reported-route")); assertNotNull(reportedRoute); - expectedQName = QName.create(UG_NS, UG_REV, "reported-route"); + expectedQName = QName.create(UG, "reported-route"); assertEquals(expectedQName, reportedRoute.getQName()); path.pollLast(); path.pollLast(); @@ -448,7 +447,7 @@ public class UsesAugmentTest { processingRule = (LeafSchemaNode) reportedRoute.getDataChildByName(QName.create(testModule.getQNameModule(), "processing-rule")); assertNotNull(processingRule); - expectedQName = QName.create(UG_NS, UG_REV, "processing-rule"); + expectedQName = QName.create(UG, "processing-rule"); assertEquals(expectedQName, processingRule.getQName()); path.offer(expectedQName); expectedPath = SchemaPath.create(path, true); @@ -458,7 +457,7 @@ public class UsesAugmentTest { // * |-- |-- |-- |-- |-- leaf ignore ignore = (LeafSchemaNode) reportedRoute.getDataChildByName(QName.create(testModule.getQNameModule(), "ignore")); assertNotNull(ignore); - expectedQName = QName.create(UG_NS, UG_REV, "ignore"); + expectedQName = QName.create(UG, "ignore"); assertEquals(expectedQName, ignore.getQName()); path.pollLast(); path.offer(expectedQName); @@ -470,7 +469,7 @@ public class UsesAugmentTest { final ListSchemaNode subobjects = (ListSchemaNode) reportedRoute.getDataChildByName(QName.create( testModule.getQNameModule(), "subobjects")); assertNotNull(subobjects); - expectedQName = QName.create(UG_NS, UG_REV, "subobjects"); + expectedQName = QName.create(UG, "subobjects"); assertEquals(expectedQName, subobjects.getQName()); path.pollLast(); path.offer(expectedQName); @@ -481,7 +480,7 @@ public class UsesAugmentTest { ContainerSchemaNode bandwidth = (ContainerSchemaNode) reportedRoute.getDataChildByName(QName.create( testModule.getQNameModule(), "bandwidth")); assertNotNull(bandwidth); - expectedQName = QName.create(UG_NS, UG_REV, "bandwidth"); + expectedQName = QName.create(UG, "bandwidth"); assertEquals(expectedQName, bandwidth.getQName()); path.pollLast(); path.offer(expectedQName); @@ -492,7 +491,7 @@ public class UsesAugmentTest { bandwidth = (ContainerSchemaNode) p2p .getDataChildByName(QName.create(testModule.getQNameModule(), "bandwidth")); assertNotNull(bandwidth); - expectedQName = QName.create(UG_NS, UG_REV, "bandwidth"); + expectedQName = QName.create(UG, "bandwidth"); assertEquals(expectedQName, bandwidth.getQName()); path.pollLast(); path.pollLast(); @@ -504,7 +503,7 @@ public class UsesAugmentTest { processingRule = (LeafSchemaNode) bandwidth.getDataChildByName(QName.create(testModule.getQNameModule(), "processing-rule")); assertNotNull(processingRule); - expectedQName = QName.create(UG_NS, UG_REV, "processing-rule"); + expectedQName = QName.create(UG, "processing-rule"); assertEquals(expectedQName, processingRule.getQName()); path.offer(expectedQName); expectedPath = SchemaPath.create(path, true); @@ -514,7 +513,7 @@ public class UsesAugmentTest { // * |-- |-- |-- |-- |-- leaf ignore ignore = (LeafSchemaNode) bandwidth.getDataChildByName(QName.create(testModule.getQNameModule(), "ignore")); assertNotNull(ignore); - expectedQName = QName.create(UG_NS, UG_REV, "ignore"); + expectedQName = QName.create(UG, "ignore"); assertEquals(expectedQName, ignore.getQName()); path.pollLast(); path.offer(expectedQName); @@ -526,7 +525,7 @@ public class UsesAugmentTest { final ContainerSchemaNode bandwidthInner = (ContainerSchemaNode) bandwidth.getDataChildByName(QName.create( testModule.getQNameModule(), "bandwidth")); assertNotNull(bandwidthInner); - expectedQName = QName.create(UG_NS, UG_REV, "bandwidth"); + expectedQName = QName.create(UG, "bandwidth"); assertEquals(expectedQName, bandwidth.getQName()); path.pollLast(); path.offer(expectedQName); @@ -537,7 +536,7 @@ public class UsesAugmentTest { final ListSchemaNode svec = (ListSchemaNode) pcreq.getDataChildByName(QName.create(testModule.getQNameModule(), "svec")); assertNotNull(svec); - expectedQName = QName.create(UG_NS, UG_REV, "svec"); + expectedQName = QName.create(UG, "svec"); assertEquals(expectedQName, svec.getQName()); path.pollLast(); path.pollLast(); @@ -552,7 +551,7 @@ public class UsesAugmentTest { final LeafSchemaNode linkDiverse = (LeafSchemaNode) svec.getDataChildByName(QName.create( testModule.getQNameModule(), "link-diverse")); assertNotNull(linkDiverse); - expectedQName = QName.create(UG_NS, UG_REV, "link-diverse"); + expectedQName = QName.create(UG, "link-diverse"); assertEquals(expectedQName, linkDiverse.getQName()); path.offer(expectedQName); expectedPath = SchemaPath.create(path, true); @@ -563,7 +562,7 @@ public class UsesAugmentTest { processingRule = (LeafSchemaNode) svec.getDataChildByName(QName.create(testModule.getQNameModule(), "processing-rule")); assertNotNull(processingRule); - expectedQName = QName.create(UG_NS, UG_REV, "processing-rule"); + expectedQName = QName.create(UG, "processing-rule"); assertEquals(expectedQName, processingRule.getQName()); path.pollLast(); path.offer(expectedQName); @@ -574,7 +573,7 @@ public class UsesAugmentTest { // * |-- |-- leaf ignore ignore = (LeafSchemaNode) svec.getDataChildByName(QName.create(testModule.getQNameModule(), "ignore")); assertNotNull(ignore); - expectedQName = QName.create(UG_NS, UG_REV, "ignore"); + expectedQName = QName.create(UG, "ignore"); assertEquals(expectedQName, ignore.getQName()); path.pollLast(); path.offer(expectedQName); @@ -586,7 +585,7 @@ public class UsesAugmentTest { final ListSchemaNode metric = (ListSchemaNode) svec.getDataChildByName(QName.create( testModule.getQNameModule(), "metric")); assertNotNull(metric); - expectedQName = QName.create(UG_NS, UG_REV, "metric"); + expectedQName = QName.create(UG, "metric"); assertEquals(expectedQName, metric.getQName()); path.pollLast(); path.offer(expectedQName); @@ -597,7 +596,7 @@ public class UsesAugmentTest { final LeafSchemaNode metricType = (LeafSchemaNode) metric.getDataChildByName(QName.create( testModule.getQNameModule(), "metric-type")); assertNotNull(metricType); - expectedQName = QName.create(UG_NS, UG_REV, "metric-type"); + expectedQName = QName.create(UG, "metric-type"); assertEquals(expectedQName, metricType.getQName()); path.offer(expectedQName); expectedPath = SchemaPath.create(path, true); @@ -607,7 +606,7 @@ public class UsesAugmentTest { // * |-- |-- |-- box box = (ContainerSchemaNode) metric.getDataChildByName(QName.create(testModule.getQNameModule(), "box")); assertNotNull(box); - expectedQName = QName.create(UG_NS, UG_REV, "box"); + expectedQName = QName.create(UG, "box"); assertEquals(expectedQName, box.getQName()); path.pollLast(); path.offer(expectedQName); @@ -618,7 +617,7 @@ public class UsesAugmentTest { processingRule = (LeafSchemaNode) metric.getDataChildByName(QName.create(testModule.getQNameModule(), "processing-rule")); assertNotNull(processingRule); - expectedQName = QName.create(UG_NS, UG_REV, "processing-rule"); + expectedQName = QName.create(UG, "processing-rule"); assertEquals(expectedQName, processingRule.getQName()); path.pollLast(); path.offer(expectedQName); @@ -629,7 +628,7 @@ public class UsesAugmentTest { // * |-- |-- |-- leaf ignore ignore = (LeafSchemaNode) metric.getDataChildByName(QName.create(testModule.getQNameModule(), "ignore")); assertNotNull(ignore); - expectedQName = QName.create(UG_NS, UG_REV, "ignore"); + expectedQName = QName.create(UG, "ignore"); assertEquals(expectedQName, ignore.getQName()); path.pollLast(); path.offer(expectedQName); @@ -641,8 +640,7 @@ public class UsesAugmentTest { @Test public void testTypedefs() throws Exception { - modules = TestUtils.loadModules(getClass().getResource("/grouping-test").toURI()); - final Module testModule = TestUtils.findModule(modules, "grouping-definitions"); + final Module testModule = TestUtils.findModule(context, "grouping-definitions").get(); final Set> types = testModule.getTypeDefinitions(); TypeDefinition intExt = null; @@ -653,7 +651,7 @@ public class UsesAugmentTest { } assertNotNull(intExt); - SchemaPath expectedPath = SchemaPath.create(true, QName.create(GD_NS, GD_REV, "int-ext")); + SchemaPath expectedPath = SchemaPath.create(true, QName.create(GD, "int-ext")); assertEquals(expectedPath, intExt.getPath()); final UnionTypeDefinition union = (UnionTypeDefinition) intExt.getBaseType(); @@ -670,8 +668,7 @@ public class UsesAugmentTest { assertNotNull(uint8); assertNotNull(pv); - expectedPath = SchemaPath.create(true, QName.create(GD_NS, GD_REV, "int-ext"), - QName.create(GD_NS, GD_REV, "union")); + expectedPath = SchemaPath.create(true, QName.create(GD, "int-ext"), QName.create(GD, "union")); assertEquals(expectedPath, union.getPath()); } diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserIdentityTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserIdentityTest.java index a432b85a3b..4b2d78add2 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserIdentityTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserIdentityTest.java @@ -11,27 +11,22 @@ package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.InputStream; -import java.net.URISyntaxException; +import java.io.IOException; import java.util.Set; 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; -import org.opendaylight.yangtools.yang.parser.util.NamedFileInputStream; public class YangParserIdentityTest { // base identity name equals identity name @Test(expected = SomeModifiersUnresolvedException.class) - public void testParsingIdentityTestModule() throws URISyntaxException, ReactorException, FileNotFoundException { - File yang = new File(getClass().getResource("/identity/identitytest.yang").toURI()); - InputStream stream = new NamedFileInputStream(yang, yang.getPath()); + public void testParsingIdentityTestModule() throws IOException, ReactorException, YangSyntaxErrorException { try { - TestUtils.loadModule(stream); + TestUtils.loadModuleResources(getClass(), "/identity/identitytest.yang"); } catch (SomeModifiersUnresolvedException e) { StmtTestUtils.log(e, " "); throw e; @@ -40,12 +35,9 @@ public class YangParserIdentityTest { // same module prefixed base identity name equals identity name @Test(expected = SomeModifiersUnresolvedException.class) - public void testParsingPrefixIdentityTestModule() throws URISyntaxException, - ReactorException, FileNotFoundException { - File yang = new File(getClass().getResource("/identity/prefixidentitytest.yang").toURI()); - InputStream stream = new NamedFileInputStream(yang, yang.getPath()); + public void testParsingPrefixIdentityTestModule() throws IOException, ReactorException, YangSyntaxErrorException { try { - TestUtils.loadModule(stream); + TestUtils.loadModuleResources(getClass(), "/identity/prefixidentitytest.yang"); } catch (SomeModifiersUnresolvedException e) { StmtTestUtils.log(e, " "); throw e; @@ -56,8 +48,8 @@ public class YangParserIdentityTest { // prefix differs @Test public void testParsingImportPrefixIdentityTestModule() throws Exception { - Set modules = TestUtils.loadModules(getClass().getResource("/identity/import").toURI()); - Module module = TestUtils.findModule(modules, "prefiximportidentitytest"); + Module module = TestUtils.findModule(TestUtils.loadModules(getClass().getResource("/identity/import").toURI()), + "prefiximportidentitytest").get(); Set imports = module.getImports(); assertEquals(imports.size(), 1); ModuleImport dummy = TestUtils.findImport(imports, "dummy"); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserNegativeTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserNegativeTest.java index 45c74ba6b8..dbc00013dd 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserNegativeTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserNegativeTest.java @@ -7,26 +7,21 @@ */ package org.opendaylight.yangtools.yang.stmt; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import com.google.common.base.Throwables; import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.InputStream; +import java.io.IOException; import java.io.PrintStream; import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException; import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException; -import org.opendaylight.yangtools.yang.parser.util.NamedFileInputStream; public class YangParserNegativeTest { @@ -45,13 +40,10 @@ public class YangParserNegativeTest { } @Test - public void testInvalidImport() throws Exception { - final File yang = new File(getClass().getResource("/negative-scenario/testfile1.yang").toURI()); + public void testInvalidImport() throws IOException, ReactorException, YangSyntaxErrorException { try { - try (InputStream stream = new NamedFileInputStream(yang, yang.getPath())) { - TestUtils.loadModule(stream); - fail("SomeModifiersUnresolvedException should be thrown"); - } + TestUtils.loadModuleResources(getClass(), "/negative-scenario/testfile1.yang"); + fail("SomeModifiersUnresolvedException should be thrown"); } catch (final SomeModifiersUnresolvedException e) { final Throwable rootCause = Throwables.getRootCause(e); assertTrue(rootCause instanceof InferenceException); @@ -61,13 +53,10 @@ public class YangParserNegativeTest { } @Test - public void testTypeNotFound() throws Exception { - final File yang = new File(getClass().getResource("/negative-scenario/testfile2.yang").toURI()); + public void testTypeNotFound() throws IOException, ReactorException, YangSyntaxErrorException { try { - try (InputStream stream = new NamedFileInputStream(yang, yang.getPath())) { - TestUtils.loadModule(stream); - fail("InferenceException should be thrown"); - } + TestUtils.loadModuleResources(getClass(), "/negative-scenario/testfile2.yang"); + fail("InferenceException should be thrown"); } catch (final SomeModifiersUnresolvedException e) { final Throwable rootCause = Throwables.getRootCause(e); assertTrue(rootCause instanceof InferenceException); @@ -77,20 +66,12 @@ public class YangParserNegativeTest { } @Test - public void testInvalidAugmentTarget() throws Exception { - final File yang1 = new File(getClass().getResource("/negative-scenario/testfile0.yang").toURI()); - final File yang2 = new File(getClass().getResource("/negative-scenario/testfile3.yang").toURI()); + public void testInvalidAugmentTarget() throws IOException, ReactorException, YangSyntaxErrorException { try { - final List streams = new ArrayList<>(2); - try (InputStream testFile0 = new NamedFileInputStream(yang1, yang1.getPath())) { - streams.add(testFile0); - try (InputStream testFile3 = new NamedFileInputStream(yang2, yang2.getPath())) { - streams.add(testFile3); - assertEquals("Expected loaded files count is 2", 2, streams.size()); - TestUtils.loadModules(streams); - fail("SomeModifiersUnresolvedException should be thrown"); - } - } + TestUtils.loadModuleResources(getClass(), + "/negative-scenario/testfile0.yang", + "/negative-scenario/testfile3.yang"); + fail("SomeModifiersUnresolvedException should be thrown"); } catch (final SomeModifiersUnresolvedException e) { final Throwable rootCause = Throwables.getRootCause(e); assertTrue(rootCause instanceof InferenceException); @@ -100,13 +81,10 @@ public class YangParserNegativeTest { } @Test - public void testInvalidRefine() throws Exception { - final File yang = new File(getClass().getResource("/negative-scenario/testfile4.yang").toURI()); + public void testInvalidRefine() throws IOException, ReactorException, YangSyntaxErrorException { try { - try (InputStream stream = new NamedFileInputStream(yang, yang.getPath())) { - TestUtils.loadModule(stream); - fail("SourceException should be thrown"); - } + TestUtils.loadModuleResources(getClass(), "/negative-scenario/testfile4.yang"); + fail("ReactorException should be thrown"); } catch (final ReactorException e) { assertTrue(e.getCause().getMessage().contains("Error in module 'test4' in the refine of uses " + "'Relative{path=[(urn:simple.container.demo?revision=1970-01-01)node]}': can not perform refine of 'PRESENCE' for" + @@ -115,39 +93,30 @@ public class YangParserNegativeTest { } @Test - public void testInvalidLength() throws Exception { - final File yang = new File(getClass().getResource("/negative-scenario/testfile5.yang").toURI()); + public void testInvalidLength() throws IOException, YangSyntaxErrorException { try { - try (InputStream stream = new NamedFileInputStream(yang, yang.getPath())) { - TestUtils.loadModule(stream); - fail("YangParseException should be thrown"); - } + TestUtils.loadModuleResources(getClass(), "/negative-scenario/testfile5.yang"); + fail("ReactorException should be thrown"); } catch (final ReactorException e) { assertTrue(e.getCause().getMessage().contains("Invalid length constraint: <4, 10>")); } } @Test - public void testInvalidRange() throws Exception { - final File yang = new File(getClass().getResource("/negative-scenario/testfile6.yang").toURI()); + public void testInvalidRange() throws IOException, YangSyntaxErrorException { try { - try (InputStream stream = new NamedFileInputStream(yang, yang.getPath())) { - TestUtils.loadModule(stream); - fail("Exception should be thrown"); - } + TestUtils.loadModuleResources(getClass(), "/negative-scenario/testfile6.yang"); + fail("ReactorException should be thrown"); } catch (final ReactorException e) { assertTrue(e.getCause().getMessage().contains("Invalid range constraint: <5, 20>")); } } @Test - public void testDuplicateContainer() throws Exception { - final File yang = new File(getClass().getResource("/negative-scenario/duplicity/container.yang").toURI()); + public void testDuplicateContainer() throws IOException, YangSyntaxErrorException { try { - try (InputStream stream = new NamedFileInputStream(yang, yang.getPath())) { - TestUtils.loadModule(stream); - fail("SourceException should be thrown"); - } + TestUtils.loadModuleResources(getClass(), "/negative-scenario/duplicity/container.yang"); + fail("SourceException should be thrown"); } catch (final ReactorException e) { final String expected = "Error in module 'container': cannot add '(urn:simple.container" + ".demo?revision=1970-01-01)foo'. Node name collision: '(urn:simple.container" + @@ -157,13 +126,10 @@ public class YangParserNegativeTest { } @Test - public void testDuplicateContainerList() throws Exception { - final File yang = new File(getClass().getResource("/negative-scenario/duplicity/container-list.yang").toURI()); + public void testDuplicateContainerList() throws IOException, YangSyntaxErrorException { try { - try (InputStream stream = new NamedFileInputStream(yang, yang.getPath())) { - TestUtils.loadModule(stream); - fail("SourceException should be thrown"); - } + TestUtils.loadModuleResources(getClass(), "/negative-scenario/duplicity/container-list.yang"); + fail("SourceException should be thrown"); } catch (final ReactorException e) { final String expected = "Error in module 'container-list': cannot add '(urn:simple.container" + ".demo?revision=1970-01-01)foo'. Node name collision: '(urn:simple.container" + @@ -173,13 +139,10 @@ public class YangParserNegativeTest { } @Test - public void testDuplicateContainerLeaf() throws Exception { - final File yang = new File(getClass().getResource("/negative-scenario/duplicity/container-leaf.yang").toURI()); + public void testDuplicateContainerLeaf() throws IOException, YangSyntaxErrorException { try { - try (InputStream stream = new NamedFileInputStream(yang, yang.getPath())) { - TestUtils.loadModule(stream); - fail("SourceException should be thrown"); - } + TestUtils.loadModuleResources(getClass(), "/negative-scenario/duplicity/container-leaf.yang"); + fail("SourceException should be thrown"); } catch (final ReactorException e) { final String expected = "Error in module 'container-leaf': cannot add '(urn:simple.container" + ".demo?revision=1970-01-01)foo'. Node name collision: '(urn:simple.container" + @@ -189,13 +152,10 @@ public class YangParserNegativeTest { } @Test - public void testDuplicateTypedef() throws Exception { - final File yang = new File(getClass().getResource("/negative-scenario/duplicity/typedef.yang").toURI()); + public void testDuplicateTypedef() throws IOException, YangSyntaxErrorException { try { - try (InputStream stream = new NamedFileInputStream(yang, yang.getPath())) { - TestUtils.loadModule(stream); - fail("SourceException should be thrown"); - } + TestUtils.loadModuleResources(getClass(), "/negative-scenario/duplicity/typedef.yang"); + fail("SourceException should be thrown"); } catch (final ReactorException e) { assertTrue(e.getCause().getMessage().startsWith( "Duplicate name for typedef (urn:simple.container.demo?revision=1970-01-01)int-ext [at")); @@ -203,55 +163,42 @@ public class YangParserNegativeTest { } @Test - public void testDuplicityInAugmentTarget1() throws Exception { - final File yang1 = new File(getClass().getResource("/negative-scenario/duplicity/augment0.yang").toURI()); - final File yang2 = new File(getClass().getResource("/negative-scenario/duplicity/augment1.yang").toURI()); - try (InputStream stream1 = new NamedFileInputStream(yang1, yang1.getPath()); - InputStream stream2 = new NamedFileInputStream(yang2, yang2.getPath())) { - TestUtils.loadModules(Arrays.asList(stream1, stream2)); - testLog = output.toString(); - assertTrue(testLog.contains("An augment cannot add node named 'id' because this name is already used in target")); - } + public void testDuplicityInAugmentTarget1() throws IOException, ReactorException, YangSyntaxErrorException { + TestUtils.loadModuleResources(getClass(), + "/negative-scenario/duplicity/augment0.yang", + "/negative-scenario/duplicity/augment1.yang"); + testLog = output.toString(); + assertTrue(testLog.contains("An augment cannot add node named 'id' because this name is already used in target")); } @Test - public void testDuplicityInAugmentTarget2() throws Exception { - final File yang1 = new File(getClass().getResource("/negative-scenario/duplicity/augment0.yang").toURI()); - final File yang2 = new File(getClass().getResource("/negative-scenario/duplicity/augment2.yang").toURI()); - try (InputStream stream1 = new NamedFileInputStream(yang1, yang1.getPath()); - InputStream stream2 = new NamedFileInputStream(yang2, yang2.getPath())) { - TestUtils.loadModules(Arrays.asList(stream1, stream2)); - testLog = output.toString(); - assertTrue(testLog.contains("An augment cannot add node named 'delta' because this name is already used in target")); - } + public void testDuplicityInAugmentTarget2() throws IOException, ReactorException, YangSyntaxErrorException { + TestUtils.loadModuleResources(getClass(), + "/negative-scenario/duplicity/augment0.yang", + "/negative-scenario/duplicity/augment2.yang"); + testLog = output.toString(); + assertTrue(testLog.contains("An augment cannot add node named 'delta' because this name is already used in target")); } @Test - public void testMandatoryInAugment() throws Exception { - final File yang1 = new File(getClass().getResource("/negative-scenario/testfile8.yang").toURI()); - final File yang2 = new File(getClass().getResource("/negative-scenario/testfile7.yang").toURI()); - try (InputStream stream1 = new NamedFileInputStream(yang1, yang1.getPath()); - InputStream stream2 = new NamedFileInputStream(yang2, yang2.getPath())) { - TestUtils.loadModules(Arrays.asList(stream1, stream2)); - testLog = output.toString(); - assertTrue(testLog.contains( - "An augment cannot add node 'linkleaf' because it is mandatory and in module different than target")); - } + public void testMandatoryInAugment() throws IOException, ReactorException, YangSyntaxErrorException { + TestUtils.loadModuleResources(getClass(), + "/negative-scenario/testfile8.yang", + "/negative-scenario/testfile7.yang"); + testLog = output.toString(); + assertTrue(testLog.contains( + "An augment cannot add node 'linkleaf' because it is mandatory and in module different than target")); } @Test - public void testInvalidListKeyDefinition() throws Exception { - final File yang1 = new File(getClass().getResource("/negative-scenario/invalid-list-key-def.yang").toURI()); + public void testInvalidListKeyDefinition() throws IOException, YangSyntaxErrorException { try { - try (InputStream stream1 = new NamedFileInputStream(yang1, yang1.getPath())) { - TestUtils.loadModule(stream1); - fail("InferenceException should be thrown"); - } + TestUtils.loadModuleResources(getClass(), "/negative-scenario/invalid-list-key-def.yang"); + fail("InferenceException should be thrown"); } catch (final ReactorException e) { - final String expected = "Key 'rib-id' misses node 'rib-id' in list '(invalid:list:key:def?revision=1970-01-01)" + - "application-map'"; + final String expected = "Key 'rib-id' misses node 'rib-id' in list " + + "'(invalid:list:key:def?revision=1970-01-01)application-map'"; assertTrue(e.getCause().getMessage().startsWith(expected)); } } - } diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserSimpleTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserSimpleTest.java index b3f301591d..07a7a8200f 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserSimpleTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserSimpleTest.java @@ -22,6 +22,7 @@ import java.util.Set; import org.junit.Before; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.common.QNameModule; import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil; import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode; import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition; @@ -31,27 +32,29 @@ import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode; import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.MustDefinition; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.SchemaPath; import org.opendaylight.yangtools.yang.model.api.Status; import org.opendaylight.yangtools.yang.model.api.TypeDefinition; import org.opendaylight.yangtools.yang.model.api.UsesNode; public class YangParserSimpleTest { - private final URI snNS = URI.create("urn:opendaylight:simple-nodes"); - private Date snRev; - private final String snPref = "sn"; + private static final QNameModule SN = + QNameModule.create(URI.create("urn:opendaylight:simple-nodes"), QName.parseRevision("2013-07-30")); + private static final QName SN_NODES = QName.create(SN, "nodes"); + private static final SchemaPath SN_NODES_PATH = SchemaPath.create(true, SN_NODES); - private Set modules; + private SchemaContext context; + private Module testModule; @Before public void init() throws Exception { - snRev = SimpleDateFormatUtil.getRevisionFormat().parse("2013-07-30"); - modules = TestUtils.loadModules(getClass().getResource("/simple-test").toURI()); + context = TestUtils.loadModules(getClass().getResource("/simple-test").toURI()); + testModule = TestUtils.findModule(context, "simple-nodes").get(); } @Test public void testParseAnyXml() { - final Module testModule = TestUtils.findModule(modules, "simple-nodes"); final AnyXmlSchemaNode data = (AnyXmlSchemaNode) testModule.getDataChildByName(QName.create(testModule.getQNameModule(), "data")); assertNotNull("'anyxml data not found'", data); assertFalse(data.equals(null)); @@ -59,10 +62,7 @@ public class YangParserSimpleTest { "path=AbsoluteSchemaPath{path=[(urn:opendaylight:simple-nodes?revision=2013-07-30)data]}]", data.toString()); // test SchemaNode args - final QName qname = data.getQName(); - assertEquals("data", qname.getLocalName()); - assertEquals(snNS, qname.getNamespace()); - assertEquals(snRev, qname.getRevision()); + assertEquals(QName.create(SN, "data"), data.getQName()); assertEquals("anyxml desc", data.getDescription()); assertEquals("data ref", data.getReference()); assertEquals(Status.OBSOLETE, data.getStatus()); @@ -104,14 +104,11 @@ public class YangParserSimpleTest { @Test public void testParseContainer() throws ParseException { - final Module test = TestUtils.findModule(modules, "simple-nodes"); - - final ContainerSchemaNode nodes = (ContainerSchemaNode) test.getDataChildByName(QName.create(test.getQNameModule(), "nodes")); + final ContainerSchemaNode nodes = (ContainerSchemaNode) testModule + .getDataChildByName(QName.create(testModule.getQNameModule(), "nodes")); // test SchemaNode args - final QName expectedQName = QName.create(snNS, snRev, "nodes"); - assertEquals(expectedQName, nodes.getQName()); - final SchemaPath expectedPath = TestUtils.createPath(true, snNS, snRev, snPref, "nodes"); - assertEquals(expectedPath, nodes.getPath()); + assertEquals(SN_NODES, nodes.getQName()); + assertEquals(SN_NODES_PATH, nodes.getPath()); assertEquals("nodes collection", nodes.getDescription()); assertEquals("nodes ref", nodes.getReference()); assertEquals(Status.CURRENT, nodes.getStatus()); @@ -156,10 +153,9 @@ public class YangParserSimpleTest { final Set> typedefs = nodes.getTypeDefinitions(); assertEquals(1, typedefs.size()); final TypeDefinition nodesType = typedefs.iterator().next(); - final QName typedefQName = QName.create(snNS, snRev, "nodes-type"); + final QName typedefQName = QName.create(SN, "nodes-type"); assertEquals(typedefQName, nodesType.getQName()); - final SchemaPath nodesTypePath = TestUtils.createPath(true, snNS, snRev, snPref, "nodes", "nodes-type"); - assertEquals(nodesTypePath, nodesType.getPath()); + assertEquals(SN_NODES_PATH.createChild(QName.create(SN, "nodes-type")), nodesType.getPath()); assertNull(nodesType.getDescription()); assertNull(nodesType.getReference()); assertEquals(Status.CURRENT, nodesType.getStatus()); @@ -168,19 +164,19 @@ public class YangParserSimpleTest { // child nodes // total size = 8: defined 6, inserted by uses 2 assertEquals(8, nodes.getChildNodes().size()); - final LeafListSchemaNode added = (LeafListSchemaNode)nodes.getDataChildByName(QName.create(test.getQNameModule(), "added")); + final LeafListSchemaNode added = (LeafListSchemaNode)nodes.getDataChildByName(QName.create(testModule.getQNameModule(), "added")); assertEquals(createPath("nodes", "added"), added.getPath()); assertEquals(createPath("mytype"), added.getType().getPath()); - final ListSchemaNode links = (ListSchemaNode) nodes.getDataChildByName(QName.create(test.getQNameModule(), "links")); + final ListSchemaNode links = (ListSchemaNode) nodes.getDataChildByName(QName.create(testModule.getQNameModule(), "links")); assertFalse(links.isUserOrdered()); final Set groupings = nodes.getGroupings(); assertEquals(1, groupings.size()); final GroupingDefinition nodeGroup = groupings.iterator().next(); - final QName groupQName = QName.create(snNS, snRev, "node-group"); + final QName groupQName = QName.create(SN, "node-group"); assertEquals(groupQName, nodeGroup.getQName()); - final SchemaPath nodeGroupPath = TestUtils.createPath(true, snNS, snRev, snPref, "nodes", "node-group"); + final SchemaPath nodeGroupPath = SN_NODES_PATH.createChild(groupQName); assertEquals(nodeGroupPath, nodeGroup.getPath()); final Set uses = nodes.getUses(); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserTest.java index 6f0aa2189d..855757d027 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserTest.java @@ -12,14 +12,11 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource; -import java.io.File; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; -import java.text.DateFormat; import java.text.ParseException; import java.util.ArrayList; import java.util.Collection; @@ -30,7 +27,7 @@ import java.util.Set; import org.junit.Before; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil; +import org.opendaylight.yangtools.yang.common.QNameModule; import org.opendaylight.yangtools.yang.common.YangConstants; import org.opendaylight.yangtools.yang.common.YangVersion; import org.opendaylight.yangtools.yang.model.api.AugmentationSchema; @@ -69,38 +66,33 @@ import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource; import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor; import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline; -import org.opendaylight.yangtools.yang.parser.util.YangParseException; public class YangParserTest { - public static final String FS = File.separator; - - private final URI fooNS = URI.create("urn:opendaylight.foo"); - private final URI barNS = URI.create("urn:opendaylight.bar"); - private final URI bazNS = URI.create("urn:opendaylight.baz"); - private Date fooRev; - private Date barRev; - private Date bazRev; - - private Set modules; + private static final QNameModule FOO = QNameModule.create( + URI.create("urn:opendaylight.foo"), QName.parseRevision("2013-02-27")); + private static final QNameModule BAR = QNameModule.create( + URI.create("urn:opendaylight.bar"), QName.parseRevision("2013-07-03")); + private static final QNameModule BAZ = QNameModule.create( + URI.create("urn:opendaylight.baz"), QName.parseRevision("2013-02-27")); + + private SchemaContext context; + private Module foo; + private Module bar; + private Module baz; @Before public void init() throws Exception { - final DateFormat simpleDateFormat = SimpleDateFormatUtil.getRevisionFormat(); - fooRev = simpleDateFormat.parse("2013-02-27"); - barRev = simpleDateFormat.parse("2013-07-03"); - bazRev = simpleDateFormat.parse("2013-02-27"); - - modules = TestUtils.loadModules(getClass().getResource("/model").toURI()); - assertEquals(3, modules.size()); + context = TestUtils.loadModules(getClass().getResource("/model").toURI()); + foo = TestUtils.findModule(context, "foo").get(); + bar = TestUtils.findModule(context, "bar").get(); + baz = TestUtils.findModule(context, "baz").get(); } @Test public void testHeaders() throws ParseException { - final Module foo = TestUtils.findModule(modules, "foo"); - assertEquals("foo", foo.getName()); assertEquals(YangVersion.VERSION_1.toString(), foo.getYangVersion()); - assertEquals(fooNS, foo.getNamespace()); + assertEquals(FOO.getNamespace(), foo.getNamespace()); assertEquals("foo", foo.getPrefix()); final Set imports = foo.getImports(); @@ -108,11 +100,11 @@ public class YangParserTest { final ModuleImport import2 = TestUtils.findImport(imports, "br"); assertEquals("bar", import2.getModuleName()); - assertEquals(barRev, import2.getRevision()); + assertEquals(BAR.getRevision(), import2.getRevision()); final ModuleImport import3 = TestUtils.findImport(imports, "bz"); assertEquals("baz", import3.getModuleName()); - assertEquals(bazRev, import3.getRevision()); + assertEquals(BAZ.getRevision(), import3.getRevision()); assertEquals("opendaylight", foo.getOrganization()); assertEquals("http://www.opendaylight.org/", foo.getContact()); @@ -123,20 +115,15 @@ public class YangParserTest { @Test public void testParseList() { - final Module bar = TestUtils.findModule(modules, "bar"); - final URI expectedNamespace = URI.create("urn:opendaylight.bar"); - final String expectedPrefix = "bar"; - final ContainerSchemaNode interfaces = (ContainerSchemaNode) bar.getDataChildByName(QName.create( bar.getQNameModule(), "interfaces")); final ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName(QName.create(bar.getQNameModule(), "ifEntry")); // test SchemaNode args - final QName expectedQName = QName.create(expectedNamespace, barRev, "ifEntry"); - assertEquals(expectedQName, ifEntry.getQName()); - final SchemaPath expectedPath = TestUtils.createPath(true, expectedNamespace, barRev, expectedPrefix, - "interfaces", "ifEntry"); + assertEquals(QName.create(BAR, "ifEntry"), ifEntry.getQName()); + + final SchemaPath expectedPath = TestUtils.createPath(true, BAR, "interfaces", "ifEntry"); assertEquals(expectedPath, ifEntry.getPath()); assertNull(ifEntry.getDescription()); assertNull(ifEntry.getReference()); @@ -158,7 +145,7 @@ public class YangParserTest { assertEquals(2, availableAugmentations.size()); // test ListSchemaNode args final List expectedKey = new ArrayList<>(); - expectedKey.add(QName.create(expectedNamespace, barRev, "ifIndex")); + expectedKey.add(QName.create(BAR, "ifIndex")); assertEquals(expectedKey, ifEntry.getKeyDefinition()); assertFalse(ifEntry.isUserOrdered()); // test DataNodeContainer args @@ -177,14 +164,10 @@ public class YangParserTest { @Test public void testTypedefRangesResolving() throws ParseException { - final Module foo = TestUtils.findModule(modules, "foo"); final LeafSchemaNode int32Leaf = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(), "int32-leaf")); final IntegerTypeDefinition leafType = (IntegerTypeDefinition) int32Leaf.getType(); - final QName leafTypeQName = leafType.getQName(); - assertEquals("int32-ext2", leafTypeQName.getLocalName()); - assertEquals(fooNS, leafTypeQName.getNamespace()); - assertEquals(fooRev, leafTypeQName.getRevision()); + assertEquals(QName.create(FOO, "int32-ext2"), leafType.getQName()); assertEquals("mile", leafType.getUnits()); assertEquals("11", leafType.getDefaultValue()); @@ -195,10 +178,7 @@ public class YangParserTest { assertEquals(20, range.getMax().intValue()); final IntegerTypeDefinition baseType = leafType.getBaseType(); - final QName baseTypeQName = baseType.getQName(); - assertEquals("int32-ext2", baseTypeQName.getLocalName()); - assertEquals(barNS, baseTypeQName.getNamespace()); - assertEquals(barRev, baseTypeQName.getRevision()); + assertEquals(QName.create(BAR, "int32-ext2"), baseType.getQName()); assertEquals("mile", baseType.getUnits()); assertEquals("11", baseType.getDefaultValue()); @@ -214,8 +194,7 @@ public class YangParserTest { final IntegerTypeDefinition base = baseType.getBaseType(); final QName baseQName = base.getQName(); assertEquals("int32-ext1", baseQName.getLocalName()); - assertEquals(barNS, baseQName.getNamespace()); - assertEquals(barRev, baseQName.getRevision()); + assertEquals(BAR, baseQName.getModule()); assertNull(base.getUnits()); assertNull(base.getDefaultValue()); @@ -230,15 +209,13 @@ public class YangParserTest { @Test public void testTypedefPatternsResolving() { - final Module foo = TestUtils.findModule(modules, "foo"); final LeafSchemaNode stringleaf = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(), "string-leaf")); assertTrue(stringleaf.getType() instanceof StringTypeDefinition); final StringTypeDefinition type = (StringTypeDefinition) stringleaf.getType(); final QName typeQName = type.getQName(); assertEquals("string-ext4", typeQName.getLocalName()); - assertEquals(barNS, typeQName.getNamespace()); - assertEquals(barRev, typeQName.getRevision()); + assertEquals(BAR, typeQName.getModule()); assertNull(type.getUnits()); assertNull(type.getDefaultValue()); List patterns = type.getPatternConstraints(); @@ -250,8 +227,7 @@ public class YangParserTest { final StringTypeDefinition baseType1 = type.getBaseType(); final QName baseType1QName = baseType1.getQName(); assertEquals("string-ext3", baseType1QName.getLocalName()); - assertEquals(barNS, baseType1QName.getNamespace()); - assertEquals(barRev, baseType1QName.getRevision()); + assertEquals(BAR, baseType1QName.getModule()); assertNull(baseType1.getUnits()); assertNull(baseType1.getDefaultValue()); patterns = baseType1.getPatternConstraints(); @@ -263,8 +239,7 @@ public class YangParserTest { final StringTypeDefinition baseType2 = baseType1.getBaseType(); final QName baseType2QName = baseType2.getQName(); assertEquals("string-ext2", baseType2QName.getLocalName()); - assertEquals(barNS, baseType2QName.getNamespace()); - assertEquals(barRev, baseType2QName.getRevision()); + assertEquals(BAR, baseType2QName.getModule()); assertNull(baseType2.getUnits()); assertNull(baseType2.getDefaultValue()); assertTrue(baseType2.getPatternConstraints().isEmpty()); @@ -275,10 +250,7 @@ public class YangParserTest { assertEquals(10, length.getMax().intValue()); final StringTypeDefinition baseType3 = baseType2.getBaseType(); - final QName baseType3QName = baseType3.getQName(); - assertEquals("string-ext1", baseType3QName.getLocalName()); - assertEquals(barNS, baseType3QName.getNamespace()); - assertEquals(barRev, baseType3QName.getRevision()); + assertEquals(QName.create(BAR, "string-ext1"), baseType3.getQName()); assertNull(baseType3.getUnits()); assertNull(baseType3.getDefaultValue()); patterns = baseType3.getPatternConstraints(); @@ -296,14 +268,10 @@ public class YangParserTest { @Test public void testTypedefInvalidPatternsResolving() { - final Module foo = TestUtils.findModule(modules, "foo"); final LeafSchemaNode invalidPatternStringLeaf = (LeafSchemaNode) foo .getDataChildByName(QName.create(foo.getQNameModule(), "invalid-pattern-string-leaf")); StringTypeDefinition type = (StringTypeDefinition) invalidPatternStringLeaf.getType(); - QName typeQName = type.getQName(); - assertEquals("invalid-string-pattern", typeQName.getLocalName()); - assertEquals(barNS, typeQName.getNamespace()); - assertEquals(barRev, typeQName.getRevision()); + assertEquals(QName.create(BAR, "invalid-string-pattern"), type.getQName()); assertNull(type.getUnits()); assertNull(type.getDefaultValue()); List patterns = type.getPatternConstraints(); @@ -312,10 +280,8 @@ public class YangParserTest { final LeafSchemaNode invalidDirectStringPatternDefLeaf = (LeafSchemaNode) foo .getDataChildByName(QName.create(foo.getQNameModule(), "invalid-direct-string-pattern-def-leaf")); type = (StringTypeDefinition) invalidDirectStringPatternDefLeaf.getType(); - typeQName = type.getQName(); - assertEquals("string", typeQName.getLocalName()); - assertEquals(YangConstants.RFC6020_YANG_NAMESPACE, typeQName.getNamespace()); - assertNull(typeQName.getRevision()); + + assertEquals(QName.create(YangConstants.RFC6020_YANG_MODULE, "string"), type.getQName()); assertNull(type.getUnits()); assertNull(type.getDefaultValue()); patterns = type.getPatternConstraints(); @@ -324,10 +290,7 @@ public class YangParserTest { final LeafSchemaNode multiplePatternStringLeaf = (LeafSchemaNode) foo .getDataChildByName(QName.create(foo.getQNameModule(), "multiple-pattern-string-leaf")); type = (StringTypeDefinition) multiplePatternStringLeaf.getType(); - typeQName = type.getQName(); - assertEquals("multiple-pattern-string", typeQName.getLocalName()); - assertEquals(barNS, typeQName.getNamespace()); - assertEquals(barRev, typeQName.getRevision()); + assertEquals(QName.create(BAR, "multiple-pattern-string"), type.getQName()); assertNull(type.getUnits()); assertNull(type.getDefaultValue()); patterns = type.getPatternConstraints(); @@ -340,10 +303,7 @@ public class YangParserTest { final LeafSchemaNode multiplePatternDirectStringDefLeaf = (LeafSchemaNode) foo .getDataChildByName(QName.create(foo.getQNameModule(), "multiple-pattern-direct-string-def-leaf")); type = (StringTypeDefinition) multiplePatternDirectStringDefLeaf.getType(); - typeQName = type.getQName(); - assertEquals("string", typeQName.getLocalName()); - assertEquals(fooNS, typeQName.getNamespace()); - assertEquals(fooRev, typeQName.getRevision()); + assertEquals(QName.create(FOO, "string"), type.getQName()); assertNull(type.getUnits()); assertNull(type.getDefaultValue()); patterns = type.getPatternConstraints(); @@ -365,15 +325,10 @@ public class YangParserTest { @Test public void testTypedefLengthsResolving() { - final Module foo = TestUtils.findModule(modules, "foo"); - final LeafSchemaNode lengthLeaf = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(), "length-leaf")); final StringTypeDefinition type = (StringTypeDefinition) lengthLeaf.getType(); - final QName typeQName = type.getQName(); - assertEquals("string-ext2", typeQName.getLocalName()); - assertEquals(fooNS, typeQName.getNamespace()); - assertEquals(fooRev, typeQName.getRevision()); + assertEquals(QName.create(FOO, "string-ext2"), type.getQName()); assertNull(type.getUnits()); assertNull(type.getDefaultValue()); assertTrue(type.getPatternConstraints().isEmpty()); @@ -384,10 +339,7 @@ public class YangParserTest { assertEquals(10, length.getMax().intValue()); final StringTypeDefinition baseType1 = type.getBaseType(); - final QName baseType1QName = baseType1.getQName(); - assertEquals("string-ext2", baseType1QName.getLocalName()); - assertEquals(barNS, baseType1QName.getNamespace()); - assertEquals(barRev, baseType1QName.getRevision()); + assertEquals(QName.create(BAR, "string-ext2"), baseType1.getQName()); assertNull(baseType1.getUnits()); assertNull(baseType1.getDefaultValue()); assertTrue(baseType1.getPatternConstraints().isEmpty()); @@ -398,10 +350,7 @@ public class YangParserTest { assertEquals(10, length.getMax().intValue()); final StringTypeDefinition baseType2 = baseType1.getBaseType(); - final QName baseType2QName = baseType2.getQName(); - assertEquals("string-ext1", baseType2QName.getLocalName()); - assertEquals(barNS, baseType2QName.getNamespace()); - assertEquals(barRev, baseType2QName.getRevision()); + assertEquals(QName.create(BAR, "string-ext1"), baseType2.getQName()); assertNull(baseType2.getUnits()); assertNull(baseType2.getDefaultValue()); final List patterns = baseType2.getPatternConstraints(); @@ -419,25 +368,18 @@ public class YangParserTest { @Test public void testTypedefDecimal1() { - final Module foo = TestUtils.findModule(modules, "foo"); final LeafSchemaNode testleaf = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(), "decimal-leaf")); assertTrue(testleaf.getType() instanceof DecimalTypeDefinition); final DecimalTypeDefinition type = (DecimalTypeDefinition) testleaf.getType(); - final QName typeQName = type.getQName(); - assertEquals("my-decimal-type", typeQName.getLocalName()); - assertEquals(barNS, typeQName.getNamespace()); - assertEquals(barRev, typeQName.getRevision()); + assertEquals(QName.create(BAR, "my-decimal-type"), type.getQName()); assertNull(type.getUnits()); assertNull(type.getDefaultValue()); assertEquals(6, type.getFractionDigits().intValue()); assertEquals(1, type.getRangeConstraints().size()); final DecimalTypeDefinition typeBase = type.getBaseType(); - final QName typeBaseQName = typeBase.getQName(); - assertEquals("decimal64", typeBaseQName.getLocalName()); - assertEquals(barNS, typeBaseQName.getNamespace()); - assertEquals(barRev, typeBaseQName.getRevision()); + assertEquals(QName.create(BAR, "decimal64"), typeBase.getQName()); assertNull(typeBase.getUnits()); assertNull(typeBase.getDefaultValue()); assertEquals(6, typeBase.getFractionDigits().intValue()); @@ -448,15 +390,11 @@ public class YangParserTest { @Test public void testTypedefDecimal2() { - final Module foo = TestUtils.findModule(modules, "foo"); final LeafSchemaNode testleaf = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(), "decimal-leaf2")); assertTrue(testleaf.getType() instanceof DecimalTypeDefinition); final DecimalTypeDefinition type = (DecimalTypeDefinition) testleaf.getType(); - final QName typeQName = type.getQName(); - assertEquals("my-decimal-type", typeQName.getLocalName()); - assertEquals(barNS, typeQName.getNamespace()); - assertEquals(barRev, typeQName.getRevision()); + assertEquals(QName.create(BAR, "my-decimal-type"), type.getQName()); assertNull(type.getUnits()); assertNull(type.getDefaultValue()); assertEquals(6, type.getFractionDigits().intValue()); @@ -468,23 +406,16 @@ public class YangParserTest { @Test public void testTypedefUnion() { - final Module foo = TestUtils.findModule(modules, "foo"); final LeafSchemaNode unionleaf = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(), "union-leaf")); assertTrue(unionleaf.getType() instanceof UnionTypeDefinition); final UnionTypeDefinition type = (UnionTypeDefinition) unionleaf.getType(); - final QName typeQName = type.getQName(); - assertEquals("my-union-ext", typeQName.getLocalName()); - assertEquals(barNS, typeQName.getNamespace()); - assertEquals(barRev, typeQName.getRevision()); + assertEquals(QName.create(BAR, "my-union-ext"), type.getQName()); assertNull(type.getUnits()); assertNull(type.getDefaultValue()); final UnionTypeDefinition baseType = type.getBaseType(); - final QName baseTypeQName = baseType.getQName(); - assertEquals("my-union", baseTypeQName.getLocalName()); - assertEquals(barNS, baseTypeQName.getNamespace()); - assertEquals(barRev, baseTypeQName.getRevision()); + assertEquals(QName.create(BAR, "my-union"), baseType.getQName()); assertNull(baseType.getUnits()); assertNull(baseType.getDefaultValue()); @@ -493,10 +424,7 @@ public class YangParserTest { assertEquals(2, unionTypes.size()); final IntegerTypeDefinition unionType1 = (IntegerTypeDefinition) unionTypes.get(0); - final QName unionType1QName = baseType.getQName(); - assertEquals("my-union", unionType1QName.getLocalName()); - assertEquals(barNS, unionType1QName.getNamespace()); - assertEquals(barRev, unionType1QName.getRevision()); + assertEquals(QName.create(BAR, "my-union"), baseType.getQName()); assertNull(unionType1.getUnits()); assertNull(unionType1.getDefaultValue()); @@ -512,23 +440,16 @@ public class YangParserTest { @Test public void testNestedUnionResolving() { - final Module foo = TestUtils.findModule(modules, "foo"); final LeafSchemaNode testleaf = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(), "custom-union-leaf")); assertTrue(testleaf.getType() instanceof UnionTypeDefinition); final UnionTypeDefinition type = (UnionTypeDefinition) testleaf.getType(); - final QName testleafTypeQName = type.getQName(); - assertEquals(bazNS, testleafTypeQName.getNamespace()); - assertEquals(bazRev, testleafTypeQName.getRevision()); - assertEquals("union1", testleafTypeQName.getLocalName()); + assertEquals(QName.create(BAZ, "union1"), type.getQName()); assertNull(type.getUnits()); assertNull(type.getDefaultValue()); final UnionTypeDefinition typeBase = type.getBaseType(); - final QName typeBaseQName = typeBase.getQName(); - assertEquals(bazNS, typeBaseQName.getNamespace()); - assertEquals(bazRev, typeBaseQName.getRevision()); - assertEquals("union2", typeBaseQName.getLocalName()); + assertEquals(QName.create(BAZ, "union2"), typeBase.getQName()); assertNull(typeBase.getUnits()); assertNull(typeBase.getDefaultValue()); @@ -539,10 +460,7 @@ public class YangParserTest { assertTrue(unionTypes.get(1) instanceof UnionTypeDefinition); final UnionTypeDefinition unionType1 = (UnionTypeDefinition) unionTypes.get(1); - final QName uniontType1QName = unionType1.getQName(); - assertEquals(barNS, uniontType1QName.getNamespace()); - assertEquals(barRev, uniontType1QName.getRevision()); - assertEquals("nested-union2", uniontType1QName.getLocalName()); + assertEquals(QName.create(BAR, "nested-union2"), unionType1.getQName()); assertNull(unionType1.getUnits()); assertNull(unionType1.getDefaultValue()); @@ -553,19 +471,13 @@ public class YangParserTest { assertTrue(nestedUnion2Types.get(0) instanceof UnionTypeDefinition); final UnionTypeDefinition myUnionExt = (UnionTypeDefinition) nestedUnion2Types.get(0); - final QName myUnionExtQName = myUnionExt.getQName(); - assertEquals(barNS, myUnionExtQName.getNamespace()); - assertEquals(barRev, myUnionExtQName.getRevision()); - assertEquals("my-union-ext", myUnionExtQName.getLocalName()); + assertEquals(QName.create(BAR, "my-union-ext"), myUnionExt.getQName()); assertNull(myUnionExt.getUnits()); assertNull(myUnionExt.getDefaultValue()); final UnionTypeDefinition myUnion = myUnionExt.getBaseType(); - final QName myUnionQName = myUnion.getQName(); - assertEquals(barNS, myUnionQName.getNamespace()); - assertEquals(barRev, myUnionQName.getRevision()); - assertEquals("my-union", myUnionQName.getLocalName()); + assertEquals(QName.create(BAR, "my-union"), myUnion.getQName()); assertNull(myUnion.getUnits()); assertNull(myUnion.getDefaultValue()); @@ -576,10 +488,7 @@ public class YangParserTest { assertEquals(BaseTypes.int32Type(), myUnionBaseTypes.get(1)); final IntegerTypeDefinition int16Ext = (IntegerTypeDefinition) myUnionBaseTypes.get(0); - final QName int16ExtQName = int16Ext.getQName(); - assertEquals(barNS, int16ExtQName.getNamespace()); - assertEquals(barRev, int16ExtQName.getRevision()); - assertEquals("int16", int16ExtQName.getLocalName()); + assertEquals(QName.create(BAR, "int16"), int16Ext.getQName()); assertNull(int16Ext.getUnits()); assertNull(int16Ext.getDefaultValue()); final List ranges = int16Ext.getRangeConstraints(); @@ -593,7 +502,6 @@ public class YangParserTest { @Test public void testChoice() { - final Module foo = TestUtils.findModule(modules, "foo"); final ContainerSchemaNode transfer = (ContainerSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(), "transfer")); final ChoiceSchemaNode how = (ChoiceSchemaNode) transfer.getDataChildByName(QName.create(foo.getQNameModule(), "how")); final Set cases = how.getCases(); @@ -615,16 +523,14 @@ public class YangParserTest { @Test public void testDeviation() { - final Module foo = TestUtils.findModule(modules, "foo"); final Set deviations = foo.getDeviations(); assertEquals(1, deviations.size()); final Deviation dev = deviations.iterator().next(); assertEquals("system/user ref", dev.getReference()); - final List path = new ArrayList<>(); - path.add(QName.create(barNS, barRev, "interfaces")); - path.add(QName.create(barNS, barRev, "ifEntry")); - final SchemaPath expectedPath = SchemaPath.create(path, true); + final SchemaPath expectedPath = SchemaPath.create(true, + QName.create(BAR, "interfaces"), + QName.create(BAR, "ifEntry")); assertEquals(expectedPath, dev.getTargetPath()); assertEquals(DeviateKind.ADD, dev.getDeviates().iterator().next().getDeviateType()); @@ -632,7 +538,6 @@ public class YangParserTest { @Test public void testUnknownNode() { - final Module baz = TestUtils.findModule(modules, "baz"); final ContainerSchemaNode network = (ContainerSchemaNode) baz.getDataChildByName(QName.create(baz.getQNameModule(), "network")); final List unknownNodes = network.getUnknownSchemaNodes(); assertEquals(1, unknownNodes.size()); @@ -643,14 +548,12 @@ public class YangParserTest { @Test public void testFeature() { - final Module baz = TestUtils.findModule(modules, "baz"); final Set features = baz.getFeatures(); assertEquals(1, features.size()); } @Test public void testExtension() { - final Module baz = TestUtils.findModule(modules, "baz"); final List extensions = baz.getExtensionSchemaNodes(); assertEquals(1, extensions.size()); final ExtensionDefinition extension = extensions.get(0); @@ -662,17 +565,13 @@ public class YangParserTest { @Test public void testNotification() { - final Module baz = TestUtils.findModule(modules, "baz"); - final String expectedPrefix = "c"; - final Set notifications = baz.getNotifications(); assertEquals(1, notifications.size()); final NotificationDefinition notification = notifications.iterator().next(); // test SchemaNode args - final QName expectedQName = QName.create(bazNS, bazRev, "event"); - assertEquals(expectedQName, notification.getQName()); - final SchemaPath expectedPath = TestUtils.createPath(true, bazNS, bazRev, expectedPrefix, "event"); + assertEquals(QName.create(BAZ, "event"), notification.getQName()); + final SchemaPath expectedPath = SchemaPath.create(true, QName.create(BAZ, "event")); assertEquals(expectedPath, notification.getPath()); assertNull(notification.getDescription()); assertNull(notification.getReference()); @@ -692,8 +591,6 @@ public class YangParserTest { @Test public void testRpc() { - final Module baz = TestUtils.findModule(modules, "baz"); - final Set rpcs = baz.getRpcs(); assertEquals(1, rpcs.size()); @@ -704,16 +601,12 @@ public class YangParserTest { @Test public void testTypePath() throws ParseException { - final Module bar = TestUtils.findModule(modules, "bar"); final Set> types = bar.getTypeDefinitions(); // int32-ext1 final IntegerTypeDefinition int32ext1 = (IntegerTypeDefinition) TestUtils.findTypedef(types, "int32-ext1"); - final QName int32TypedefQName = int32ext1.getQName(); - - assertEquals(barNS, int32TypedefQName.getNamespace()); - assertEquals(barRev, int32TypedefQName.getRevision()); - assertEquals("int32-ext1", int32TypedefQName.getLocalName()); + final QName int32TypedefQName = QName.create(BAR, "int32-ext1"); + assertEquals(int32TypedefQName, int32ext1.getQName()); final SchemaPath typeSchemaPath = int32ext1.getPath(); final Iterable typePath = typeSchemaPath.getPathFromRoot(); @@ -728,15 +621,13 @@ public class YangParserTest { @Test public void testTypePath2() throws ParseException { - final Module bar = TestUtils.findModule(modules, "bar"); final Set> types = bar.getTypeDefinitions(); // my-decimal-type final DecimalTypeDefinition myDecType = (DecimalTypeDefinition) TestUtils.findTypedef(types, "my-decimal-type"); final QName myDecTypeQName = myDecType.getQName(); - assertEquals(barNS, myDecTypeQName.getNamespace()); - assertEquals(barRev, myDecTypeQName.getRevision()); + assertEquals(BAR, myDecTypeQName.getModule()); assertEquals("my-decimal-type", myDecTypeQName.getLocalName()); final SchemaPath typeSchemaPath = myDecType.getPath(); @@ -749,8 +640,7 @@ public class YangParserTest { final DecimalTypeDefinition dec64 = myDecType.getBaseType(); final QName dec64QName = dec64.getQName(); - assertEquals(barNS, dec64QName.getNamespace()); - assertEquals(barRev, dec64QName.getRevision()); + assertEquals(BAR, dec64QName.getModule()); assertEquals("decimal64", dec64QName.getLocalName()); final SchemaPath dec64SchemaPath = dec64.getPath(); @@ -791,8 +681,6 @@ public class YangParserTest { @Test public void testSubmodules() { - final Module foo = TestUtils.findModule(modules, "foo"); - final DataSchemaNode id = foo.getDataChildByName(QName.create(foo.getQNameModule(), "id")); assertNotNull(id); final DataSchemaNode subExt = foo.getDataChildByName(QName.create(foo.getQNameModule(), "sub-ext")); @@ -808,14 +696,7 @@ public class YangParserTest { public void unknownStatementInSubmoduleHeaderTest() throws IOException, URISyntaxException, ReactorException { final StatementStreamSource yang1 = sourceForResource("/yang-grammar-test/revisions-extension.yang"); final StatementStreamSource yang2 = sourceForResource("/yang-grammar-test/submodule-header-extension.yang"); - - try { - TestUtils.parseYangSources(yang1, yang2); - } catch (final YangParseException e) { - e.printStackTrace(); - fail("YangParseException should not be thrown"); - } - + TestUtils.parseYangSources(yang1, yang2); } @Test diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserWithContextTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserWithContextTest.java index 6fdd1ff438..be8c883d08 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserWithContextTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserWithContextTest.java @@ -373,10 +373,7 @@ public class YangParserWithContextTest { final StatementStreamSource test3 = sourceForResource("/context-augment-test/test3.yang"); final SchemaContext context = TestUtils.parseYangSources(resource, test1, test2, test3); - final Set modules = context.getModules(); - assertNotNull(modules); - - final Module t4 = TestUtils.findModule(modules, "test4"); + final Module t4 = TestUtils.findModule(context, "test4").get(); final ContainerSchemaNode interfaces = (ContainerSchemaNode) t4.getDataChildByName(QName.create( t4.getQNameModule(), "interfaces")); final ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName(QName.create(t4.getQNameModule(), diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/openconfigver/yin/YinOpenconfigVersionTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/openconfigver/yin/YinOpenconfigVersionTest.java index 902da6a356..ea7b976b75 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/openconfigver/yin/YinOpenconfigVersionTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/openconfigver/yin/YinOpenconfigVersionTest.java @@ -13,7 +13,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import java.io.FileNotFoundException; +import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import org.junit.Test; @@ -22,20 +22,20 @@ import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; import org.opendaylight.yangtools.yang.stmt.StmtTestUtils; +import org.xml.sax.SAXException; public class YinOpenconfigVersionTest { @Test - public void basicTest() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException { + public void basicTest() throws URISyntaxException, SAXException, IOException, ReactorException { SchemaContext context = StmtTestUtils.parseYinSources("/openconfig-version/yin-input/basic", StatementParserMode.SEMVER_MODE); assertNotNull(context); - Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next(); - Module bar = context.findModuleByNamespace(new URI("bar")).iterator().next(); - Module semVer = context.findModuleByNamespace(new URI("http://openconfig.net/yang/openconfig-ext")) + Module foo = context.findModuleByNamespace(URI.create("foo")).iterator().next(); + Module bar = context.findModuleByNamespace(URI.create("bar")).iterator().next(); + Module semVer = context.findModuleByNamespace(URI.create("http://openconfig.net/yang/openconfig-ext")) .iterator().next(); assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion()); @@ -44,13 +44,13 @@ public class YinOpenconfigVersionTest { } @Test - public void basicImportTest1() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException { + public void basicImportTest1() throws URISyntaxException, SAXException, IOException, ReactorException { SchemaContext context = StmtTestUtils.parseYinSources("/openconfig-version/yin-input/basic-import", StatementParserMode.SEMVER_MODE); assertNotNull(context); - Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next(); - Module semVer = context.findModuleByNamespace(new URI("http://openconfig.net/yang/openconfig-ext")) + Module foo = context.findModuleByNamespace(URI.create("foo")).iterator().next(); + Module semVer = context.findModuleByNamespace(URI.create("http://openconfig.net/yang/openconfig-ext")) .iterator().next(); assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion()); @@ -60,8 +60,7 @@ public class YinOpenconfigVersionTest { } @Test - public void basicImportErrTest1() throws SourceException, FileNotFoundException, ReactorException, - URISyntaxException { + public void basicImportErrTest1() throws URISyntaxException, SAXException, IOException { try { StmtTestUtils.parseYinSources("/openconfig-version/yin-input/basic-import-invalid", StatementParserMode.SEMVER_MODE); fail("Test should fail due to invalid openconfig version"); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileAugmentStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileAugmentStmtTest.java index a1994cd76b..b10cf671a9 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileAugmentStmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileAugmentStmtTest.java @@ -11,6 +11,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import java.io.IOException; import java.net.URISyntaxException; import java.util.Iterator; import java.util.Set; @@ -20,22 +21,24 @@ import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.AugmentationSchema; import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode; import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.stmt.TestUtils; +import org.xml.sax.SAXException; public class YinFileAugmentStmtTest { - private Set modules; + private SchemaContext context; @Before - public void init() throws URISyntaxException, ReactorException { - modules = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI()); - assertEquals(9, modules.size()); + public void init() throws ReactorException, SAXException, IOException, URISyntaxException { + context = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI()); + assertEquals(9, context.getModules().size()); } @Test public void testAugment() { - final Module testModule = TestUtils.findModule(modules, "main-impl"); + final Module testModule = TestUtils.findModule(context, "main-impl").get(); assertNotNull(testModule); final Set augmentations = testModule.getAugmentations(); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileChoiceStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileChoiceStmtTest.java index 8a912acc04..72065a976d 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileChoiceStmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileChoiceStmtTest.java @@ -12,9 +12,9 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import java.io.IOException; import java.net.URISyntaxException; import java.util.Iterator; -import java.util.Set; import org.junit.Before; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; @@ -24,22 +24,24 @@ import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.stmt.TestUtils; +import org.xml.sax.SAXException; public class YinFileChoiceStmtTest { - private Set modules; + private SchemaContext context; @Before - public void init() throws URISyntaxException, ReactorException { - modules = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI()); - assertEquals(9, modules.size()); + public void init() throws ReactorException, SAXException, IOException, URISyntaxException { + context = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI()); + assertEquals(9, context.getModules().size()); } @Test public void testChoiceAndCases() { - final Module testModule = TestUtils.findModule(modules, "config"); + final Module testModule = TestUtils.findModule(context, "config").get(); assertNotNull(testModule); final ContainerSchemaNode container = (ContainerSchemaNode) testModule.getDataChildByName(QName.create( diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileExtensionStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileExtensionStmtTest.java index 99d68e23e9..65018e3313 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileExtensionStmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileExtensionStmtTest.java @@ -11,30 +11,32 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import java.io.IOException; import java.net.URISyntaxException; import java.util.Iterator; import java.util.List; -import java.util.Set; import org.junit.Before; import org.junit.Test; import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition; import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.stmt.TestUtils; +import org.xml.sax.SAXException; public class YinFileExtensionStmtTest { - private Set modules; + private SchemaContext context; @Before - public void init() throws URISyntaxException, ReactorException { - modules = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI()); - assertEquals(9, modules.size()); + public void init() throws ReactorException, SAXException, IOException, URISyntaxException { + context = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI()); + assertEquals(9, context.getModules().size()); } @Test public void testExtensions() { - Module testModule = TestUtils.findModule(modules, "config"); + Module testModule = TestUtils.findModule(context, "config").get(); assertNotNull(testModule); List extensions = testModule.getExtensionSchemaNodes(); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileFeatureStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileFeatureStmtTest.java index d823693761..b3c8ce9504 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileFeatureStmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileFeatureStmtTest.java @@ -13,6 +13,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; +import java.io.IOException; import java.net.URISyntaxException; import java.util.Iterator; import java.util.Set; @@ -20,23 +21,25 @@ import org.junit.Before; import org.junit.Test; import org.opendaylight.yangtools.yang.model.api.FeatureDefinition; import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.stmt.TestUtils; +import org.xml.sax.SAXException; public class YinFileFeatureStmtTest { - private Set modules; + private SchemaContext context; @Before - public void init() throws URISyntaxException, ReactorException { - modules = TestUtils.loadYinModules(getClass().getResource - ("/semantic-statement-parser/yin/feature-test/").toURI()); - assertEquals(1, modules.size()); + public void init() throws ReactorException, SAXException, IOException, URISyntaxException { + context = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/feature-test/") + .toURI()); + assertEquals(1, context.getModules().size()); } @Test public void testFeature() { - Module testModule = TestUtils.findModule(modules, "yang-with-features"); + Module testModule = TestUtils.findModule(context, "yang-with-features").get(); assertNotNull(testModule); Set features = testModule.getFeatures(); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileGroupingStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileGroupingStmtTest.java index 1fff202cf6..b4da6ca7de 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileGroupingStmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileGroupingStmtTest.java @@ -11,6 +11,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import java.io.IOException; import java.net.URISyntaxException; import java.util.Collection; import java.util.Iterator; @@ -22,22 +23,24 @@ import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.GroupingDefinition; import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.stmt.TestUtils; +import org.xml.sax.SAXException; public class YinFileGroupingStmtTest { - private Set modules; + private SchemaContext context; @Before - public void init() throws URISyntaxException, ReactorException { - modules = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI()); - assertEquals(9, modules.size()); + public void init() throws ReactorException, SAXException, IOException, URISyntaxException { + context = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI()); + assertEquals(9, context.getModules().size()); } @Test public void testGrouping() throws URISyntaxException { - final Module testModule = TestUtils.findModule(modules, "config"); + final Module testModule = TestUtils.findModule(context, "config").get(); assertNotNull(testModule); final Set groupings = testModule.getGroupings(); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileHeaderStmtsTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileHeaderStmtsTest.java index d8231d403e..47852d18ca 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileHeaderStmtsTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileHeaderStmtsTest.java @@ -9,29 +9,31 @@ package org.opendaylight.yangtools.yang.stmt.yin; import static org.junit.Assert.assertEquals; +import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; -import java.util.Set; import org.junit.Before; import org.junit.Test; import org.opendaylight.yangtools.yang.common.YangVersion; import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.stmt.TestUtils; +import org.xml.sax.SAXException; public class YinFileHeaderStmtsTest { - private Set modules; + private SchemaContext modules; @Before - public void init() throws URISyntaxException, ReactorException { + public void init() throws URISyntaxException, ReactorException, SAXException, IOException { modules = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI()); - assertEquals(9, modules.size()); + assertEquals(9, modules.getModules().size()); } @Test public void testYinFileHeader() throws URISyntaxException { - Module testModule = TestUtils.findModule(modules, "config"); + Module testModule = TestUtils.findModule(modules, "config").get(); assertEquals(YangVersion.VERSION_1.toString(), testModule.getYangVersion()); assertEquals(new URI("urn:opendaylight:params:xml:ns:yang:controller:config"), testModule.getNamespace()); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileIdentityStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileIdentityStmtTest.java index 4d956a5bdc..0c62ab50b3 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileIdentityStmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileIdentityStmtTest.java @@ -14,6 +14,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; +import java.io.IOException; import java.net.URISyntaxException; import java.util.Iterator; import java.util.Set; @@ -21,22 +22,24 @@ import org.junit.Before; import org.junit.Test; import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode; import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.stmt.TestUtils; +import org.xml.sax.SAXException; public class YinFileIdentityStmtTest { - private Set modules; + private SchemaContext context; @Before - public void init() throws URISyntaxException, ReactorException { - modules = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI()); - assertEquals(9, modules.size()); + public void init() throws URISyntaxException, ReactorException, SAXException, IOException { + context = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI()); + assertEquals(9, context.getModules().size()); } @Test public void testIdentity() throws URISyntaxException { - Module testModule = TestUtils.findModule(modules, "config"); + Module testModule = TestUtils.findModule(context, "config").get(); assertNotNull(testModule); Set identities = testModule.getIdentities(); @@ -51,6 +54,5 @@ public class YinFileIdentityStmtTest { id = idIterator.next(); assertThat(id.getQName().getLocalName(), anyOf(is("module-type"), is("service-type"))); assertNull(id.getBaseIdentity()); - } } diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileImportStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileImportStmtTest.java index 50eba7c013..98c0f72fd6 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileImportStmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileImportStmtTest.java @@ -13,6 +13,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; +import java.io.IOException; import java.net.URISyntaxException; import java.text.ParseException; import java.util.Iterator; @@ -21,23 +22,25 @@ import org.junit.Before; 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.api.SchemaContext; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.stmt.TestUtils; +import org.xml.sax.SAXException; public class YinFileImportStmtTest { - private Set modules; + private SchemaContext context; @Before - public void init() throws URISyntaxException, ReactorException { - modules = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI()); - assertEquals(9, modules.size()); + public void init() throws URISyntaxException, ReactorException, SAXException, IOException { + context = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI()); + assertEquals(9, context.getModules().size()); } @Test public void testImport() throws ParseException { - Module testModule = TestUtils.findModule(modules, "ietf-netconf-monitoring"); + Module testModule = TestUtils.findModule(context, "ietf-netconf-monitoring").get(); assertNotNull(testModule); Set imports = testModule.getImports(); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileIncludeStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileIncludeStmtTest.java index 8e6624f8d3..a524a52efd 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileIncludeStmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileIncludeStmtTest.java @@ -10,30 +10,32 @@ package org.opendaylight.yangtools.yang.stmt.yin; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.util.Iterator; -import java.util.Set; import org.junit.Before; import org.junit.Test; import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.stmt.TestUtils; +import org.xml.sax.SAXException; public class YinFileIncludeStmtTest { - private Set modules; + private SchemaContext context; @Before - public void init() throws URISyntaxException, ReactorException { - modules = TestUtils.loadYinModules(getClass().getResource + public void init() throws URISyntaxException, ReactorException, SAXException, IOException { + context = TestUtils.loadYinModules(getClass().getResource ("/semantic-statement-parser/yin/include-belongs-to-test").toURI()); - assertEquals(1, modules.size()); + assertEquals(1, context.getModules().size()); } @Test public void testInclude() throws URISyntaxException { - Module parentModule = TestUtils.findModule(modules, "parent"); + Module parentModule = TestUtils.findModule(context, "parent").get(); assertNotNull(parentModule); assertEquals(1, parentModule.getSubmodules().size()); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileLeafListStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileLeafListStmtTest.java index d161369076..b84ae68106 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileLeafListStmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileLeafListStmtTest.java @@ -11,30 +11,32 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import java.io.IOException; import java.net.URISyntaxException; -import java.util.Set; import org.junit.Before; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; 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.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.stmt.TestUtils; +import org.xml.sax.SAXException; public class YinFileLeafListStmtTest { - private Set modules; + private SchemaContext context; @Before - public void init() throws URISyntaxException, ReactorException { - modules = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI()); - assertEquals(9, modules.size()); + public void init() throws URISyntaxException, ReactorException, SAXException, IOException { + context = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI()); + assertEquals(9, context.getModules().size()); } @Test public void testLeafList() { - final Module testModule = TestUtils.findModule(modules, "ietf-netconf-monitoring"); + final Module testModule = TestUtils.findModule(context, "ietf-netconf-monitoring").get(); assertNotNull(testModule); ContainerSchemaNode container = (ContainerSchemaNode) testModule.getDataChildByName(QName.create( diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileListStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileListStmtTest.java index 8dffff3c9a..a7dd6380e1 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileListStmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileListStmtTest.java @@ -11,11 +11,11 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import java.io.IOException; import java.net.URISyntaxException; import java.util.Collection; import java.util.Iterator; import java.util.List; -import java.util.Set; import org.junit.Before; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; @@ -24,25 +24,27 @@ import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.TypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition; import org.opendaylight.yangtools.yang.model.util.type.BaseTypes; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.stmt.TestUtils; +import org.xml.sax.SAXException; public class YinFileListStmtTest { - private Set modules; + private SchemaContext context; @Before - public void init() throws URISyntaxException, ReactorException { - modules = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI()); - assertEquals(9, modules.size()); + public void init() throws URISyntaxException, ReactorException, SAXException, IOException { + context = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI()); + assertEquals(9, context.getModules().size()); } @Test - public void testListAndLeaves() throws URISyntaxException { - final Module testModule = TestUtils.findModule(modules, "config"); + public void testListAndLeaves() { + final Module testModule = TestUtils.findModule(context, "config").get(); assertNotNull(testModule); final ContainerSchemaNode container = (ContainerSchemaNode) testModule.getDataChildByName(QName.create( diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileMetaStmtsTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileMetaStmtsTest.java index 29244eff26..75a41b1cd5 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileMetaStmtsTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileMetaStmtsTest.java @@ -10,27 +10,29 @@ package org.opendaylight.yangtools.yang.stmt.yin; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import java.io.IOException; import java.net.URISyntaxException; -import java.util.Set; import org.junit.Before; import org.junit.Test; import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.stmt.TestUtils; +import org.xml.sax.SAXException; public class YinFileMetaStmtsTest { - private Set modules; + private SchemaContext context; @Before - public void init() throws URISyntaxException, ReactorException { - modules = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI()); - assertEquals(9, modules.size()); + public void init() throws URISyntaxException, ReactorException, SAXException, IOException { + context = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI()); + assertEquals(9, context.getModules().size()); } @Test public void testMetaStatements() throws URISyntaxException { - Module testModule = TestUtils.findModule(modules, "ietf-netconf-monitoring"); + Module testModule = TestUtils.findModule(context, "ietf-netconf-monitoring").get(); assertNotNull(testModule); assertEquals("IETF NETCONF (Network Configuration) Working Group", testModule.getOrganization()); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileRpcStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileRpcStmtTest.java index c00cb6a4c9..45f111a2c6 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileRpcStmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileRpcStmtTest.java @@ -10,6 +10,7 @@ package org.opendaylight.yangtools.yang.stmt.yin; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import java.io.IOException; import java.net.URISyntaxException; import java.util.Set; import org.junit.Before; @@ -17,24 +18,24 @@ import org.junit.Test; import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.RpcDefinition; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.stmt.TestUtils; +import org.xml.sax.SAXException; public class YinFileRpcStmtTest { - private Set modules; + private SchemaContext context; @Before - public void init() throws URISyntaxException, ReactorException { - modules = TestUtils.loadYinModules(getClass().getResource - ("/semantic-statement-parser/yin/modules").toURI()); - assertEquals(9, modules.size()); + public void init() throws URISyntaxException, ReactorException, SAXException, IOException { + context = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI()); + assertEquals(9, context.getModules().size()); } @Test public void testRpc() { - Module testModule = TestUtils.findModule(modules, "ietf-netconf-monitoring"); - assertNotNull(testModule); + Module testModule = TestUtils.findModule(context, "ietf-netconf-monitoring").get(); Set rpcs = testModule.getRpcs(); assertEquals(1, rpcs.size()); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileStmtTest.java index 86a3988c18..7d2cbe2e13 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileStmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileStmtTest.java @@ -12,20 +12,22 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.io.IOException; import java.net.URISyntaxException; -import java.util.Set; import org.junit.Before; import org.junit.Test; -import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.model.repo.api.YinTextSchemaSource; +import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YinStatementStreamSource; +import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YinTextToDomTransformer; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException; import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource; import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor; import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YinStatementSourceImpl; import org.opendaylight.yangtools.yang.stmt.TestUtils; +import org.xml.sax.SAXException; public class YinFileStmtTest { @@ -35,20 +37,26 @@ public class YinFileStmtTest { private static final StatementStreamSource INVALID_YIN_FILE = createSource("incorrect-foo.yin"); private static final StatementStreamSource INVALID_YIN_FILE_2 = createSource("incorrect-bar.yin"); - private Set modules; + private SchemaContext context; private static StatementStreamSource createSource(final String name) { - return new YinStatementSourceImpl("/semantic-statement-parser/yin/" + name, false); + try { + return YinStatementStreamSource.create(YinTextToDomTransformer.transformSource( + YinTextSchemaSource.forResource(YinFileStmtTest.class, "/semantic-statement-parser/yin/" + name))); + } catch (SAXException | IOException e) { + throw new IllegalArgumentException(e); + } } @Before - public void init() throws URISyntaxException, ReactorException { - modules = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI()); + public void init() throws URISyntaxException, ReactorException, SAXException, IOException { + context = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI()); } @Test public void readAndParseYinFileTestModel() throws SourceException, ReactorException { CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(); + addSources(reactor, YIN_FILE, EXT_FILE, EXT_USE_FILE); SchemaContext result = reactor.buildEffective(); assertNotNull(result); @@ -81,7 +89,7 @@ public class YinFileStmtTest { @Test public void testModulesSize() { - assertEquals(modules.size(), 9); + assertEquals(context.getModules().size(), 9); } private static void addSources(final CrossSourceStatementReactor.BuildAction reactor, final diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileTypeDefStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileTypeDefStmtTest.java index 0b66a3d24d..e6be6abdd9 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileTypeDefStmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileTypeDefStmtTest.java @@ -10,29 +10,32 @@ package org.opendaylight.yangtools.yang.stmt.yin; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import java.io.IOException; import java.net.URISyntaxException; import java.util.Iterator; import java.util.Set; import org.junit.Before; import org.junit.Test; import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.TypeDefinition; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.stmt.TestUtils; +import org.xml.sax.SAXException; public class YinFileTypeDefStmtTest { - private Set modules; + private SchemaContext context; @Before - public void init() throws URISyntaxException, ReactorException { - modules = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI()); - assertEquals(9, modules.size()); + public void init() throws URISyntaxException, ReactorException, SAXException, IOException { + context = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI()); + assertEquals(9, context.getModules().size()); } @Test - public void testTypedef() throws URISyntaxException { - Module testModule = TestUtils.findModule(modules, "config"); + public void testTypedef() { + Module testModule = TestUtils.findModule(context, "config").get(); assertNotNull(testModule); Set> typeDefs = testModule.getTypeDefinitions(); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileUsesStmtTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileUsesStmtTest.java index 95f209f1ed..dc48bfb6d2 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileUsesStmtTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileUsesStmtTest.java @@ -11,6 +11,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import java.io.IOException; import java.net.URISyntaxException; import java.util.Iterator; import java.util.Set; @@ -21,23 +22,25 @@ import org.opendaylight.yangtools.yang.model.api.AugmentationSchema; import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode; 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.model.api.UsesNode; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.stmt.TestUtils; +import org.xml.sax.SAXException; public class YinFileUsesStmtTest { - private Set modules; + private SchemaContext context; @Before - public void init() throws URISyntaxException, ReactorException { - modules = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI()); - assertEquals(9, modules.size()); + public void init() throws URISyntaxException, ReactorException, SAXException, IOException { + context = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI()); + assertEquals(9, context.getModules().size()); } @Test public void testUses() { - final Module testModule = TestUtils.findModule(modules, "main-impl"); + final Module testModule = TestUtils.findModule(context, "main-impl").get(); assertNotNull(testModule); final Set augmentations = testModule.getAugmentations(); diff --git a/yang/yang-test-util/src/main/java/org/opendaylight/yangtools/yang/test/util/YangParserTestUtils.java b/yang/yang-test-util/src/main/java/org/opendaylight/yangtools/yang/test/util/YangParserTestUtils.java index e5343e412b..72b832e89e 100644 --- a/yang/yang-test-util/src/main/java/org/opendaylight/yangtools/yang/test/util/YangParserTestUtils.java +++ b/yang/yang-test-util/src/main/java/org/opendaylight/yangtools/yang/test/util/YangParserTestUtils.java @@ -9,11 +9,9 @@ package org.opendaylight.yangtools.yang.test.util; import com.google.common.annotations.Beta; -import com.google.common.base.Preconditions; import java.io.File; import java.io.FileFilter; -import java.io.FileNotFoundException; -import java.io.InputStream; +import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; @@ -21,16 +19,19 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.YangConstants; 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.StatementParserMode; +import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource; +import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YangStatementStreamSource; import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YinStatementStreamSource; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource; import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor; import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl; -import org.opendaylight.yangtools.yang.parser.util.NamedFileInputStream; /** * Utility class which provides convenience methods for producing effective schema context based on the supplied @@ -52,166 +53,73 @@ public final class YangParserTestUtils { * Creates a new effective schema context containing the specified YANG source. Statement parser mode is set to * default mode and all YANG features are supported. * - * @param yangSourcePath relative path to the YANG file to be parsed + * @param resource relative path to the YANG file to be parsed * * @return effective schema context - * - * @throws ReactorException if there is an error in the parsed YANG source - * @throws FileNotFoundException if the specified file does not exist - * @throws URISyntaxException if the specified file does not exist */ - public static SchemaContext parseYangSource(final String yangSourcePath) throws ReactorException, - FileNotFoundException, URISyntaxException { - return parseYangSource(yangSourcePath, StatementParserMode.DEFAULT_MODE); + public static SchemaContext parseYangResource(final String resource) { + return parseYangResource(resource, StatementParserMode.DEFAULT_MODE); } /** - * Creates a new effective schema context containing the specified YANG source. Statement parser mode is set to - * default mode. - * - * @param yangSourcePath relative path to the YANG file to be parsed - * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG - * model are resolved + * Creates a new effective schema context containing the specified YANG source. All YANG features are supported. * + * @param resource relative path to the YANG file to be parsed + * @param parserMode mode of statement parser * @return effective schema context - * - * @throws ReactorException if there is an error in the parsed YANG source - * @throws FileNotFoundException if the specified file does not exist - * @throws URISyntaxException if the specified file does not exist */ - public static SchemaContext parseYangSource(final String yangSourcePath, final Set supportedFeatures) - throws ReactorException, FileNotFoundException, URISyntaxException { - return parseYangSource(yangSourcePath, supportedFeatures, StatementParserMode.DEFAULT_MODE); + public static SchemaContext parseYangResource(final String resource, final StatementParserMode parserMode) { + return parseYangResource(resource, parserMode, null); } /** - * Creates a new effective schema context containing the specified YANG source. All YANG features are supported. - * - * @param yangSourcePath relative path to the YANG file to be parsed - * @param statementParserMode mode of statement parser + * Creates a new effective schema context containing the specified YANG source. Statement parser mode is set to + * default mode. * + * @param resource relative path to the YANG file to be parsed + * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG + * model are resolved * @return effective schema context - * - * @throws ReactorException if there is an error in the parsed YANG source - * @throws FileNotFoundException if the specified file does not exist - * @throws URISyntaxException if the specified file does not exist */ - public static SchemaContext parseYangSource(final String yangSourcePath, - final StatementParserMode statementParserMode) throws ReactorException, FileNotFoundException, - URISyntaxException { - return parseYangSource(yangSourcePath, null, statementParserMode); + public static SchemaContext parseYangResource(final String resource, final Set supportedFeatures) { + return parseYangResource(resource, StatementParserMode.DEFAULT_MODE, supportedFeatures); } /** * Creates a new effective schema context containing the specified YANG source. * - * @param yangSourcePath relative path to the YANG file to be parsed + * @param resource relative path to the YANG file to be parsed * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG * model are resolved - * @param statementParserMode mode of statement parser - * + * @param parserMode mode of statement parser * @return effective schema context - * - * @throws ReactorException if there is an error in the parsed YANG source - * @throws FileNotFoundException if the specified file does not exist - * @throws URISyntaxException if the specified file does not exist */ - public static SchemaContext parseYangSource(final String yangSourcePath, final Set supportedFeatures, - final StatementParserMode statementParserMode) throws ReactorException, FileNotFoundException, - URISyntaxException { - final URI sourcePath = YangParserTestUtils.class.getResource(yangSourcePath).toURI(); - final File sourceFile = new File(sourcePath); - return parseYangSources(supportedFeatures, statementParserMode, sourceFile); + public static SchemaContext parseYangResource(final String resource, final StatementParserMode parserMode, + final Set supportedFeatures) { + final YangTextSchemaSource source = YangTextSchemaSource.forResource(YangParserTestUtils.class, resource); + return parseYangSources(parserMode, supportedFeatures, source); } /** * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to * default mode and all YANG features are supported. * - * @param sources YANG sources to be parsed - * - * @return effective schema context - * - * @throws ReactorException if there is an error in one of the parsed YANG sources - * - * @deprecated Migration method only, do not use. - */ - @Deprecated - public static SchemaContext parseYangSources(final YangStatementSourceImpl... sources) throws ReactorException { - return parseYangSources(StatementParserMode.DEFAULT_MODE, sources); - } - - /** - * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to - * default mode. - * - * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG - * models are resolved - * @param sources YANG sources to be parsed - * - * @return effective schema context - * @throws ReactorException if there is an error in one of the parsed YANG sources - * - * @deprecated Migration method only, do not use. - */ - @Deprecated - public static SchemaContext parseYangSources(final Set supportedFeatures, - final YangStatementSourceImpl... sources) throws ReactorException { - return parseYangSources(supportedFeatures, StatementParserMode.DEFAULT_MODE, sources); - } - - /** - * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported. - * - * @param statementParserMode mode of statement parser - * @param sources YANG sources to be parsed - * - * @return effective schema context - * @throws ReactorException if there is an error in one of the parsed YANG sources - * - * @deprecated Migration method only, do not use. - */ - @Deprecated - public static SchemaContext parseYangSources(final StatementParserMode statementParserMode, - final YangStatementSourceImpl... sources) throws ReactorException { - return parseYangSources(null, statementParserMode, sources); - } - - /** - * Creates a new effective schema context containing the specified YANG sources. - * - * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG - * models are resolved - * @param statementParserMode mode of statement parser - * @param sources YANG sources to be parsed - * + * @param files YANG files to be parsed * @return effective schema context - * - * @throws ReactorException if there is an error in one of the parsed YANG sources */ - public static SchemaContext parseYangSources(final Set supportedFeatures, - final StatementParserMode statementParserMode, final YangStatementSourceImpl... sources) - throws ReactorException { - final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild( - statementParserMode, supportedFeatures); - reactor.addSources(sources); - - return reactor.buildEffective(); + public static SchemaContext parseYangFiles(final File... files) { + return parseYangFiles(Arrays.asList(files)); } /** * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to * default mode and all YANG features are supported. * - * @param files YANG files to be parsed - * + * @param files collection of YANG files to be parsed * @return effective schema context - * - * @throws ReactorException if there is an error in one of the parsed YANG sources - * @throws FileNotFoundException if one of the specified files does not exist */ - public static SchemaContext parseYangSources(final File... files) throws ReactorException, FileNotFoundException { - return parseYangSources(StatementParserMode.DEFAULT_MODE, files); + public static SchemaContext parseYangFiles(final Collection files) { + return parseYangFiles(StatementParserMode.DEFAULT_MODE, files); } /** @@ -221,105 +129,36 @@ public final class YangParserTestUtils { * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG * models are resolved * @param files YANG files to be parsed - * * @return effective schema context - * - * @throws ReactorException if there is an error in one of the parsed YANG sources - * @throws FileNotFoundException if one of the specified files does not exist */ - public static SchemaContext parseYangSources(final Set supportedFeatures, final File... files) - throws ReactorException, FileNotFoundException { - return parseYangSources(supportedFeatures, StatementParserMode.DEFAULT_MODE, files); + public static SchemaContext parseYangFiles(final Set supportedFeatures, final File... files) { + return parseYangFiles(supportedFeatures, Arrays.asList(files)); } - /** - * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported. - * - * @param statementParserMode mode of statement parser - * @param files YANG files to be parsed - * - * @return effective schema context - * - * @throws ReactorException if there is an error in one of the parsed YANG sources - * @throws FileNotFoundException if one of the specified files does not exist - */ - public static SchemaContext parseYangSources(final StatementParserMode statementParserMode, final File... files) - throws ReactorException, FileNotFoundException { - return parseYangSources(null, statementParserMode, files); + public static SchemaContext parseYangFiles(final Set supportedFeatures, final Collection files) { + return parseYangFiles(supportedFeatures, StatementParserMode.DEFAULT_MODE, files); } /** - * Creates a new effective schema context containing the specified YANG sources. + * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported. * - * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG - * models are resolved - * @param statementParserMode mode of statement parser + * @param parserMode mode of statement parser * @param files YANG files to be parsed - * * @return effective schema context - * - * @throws ReactorException if there is an error in one of the parsed YANG sources - * @throws FileNotFoundException if one of the specified files does not exist */ - public static SchemaContext parseYangSources(final Set supportedFeatures, - final StatementParserMode statementParserMode, final File... files) throws ReactorException, - FileNotFoundException { - final YangStatementSourceImpl[] sources = new YangStatementSourceImpl[files.length]; - for (int i = 0; i < files.length; i++) { - sources[i] = new YangStatementSourceImpl(new NamedFileInputStream(files[i], files[i].getPath())); - } - - return parseYangSources(supportedFeatures, statementParserMode, sources); - } - - /** - * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to - * default mode and all YANG features are supported. - * - * @param files collection of YANG files to be parsed - * - * @return effective schema context - * - * @throws ReactorException if there is an error in one of the parsed YANG sources - * @throws FileNotFoundException if one of the specified files does not exist - */ - public static SchemaContext parseYangSources(final Collection files) throws ReactorException, - FileNotFoundException { - return parseYangSources(files, StatementParserMode.DEFAULT_MODE); - } - - /** - * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to - * default mode. - * - * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG - * models are resolved - * @param files collection of YANG files to be parsed - * - * @return effective schema context - * - * @throws ReactorException if there is an error in one of the parsed YANG sources - * @throws FileNotFoundException if one of the specified files does not exist - */ - public static SchemaContext parseYangSources(final Collection files, final Set supportedFeatures) - throws ReactorException, FileNotFoundException { - return parseYangSources(files, supportedFeatures, StatementParserMode.DEFAULT_MODE); + public static SchemaContext parseYangFiles(final StatementParserMode parserMode, final File... files) { + return parseYangFiles(parserMode, Arrays.asList(files)); } /** * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported. * - * @param statementParserMode mode of statement parser + * @param parserMode mode of statement parser * @param files collection of YANG files to be parsed - * * @return effective schema context - * - * @throws ReactorException if there is an error in one of the parsed YANG sources - * @throws FileNotFoundException if one of the specified files does not exist */ - public static SchemaContext parseYangSources(final Collection files, - final StatementParserMode statementParserMode) throws ReactorException, FileNotFoundException { - return parseYangSources(files, null, statementParserMode); + public static SchemaContext parseYangFiles(final StatementParserMode parserMode, final Collection files) { + return parseYangFiles(null, parserMode, files); } /** @@ -327,405 +166,179 @@ public final class YangParserTestUtils { * * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG * models are resolved - * @param statementParserMode mode of statement parser - * @param files collection of YANG files to be parsed - * - * @return effective schema context - * - * @throws ReactorException if there is an error in one of the parsed YANG sources - * @throws FileNotFoundException if one of the specified files does not exist - */ - public static SchemaContext parseYangSources(final Collection files, final Set supportedFeatures, - final StatementParserMode statementParserMode) throws ReactorException, FileNotFoundException { - return parseYangSources(supportedFeatures, statementParserMode, files.toArray(new File[files.size()])); - } - - /** - * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to - * default mode and all YANG features are supported. - * - * @param yangSourcesDirectoryPath relative path to the directory with YANG files to be parsed - * - * @return effective schema context - * - * @throws ReactorException if there is an error in one of the parsed YANG sources - * @throws FileNotFoundException if the specified directory does not exist - * @throws URISyntaxException if the specified directory does not exist - */ - public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath) throws ReactorException, - FileNotFoundException, URISyntaxException { - return parseYangSources(yangSourcesDirectoryPath, StatementParserMode.DEFAULT_MODE); - } - - /** - * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to - * default mode. - * - * @param yangSourcesDirectoryPath relative path to the directory with YANG files to be parsed - * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG - * models are resolved - * - * @return effective schema context - * - * @throws ReactorException if there is an error in one of the parsed YANG sources - * @throws FileNotFoundException if the specified directory does not exist - * @throws URISyntaxException if the specified directory does not exist - */ - public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath, - final Set supportedFeatures) throws ReactorException, FileNotFoundException, - URISyntaxException { - return parseYangSources(yangSourcesDirectoryPath, supportedFeatures, StatementParserMode.DEFAULT_MODE); - } - - /** - * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported. - * - * @param yangSourcesDirectoryPath relative path to the directory with YANG files to be parsed - * @param statementParserMode mode of statement parser - * + * @param parserMode mode of statement parser + * @param files YANG files to be parsed * @return effective schema context - * - * @throws ReactorException if there is an error in one of the parsed YANG sources - * @throws FileNotFoundException if the specified directory does not exist - * @throws URISyntaxException if the specified directory does not exist */ - public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath, - final StatementParserMode statementParserMode) throws ReactorException, FileNotFoundException, - URISyntaxException { - return parseYangSources(yangSourcesDirectoryPath, null, statementParserMode); + public static SchemaContext parseYangFiles(final Set supportedFeatures, + final StatementParserMode parserMode, final File... files) { + return parseYangFiles(supportedFeatures, parserMode, Arrays.asList(files)); } /** * Creates a new effective schema context containing the specified YANG sources. * - * @param yangSourcesDirectoryPath relative path to the directory with YANG files to be parsed * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG * models are resolved - * @param statementParserMode mode of statement parser - * + * @param parserMode mode of statement parser + * @param files YANG files to be parsed * @return effective schema context - * - * @throws ReactorException if there is an error in one of the parsed YANG sources - * @throws FileNotFoundException if the specified directory does not exist - * @throws URISyntaxException if the specified directory does not exist */ - public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath, - final Set supportedFeatures, final StatementParserMode statementParserMode) - throws ReactorException, FileNotFoundException, URISyntaxException { - final URI directoryPath = YangParserTestUtils.class.getResource(yangSourcesDirectoryPath).toURI(); - final File dir = new File(directoryPath); - - return parseYangSources(supportedFeatures, statementParserMode, dir.listFiles(YANG_FILE_FILTER)); + public static SchemaContext parseYangFiles(final Set supportedFeatures, + final StatementParserMode parserMode, final Collection files) { + return parseYangSources(supportedFeatures, parserMode, + files.stream().map(YangTextSchemaSource::forFile).collect(Collectors.toList())); } /** * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to * default mode and all YANG features are supported. * - * @param yangDirs relative paths to the directories containing YANG files to be parsed - * @param yangFiles relative paths to the YANG files to be parsed - * + * @param resourcePath relative path to the directory with YANG files to be parsed * @return effective schema context - * - * @throws ReactorException if there is an error in one of the parsed YANG sources - * @throws FileNotFoundException if one of the specified directories or files does not exist - * @throws URISyntaxException if one of the specified directories or files does not exist */ - public static SchemaContext parseYangSources(final List yangDirs, final List yangFiles) - throws FileNotFoundException, ReactorException, URISyntaxException { - return parseYangSources(yangDirs, yangFiles, StatementParserMode.DEFAULT_MODE); - } - - /** - * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to - * default mode. - * - * @param yangDirs relative paths to the directories containing YANG files to be parsed - * @param yangFiles relative paths to the YANG files to be parsed - * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG - * models are resolved - * - * @return effective schema context - * - * @throws ReactorException if there is an error in one of the parsed YANG sources - * @throws FileNotFoundException if one of the specified directories or files does not exist - * @throws URISyntaxException if one of the specified directories or files does not exist - */ - public static SchemaContext parseYangSources(final List yangDirs, final List yangFiles, - final Set supportedFeatures) throws FileNotFoundException, ReactorException, - URISyntaxException { - return parseYangSources(yangDirs, yangFiles, supportedFeatures, StatementParserMode.DEFAULT_MODE); + public static SchemaContext parseYangResourceDirectory(final String resourcePath) { + return parseYangResourceDirectory(resourcePath, StatementParserMode.DEFAULT_MODE); } /** * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported. * - * @param yangDirs relative paths to the directories containing YANG files to be parsed - * @param yangFiles relative paths to the YANG files to be parsed - * @param statementParserMode mode of statement parser - * + * @param resourcePath relative path to the directory with YANG files to be parsed + * @param parserMode mode of statement parser * @return effective schema context - * - * @throws ReactorException if there is an error in one of the parsed YANG sources - * @throws FileNotFoundException if one of the specified directories or files does not exist - * @throws URISyntaxException if one of the specified directories or files does not exist */ - public static SchemaContext parseYangSources(final List yangDirs, final List yangFiles, - final StatementParserMode statementParserMode) throws FileNotFoundException, ReactorException, - URISyntaxException { - return parseYangSources(yangDirs, yangFiles, null, statementParserMode); - } - - /** - * Creates a new effective schema context containing the specified YANG sources. - * - * @param yangDirs relative paths to the directories containing YANG files to be parsed - * @param yangFiles relative paths to the YANG files to be parsed - * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG - * models are resolved - * @param statementParserMode mode of statement parser - * - * @return effective schema context - * - * @throws ReactorException if there is an error in one of the parsed YANG sources - * @throws FileNotFoundException if one of the specified directories or files does not exist - * @throws URISyntaxException if one of the specified directories or files does not exist - */ - public static SchemaContext parseYangSources(final List yangDirs, final List yangFiles, - final Set supportedFeatures, final StatementParserMode statementParserMode) - throws FileNotFoundException, ReactorException, URISyntaxException { - final List allYangFiles = new ArrayList<>(); - for (final String yangDir : yangDirs) { - allYangFiles.addAll(getYangFiles(yangDir)); - } - - for (final String yangFile : yangFiles) { - final URI filePath = YangParserTestUtils.class.getResource(yangFile).toURI(); - allYangFiles.add(new File(filePath)); - } - - return parseYangSources(allYangFiles, supportedFeatures, statementParserMode); - } - - /** - * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to - * default mode and all YANG features are supported. - * - * @param filePaths relative paths to the YANG files to be parsed - * - * @return effective schema context - * - * @throws ReactorException if there is an error in one of the parsed YANG sources - */ - public static SchemaContext parseYangSources(final List filePaths) throws ReactorException { - return parseYangSources(filePaths, StatementParserMode.DEFAULT_MODE); + public static SchemaContext parseYangResourceDirectory(final String resourcePath, + final StatementParserMode parserMode) { + return parseYangResourceDirectory(resourcePath, null, parserMode); } /** * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to * default mode. * + * @param resourcePath relative path to the directory with YANG files to be parsed * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG * models are resolved - * @param filePaths relative paths to the YANG files to be parsed - * - * @return effective schema context - * - * @throws ReactorException if there is an error in one of the parsed YANG sources - */ - public static SchemaContext parseYangSources(final List filePaths, final Set supportedFeatures) - throws ReactorException { - return parseYangSources(filePaths, supportedFeatures, StatementParserMode.DEFAULT_MODE); - } - - /** - * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported. - * - * @param statementParserMode mode of statement parser - * @param filePaths relative paths to the YANG files to be parsed - * * @return effective schema context - * - * @throws ReactorException if there is an error in one of the parsed YANG sources */ - public static SchemaContext parseYangSources(final List filePaths, - final StatementParserMode statementParserMode) throws ReactorException { - return parseYangSources(filePaths, (Set) null, statementParserMode); + public static SchemaContext parseYangResourceDirectory(final String resourcePath, + final Set supportedFeatures) { + return parseYangResourceDirectory(resourcePath, supportedFeatures, StatementParserMode.DEFAULT_MODE); } /** * Creates a new effective schema context containing the specified YANG sources. * + * @param resourcePath relative path to the directory with YANG files to be parsed * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG * models are resolved - * @param statementParserMode mode of statement parser - * @param filePaths relative paths to the YANG files to be parsed - * + * @param parserMode mode of statement parser * @return effective schema context - * - * @throws ReactorException if there is an error in one of the parsed YANG sources */ - public static SchemaContext parseYangSources(final List filePaths, - final Set supportedFeatures, final StatementParserMode statementParserMode) - throws ReactorException { - final YangStatementSourceImpl[] sources = new YangStatementSourceImpl[filePaths.size()]; - - for (int i = 0; i < filePaths.size(); i++) { - sources[i] = new YangStatementSourceImpl(YangParserTestUtils.class.getResourceAsStream(filePaths.get(i))); + public static SchemaContext parseYangResourceDirectory(final String resourcePath, + final Set supportedFeatures, final StatementParserMode parserMode) { + final URI directoryPath; + try { + directoryPath = YangParserTestUtils.class.getResource(resourcePath).toURI(); + } catch (URISyntaxException e) { + throw new IllegalArgumentException("Failed to open resource " + resourcePath, e); } - - return parseYangSources(supportedFeatures, statementParserMode, sources); + return parseYangFiles(supportedFeatures, parserMode, new File(directoryPath).listFiles(YANG_FILE_FILTER)); } /** * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to * default mode and all YANG features are supported. * - * @param streams input streams containing YANG sources to be parsed - * + * @param clazz Resource lookup base + * @param resources Resource names to be looked up * @return effective schema context - * - * @throws ReactorException if there is an error in one of the parsed YANG sources */ - public static SchemaContext parseYangStreams(final List streams) throws ReactorException { - return parseYangStreams(streams, StatementParserMode.DEFAULT_MODE); + public static SchemaContext parseYangResources(final Class clazz, final String... resources) { + final List sources = new ArrayList<>(resources.length); + for (final String r : resources) { + sources.add(YangTextSchemaSource.forResource(clazz, r)); + } + return parseYangSources(null, StatementParserMode.DEFAULT_MODE, sources); } /** * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to * default mode. * - * @param streams input streams containing YANG sources to be parsed + * @param yangDirs relative paths to the directories containing YANG files to be parsed + * @param yangFiles relative paths to the YANG files to be parsed * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG * models are resolved - * * @return effective schema context - * - * @throws ReactorException if there is an error in one of the parsed YANG sources */ - public static SchemaContext parseYangStreams(final List streams, final Set supportedFeatures) - throws ReactorException { - return parseYangStreams(streams, supportedFeatures, StatementParserMode.DEFAULT_MODE); + public static SchemaContext parseYangResources(final List yangDirs, final List yangFiles, + final Set supportedFeatures) { + return parseYangResources(yangDirs, yangFiles, supportedFeatures, StatementParserMode.DEFAULT_MODE); } /** * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported. * - * @param streams input streams containing YANG sources to be parsed + * @param yangResourceDirs relative paths to the directories containing YANG files to be parsed + * @param yangResources relative paths to the YANG files to be parsed * @param statementParserMode mode of statement parser - * * @return effective schema context - * - * @throws ReactorException if there is an error in one of the parsed YANG sources */ - public static SchemaContext parseYangStreams(final List streams, - final StatementParserMode statementParserMode) throws ReactorException { - return parseYangStreams(streams, null, statementParserMode); + public static SchemaContext parseYangResources(final List yangResourceDirs, + final List yangResources, final StatementParserMode statementParserMode) { + return parseYangResources(yangResourceDirs, yangResources, null, statementParserMode); } /** * Creates a new effective schema context containing the specified YANG sources. * + * @param yangResourceDirs relative paths to the directories containing YANG files to be parsed + * @param yangResources relative paths to the YANG files to be parsed * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG * models are resolved * @param statementParserMode mode of statement parser - * @param streams input streams containing YANG sources to be parsed - * - * @return effective schema context - * - * @throws ReactorException if there is an error in one of the parsed YANG sources - */ - public static SchemaContext parseYangStreams(final List streams, final Set supportedFeatures, - final StatementParserMode statementParserMode) throws ReactorException { - final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild( - statementParserMode, supportedFeatures); - return reactor.buildEffective(streams); - } - - /** - * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to - * default mode and all YANG features are supported. - * - * @param streams input streams containing YANG sources to be parsed - * * @return effective schema context - * - * @throws ReactorException if there is an error in one of the parsed YANG sources */ - public static SchemaContext parseYangStreams(final InputStream... streams) throws ReactorException { - return parseYangStreams(Arrays.asList(streams)); - } + public static SchemaContext parseYangResources(final List yangResourceDirs, + final List yangResources, final Set supportedFeatures, + final StatementParserMode statementParserMode) { + final List allYangFiles = new ArrayList<>(); + for (final String yangDir : yangResourceDirs) { + allYangFiles.addAll(getYangFiles(yangDir)); + } - /** - * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to - * default mode. - * - * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG - * models are resolved - * @param streams input streams containing YANG sources to be parsed - * - * @return effective schema context - * - * @throws ReactorException if there is an error in one of the parsed YANG sources - */ - public static SchemaContext parseYangStreams(final Set supportedFeatures, - final InputStream... streams) throws ReactorException { - return parseYangStreams(Arrays.asList(streams), supportedFeatures); - } + for (final String yangFile : yangResources) { + try { + allYangFiles.add(new File(YangParserTestUtils.class.getResource(yangFile).toURI())); + } catch (URISyntaxException e) { + throw new IllegalArgumentException("Invalid resource " + yangFile, e); + } + } - /** - * Creates a new effective schema context containing the specified YANG sources. All YANG features are supported. - * - * @param statementParserMode mode of statement parser - * @param streams input streams containing YANG sources to be parsed - * - * @return effective schema context - * - * @throws ReactorException if there is an error in one of the parsed YANG sources - */ - public static SchemaContext parseYangStreams(final StatementParserMode statementParserMode, - final InputStream... streams) throws ReactorException { - return parseYangStreams(Arrays.asList(streams), statementParserMode); + return parseYangFiles(supportedFeatures, statementParserMode, allYangFiles); } - /** - * Creates a new effective schema context containing the specified YANG sources. - * - * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG - * models are resolved - * @param statementParserMode mode of statement parser - * @param streams input streams containing YANG sources to be parsed - * - * @return effective schema context - * - * @throws ReactorException if there is an error in one of the parsed YANG sources - */ - public static SchemaContext parseYangStreams(final Set supportedFeatures, - final StatementParserMode statementParserMode, final InputStream... streams) throws ReactorException { - return parseYangStreams(Arrays.asList(streams), supportedFeatures, statementParserMode); + public static SchemaContext parseYangSources(final StatementParserMode parserMode, + final Set supportedFeatures, final YangTextSchemaSource... sources) { + return parseYangSources(supportedFeatures, parserMode, Arrays.asList(sources)); } - /** - * Creates a new effective schema context containing the specified YANG sources. Statement parser mode is set to - * default mode and all YANG features are supported. - * - * @param clazz Resource lookup base - * @param resources Resource names to be looked up - * - * @return effective schema context - * - * @throws ReactorException if there is an error in one of the parsed YANG sources - */ - public static SchemaContext parseYangResources(final Class clazz, final String... resources) - throws ReactorException { - final List streams = new ArrayList<>(resources.length); - for (final String r : resources) { - final InputStream is = clazz.getResourceAsStream(r); - Preconditions.checkArgument(is != null, "Resource %s not found", r); - streams.add(is); + public static SchemaContext parseYangSources(final Set supportedFeatures, + final StatementParserMode parserMode, final Collection sources) { + final Collection streams = new ArrayList<>(sources.size()); + for (YangTextSchemaSource source : sources) { + try { + streams.add(YangStatementStreamSource.create(source)); + } catch (IOException e) { + throw new IllegalArgumentException("Failed to read source " + source, e); + } catch (YangSyntaxErrorException e) { + throw new IllegalArgumentException("Malformed source " + source, e); + } } - return parseYangStreams(streams); + return parseSources(supportedFeatures, parserMode, streams); } /** @@ -733,12 +346,9 @@ public final class YangParserTestUtils { * default mode and all YANG features are supported. * * @param sources YIN sources to be parsed - * * @return effective schema context - * - * @throws ReactorException if there is an error in one of the parsed YIN sources */ - public static SchemaContext parseYinSources(final YinStatementStreamSource... sources) throws ReactorException { + public static SchemaContext parseYinSources(final YinStatementStreamSource... sources) { return parseYinSources(StatementParserMode.DEFAULT_MODE, sources); } @@ -755,7 +365,7 @@ public final class YangParserTestUtils { */ public static SchemaContext parseYinSources(final Set supportedFeatures, final YinStatementStreamSource... sources) throws ReactorException { - return parseYinSources(supportedFeatures, StatementParserMode.DEFAULT_MODE, sources); + return parseSources(supportedFeatures, StatementParserMode.DEFAULT_MODE, sources); } /** @@ -763,42 +373,61 @@ public final class YangParserTestUtils { * * @param statementParserMode mode of statement parser * @param sources YIN sources to be parsed - * * @return effective schema context - * - * @throws ReactorException if there is an error in one of the parsed YIN sources */ public static SchemaContext parseYinSources(final StatementParserMode statementParserMode, - final YinStatementStreamSource... sources) throws ReactorException { - return parseYinSources(null, statementParserMode, sources); + final YinStatementStreamSource... sources) { + return parseSources(null, statementParserMode, sources); + } + + /** + * Creates a new effective schema context containing the specified YANG sources. + * + * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG + * models are resolved + * @param parserMode mode of statement parser + * @param sources sources to be parsed + * + * @return effective schema context + */ + public static SchemaContext parseSources(final Set supportedFeatures, + final StatementParserMode parserMode, final StatementStreamSource... sources) { + return parseSources(supportedFeatures, parserMode, Arrays.asList(sources)); } /** - * Creates a new effective schema context containing the specified YIN sources. + * Creates a new effective schema context containing the specified YANG sources. * - * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YIN + * @param supportedFeatures set of supported features based on which all if-feature statements in the parsed YANG * models are resolved * @param statementParserMode mode of statement parser - * @param sources YIN sources to be parsed + * @param sources sources to be parsed * * @return effective schema context - * - * @throws ReactorException if there is an error in one of the parsed YIN sources */ - public static SchemaContext parseYinSources(final Set supportedFeatures, - final StatementParserMode statementParserMode, final YinStatementStreamSource... sources) - throws ReactorException { + public static SchemaContext parseSources(final Set supportedFeatures, + final StatementParserMode statementParserMode, final Collection sources) { final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild( - statementParserMode, supportedFeatures); + statementParserMode); + if (supportedFeatures != null) { + reactor.setSupportedFeatures(supportedFeatures); + } reactor.addSources(sources); - return reactor.buildEffective(); + try { + return reactor.buildEffective(); + } catch (ReactorException e) { + throw new IllegalStateException(e); + } } - private static Collection getYangFiles(final String yangSourcesDirectoryPath) throws URISyntaxException { - final URI directoryPath = YangParserTestUtils.class.getResource(yangSourcesDirectoryPath).toURI(); - final File dir = new File(directoryPath); - - return Arrays.asList(dir.listFiles(YANG_FILE_FILTER)); + private static Collection getYangFiles(final String resourcePath) { + final URI directoryPath; + try { + directoryPath = YangParserTestUtils.class.getResource(resourcePath).toURI(); + } catch (URISyntaxException e) { + throw new IllegalArgumentException("Failed to open resource directory " + resourcePath, e); + } + return Arrays.asList(new File(directoryPath).listFiles(YANG_FILE_FILTER)); } }