Expose URLYangTextSource 63/109663/3
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 7 Jan 2024 15:51:24 +0000 (16:51 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 7 Jan 2024 17:37:52 +0000 (18:37 +0100)
Rather than having a plethora of static factory methods, expose only a
few constructors.

JIRA: YANGTOOLS-1561
Change-Id: I4dee89e9243191bdf4d6bf2f1d6e5f1f71a5fd68
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
22 files changed:
model/yang-model-spi/src/main/java/org/opendaylight/yangtools/yang/model/spi/source/URLYangTextSource.java [moved from model/yang-model-spi/src/main/java/org/opendaylight/yangtools/yang/model/spi/source/ResourceYangTextSource.java with 54% similarity]
model/yang-model-spi/src/main/java/org/opendaylight/yangtools/yang/model/spi/source/YangTextSource.java
parser/odlext-parser-support/src/test/java/org/opendaylight/yangtools/odlext/parser/ContextReferenceTest.java
parser/odlext-parser-support/src/test/java/org/opendaylight/yangtools/odlext/parser/MountTest.java
parser/rfc6241-parser-support/src/test/java/org/opendaylight/yangtools/rfc6241/parser/NetconfTest.java
parser/rfc6536-parser-support/src/test/java/org/opendaylight/yangtools/rfc6536/parser/NACMTest.java
parser/rfc6643-parser-support/src/test/java/org/opendaylight/yangtools/rfc6643/parser/IetfYangSmiv2ExtensionPluginTest.java
parser/rfc7952-parser-support/src/test/java/org/opendaylight/yangtools/rfc7952/parser/AnnotationTest.java
parser/rfc8040-parser-support/src/test/java/org/opendaylight/yangtools/rfc8040/parser/AbstractYangDataTest.java
parser/rfc8528-parser-support/src/test/java/org/opendaylight/yangtools/rfc8528/parser/MountPointTest.java
parser/rfc8639-parser-support/src/test/java/org/opendaylight/yangtools/rfc8639/parser/SubscribedNotificationsTest.java
parser/rfc8819-parser-support/src/test/java/org/opendaylight/yangtools/rfc8819/parser/ModuleTagTest.java
parser/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/repo/YangTextSchemaContextResolver.java
parser/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YT1193Test.java
parser/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/repo/AbstractSchemaRepositoryTest.java
parser/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/repo/DependencyResolverTest.java
parser/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/repo/MultipleRevImportBug6875Test.java
parser/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/repo/OpenconfigVerSharedSchemaRepositoryTest.java
parser/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/repo/SharedEffectiveModelContextFactoryTest.java
parser/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/repo/SharedSchemaRepositoryTest.java
parser/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/repo/SharedSchemaRepositoryWithFeaturesTest.java
parser/yang-test-util/src/main/java/org/opendaylight/yangtools/yang/test/util/YangParserTestUtils.java

similarity index 54%
rename from model/yang-model-spi/src/main/java/org/opendaylight/yangtools/yang/model/spi/source/ResourceYangTextSource.java
rename to model/yang-model-spi/src/main/java/org/opendaylight/yangtools/yang/model/spi/source/URLYangTextSource.java
index 220365eeb6bb75bbe9b2873f140c334792c12d42..e4cdb1ef7023dd9f7c97cf63adb5a58760ced65a 100644 (file)
@@ -15,40 +15,57 @@ import java.io.InputStreamReader;
 import java.io.Reader;
 import java.net.URL;
 import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.opendaylight.yangtools.concepts.Delegator;
 import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
 
 /**
- * A resource-backed {@link YangTextSource}.
+ * A {@link YangTextSource} backed by a {@link URL}.
  */
-final class ResourceYangTextSource extends YangTextSource implements Delegator<URL> {
-    private final @NonNull URL url;
-    private final @NonNull Charset charset;
+@NonNullByDefault
+public class URLYangTextSource extends YangTextSource implements Delegator<URL> {
+    private final URL url;
+    private final Charset charset;
 
-    ResourceYangTextSource(final SourceIdentifier sourceId, final URL url, final Charset charset) {
+    public URLYangTextSource(final SourceIdentifier sourceId, final URL url, final Charset charset) {
         super(sourceId);
         this.url = requireNonNull(url);
         this.charset = requireNonNull(charset);
     }
 
+    /**
+     * Utility constructor. The {@link SourceIdentifier} is derived from {@link URL#getPath()} and the character set is
+     * assumed to be UTF-8.
+     *
+     * @param url backing {@link URL}
+     */
+    public URLYangTextSource(final URL url) {
+        this(SourceIdentifier.ofYangFileName(extractFileName(url.getPath())), url, StandardCharsets.UTF_8);
+    }
+
     @Override
-    public URL getDelegate() {
-        return url;
+    public final Reader openStream() throws IOException {
+        return new InputStreamReader(url.openStream(), charset);
     }
 
     @Override
-    protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
-        return super.addToStringAttributes(toStringHelper).add("url", url);
+    public final @NonNull String symbolicName() {
+        return url.toString();
     }
 
     @Override
-    public Reader openStream() throws IOException {
-        return new InputStreamReader(url.openStream(), charset);
+    public final URL getDelegate() {
+        return url;
     }
 
     @Override
-    public String symbolicName() {
-        return url.toString();
+    protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
+        return super.addToStringAttributes(toStringHelper).add("url", url);
+    }
+
+    private static String extractFileName(final String path) {
+        return path.substring(path.lastIndexOf('/') + 1);
     }
 }
index 9fbdb35a839e3a2c3bba791f5129764916905b32..1e52e39b8f81a8704cb211f97e272bc0dfe25c2e 100644 (file)
@@ -12,10 +12,8 @@ import static java.util.Objects.requireNonNull;
 import com.google.common.base.MoreObjects;
 import com.google.common.base.MoreObjects.ToStringHelper;
 import com.google.common.io.CharSource;
-import com.google.common.io.Resources;
 import java.io.File;
 import java.io.InputStream;
-import java.net.URL;
 import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
@@ -79,76 +77,6 @@ public abstract class YangTextSource extends CharSource implements YangSourceRep
         throw new IllegalArgumentException("Supplied path " + path + " is not a regular file");
     }
 
-    /**
-     * Create a new {@link YangTextSource} backed by a resource available in the ClassLoader where this
-     * class resides.
-     *
-     * @param resourceName Resource name
-     * @return A new instance.
-     * @throws IllegalArgumentException if the resource does not exist or if the name has invalid format
-     */
-    public static @NonNull YangTextSource forResource(final String resourceName) {
-        return forResource(YangTextSource.class, resourceName);
-    }
-
-    /**
-     * Create a new {@link YangTextSource} backed by a resource by a resource available on the ClassLoader
-     * which loaded the specified class.
-     *
-     * @param clazz Class reference
-     * @param resourceName Resource name
-     * @return A new instance.
-     * @throws IllegalArgumentException if the resource does not exist or if the name has invalid format
-     */
-    public static @NonNull YangTextSource forResource(final Class<?> clazz, final String resourceName) {
-        return forResource(clazz, resourceName, StandardCharsets.UTF_8);
-    }
-
-    /**
-     * Create a new {@link YangTextSource} backed by a resource by a resource available on the ClassLoader
-     * which loaded the specified class.
-     *
-     * @param clazz Class reference
-     * @param resourceName Resource name
-     * @param charset Expected character set
-     * @return A new instance.
-     * @throws IllegalArgumentException if the resource does not exist or if the name has invalid format
-     */
-    public static @NonNull YangTextSource forResource(final Class<?> clazz, final String resourceName,
-            final Charset charset) {
-        final var fileName = resourceName.substring(resourceName.lastIndexOf('/') + 1);
-        final var identifier = SourceIdentifier.ofYangFileName(fileName);
-        final var url = Resources.getResource(clazz, resourceName);
-        return new ResourceYangTextSource(identifier, url, charset);
-    }
-
-
-    /**
-     * Create a new {@link YangTextSource} backed by a URL.
-     *
-     * @param url Backing URL
-     * @param identifier Source identifier
-     * @return A new instance.
-     * @throws NullPointerException if any argument is {@code null}
-     */
-    public static @NonNull YangTextSource forURL(final URL url, final SourceIdentifier identifier) {
-        return forURL(url, identifier, StandardCharsets.UTF_8);
-    }
-
-    /**
-     * Create a new {@link YangTextSource} backed by a URL.
-     *
-     * @param url Backing URL
-     * @param identifier Source identifier
-     * @param charset Expected character set
-     * @return A new instance.
-     * @throws NullPointerException if any argument is {@code null}
-     */
-    public static @NonNull YangTextSource forURL(final URL url, final SourceIdentifier identifier,
-            final Charset charset) {
-        return new ResourceYangTextSource(identifier, url, charset);
-    }
-
     @Override
     public final Class<YangTextSource> getType() {
         return YangTextSource.class;
index 84e2e4b906fb9dc1f8ae2b92224fdcae5c0b154d..e4bbca664420dc191e9cb36f8479b96d9f95823e 100644 (file)
@@ -21,7 +21,7 @@ import org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement
 import org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.LeafListEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.ListEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
+import org.opendaylight.yangtools.yang.model.spi.source.URLYangTextSource;
 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
 import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource;
@@ -42,10 +42,10 @@ class ContextReferenceTest {
             .build();
 
         final var foo = reactor.newBuild()
-            .addSource(YangStatementStreamSource.create(YangTextSource.forResource(
-                ContextReferenceTest.class, "/yang-ext.yang")))
-            .addSource(YangStatementStreamSource.create(YangTextSource.forResource(
-                ContextReferenceTest.class, "/ctxref.yang")))
+            .addSource(YangStatementStreamSource.create(new URLYangTextSource(
+                ContextReferenceTest.class.getResource("/yang-ext.yang"))))
+            .addSource(YangStatementStreamSource.create(new URLYangTextSource(
+                ContextReferenceTest.class.getResource("/ctxref.yang"))))
             .buildEffective()
             .getModuleStatements()
             .get(FOO);
index a95c87777d757b703051d4b858c07b275ed5f995..59f737540d73d35d6ce62a3792fe09fc89cb105d 100644 (file)
@@ -14,7 +14,7 @@ import org.opendaylight.yangtools.odlext.model.api.MountEffectiveStatement;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.common.XMLNamespace;
-import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
+import org.opendaylight.yangtools.yang.model.spi.source.URLYangTextSource;
 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
 import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource;
@@ -30,8 +30,10 @@ class MountTest {
                 new MountStatementSupport(YangParserConfiguration.DEFAULT))
             .build();
         final var foo = reactor.newBuild()
-            .addSource(YangStatementStreamSource.create(YangTextSource.forResource(MountTest.class, "/yang-ext.yang")))
-            .addSource(YangStatementStreamSource.create(YangTextSource.forResource(MountTest.class, "/mount.yang")))
+            .addSource(YangStatementStreamSource.create(new URLYangTextSource(
+                MountTest.class.getResource("/yang-ext.yang"))))
+            .addSource(YangStatementStreamSource.create(new URLYangTextSource(
+                MountTest.class.getResource("/mount.yang"))))
             .buildEffective()
             .getModuleStatements()
             .get(FOO);
index 5fb6852e2f310876e1ba1caca578a748db8989fb..f2917ccff01b5ce099f8abe6ac27cb0b480b5db8 100644 (file)
@@ -17,7 +17,7 @@ import org.opendaylight.yangtools.rfc6241.model.api.NetconfConstants;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
-import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
+import org.opendaylight.yangtools.yang.model.spi.source.URLYangTextSource;
 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
 import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource;
@@ -34,9 +34,9 @@ class NetconfTest {
             .build();
         final var context = reactor.newBuild()
             .addLibSources(YangStatementStreamSource.create(
-                YangTextSource.forResource(NetconfTest.class, "/ietf-inet-types@2013-07-15.yang")))
+                new URLYangTextSource(NetconfTest.class.getResource("/ietf-inet-types@2013-07-15.yang"))))
             .addSource(YangStatementStreamSource.create(
-                YangTextSource.forResource(NetconfTest.class, "/ietf-netconf@2011-06-01.yang")))
+                new URLYangTextSource(NetconfTest.class.getResource("/ietf-netconf@2011-06-01.yang"))))
             .buildEffective();
 
         final var module = context.findModule(NetconfConstants.RFC6241_MODULE).orElseThrow();
index 42f8b8d62ea95e46864daaf383711000f98128e1..6ff7ed37fe8c1e38a5023afb236ae51e22ee95c1 100644 (file)
@@ -15,7 +15,7 @@ import org.opendaylight.yangtools.rfc6536.model.api.DefaultDenyAllSchemaNode;
 import org.opendaylight.yangtools.rfc6536.model.api.DefaultDenyWriteSchemaNode;
 import org.opendaylight.yangtools.rfc6536.model.api.NACMConstants;
 import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
+import org.opendaylight.yangtools.yang.model.spi.source.URLYangTextSource;
 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
 import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource;
@@ -34,9 +34,9 @@ class NACMTest {
         final var context = reactor.newBuild()
             .addSources(
                 YangStatementStreamSource.create(
-                    YangTextSource.forResource(NACMTest.class, "/ietf-netconf-acm@2012-02-22.yang")),
+                    new URLYangTextSource(NACMTest.class.getResource("/ietf-netconf-acm@2012-02-22.yang"))),
                 YangStatementStreamSource.create(
-                    YangTextSource.forResource(NACMTest.class, "/ietf-yang-types@2013-07-15.yang")))
+                    new URLYangTextSource(NACMTest.class.getResource("/ietf-yang-types@2013-07-15.yang"))))
             .buildEffective();
 
         final var module = context.findModule(NACMConstants.RFC6536_MODULE).orElseThrow();
index 8eb6bb24199562188a9fdae6a10236503680c4b6..fedaab441a79a5bf427bf5891c9b80091687fa3d 100644 (file)
@@ -24,7 +24,7 @@ import org.opendaylight.yangtools.yang.common.Uint32;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
-import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
+import org.opendaylight.yangtools.yang.model.spi.source.URLYangTextSource;
 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
 import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource;
@@ -54,10 +54,10 @@ class IetfYangSmiv2ExtensionPluginTest {
             .build();
         final var schema = reactor.newBuild()
             .addSources(
-                YangStatementStreamSource.create(YangTextSource.forResource(
-                    IetfYangSmiv2ExtensionPluginTest.class, "/foo.yang")),
-                YangStatementStreamSource.create(YangTextSource.forResource(
-                    IetfYangSmiv2ExtensionPluginTest.class, "/ietf-yang-smiv2.yang")))
+                YangStatementStreamSource.create(new URLYangTextSource(
+                    IetfYangSmiv2ExtensionPluginTest.class.getResource("/foo.yang"))),
+                YangStatementStreamSource.create(new URLYangTextSource(
+                    IetfYangSmiv2ExtensionPluginTest.class.getResource("/ietf-yang-smiv2.yang"))))
             .buildEffective();
 
         assertEquals(1, schema.getUnknownSchemaNodes().size());
index a82b0ee66313f33072b38fe9735364c8035cecd0..2af371e606d5ebaea46f03897f1d25b668886010 100644 (file)
@@ -18,7 +18,7 @@ import org.opendaylight.yangtools.rfc7952.model.api.AnnotationSchemaNode;
 import org.opendaylight.yangtools.yang.common.AnnotationName;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes;
-import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
+import org.opendaylight.yangtools.yang.model.spi.source.URLYangTextSource;
 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
 import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource;
@@ -37,9 +37,9 @@ class AnnotationTest {
         final var context = reactor.newBuild()
             .addSources(
                 YangStatementStreamSource.create(
-                    YangTextSource.forResource(AnnotationTest.class, "/ietf-yang-metadata@2016-08-05.yang")),
+                    new URLYangTextSource(AnnotationTest.class.getResource("/ietf-yang-metadata@2016-08-05.yang"))),
                 YangStatementStreamSource.create(
-                    YangTextSource.forResource(AnnotationTest.class, "/example-last-modified.yang")))
+                    new URLYangTextSource(AnnotationTest.class.getResource("/example-last-modified.yang"))))
             .buildEffective();
 
         final var annotations = AnnotationSchemaNode.findAll(context);
index 3816657d314d14862be882344bfb698e1bb9eb85..2ea53c122af8b39ea0453cc4deded1a88d440a70 100644 (file)
@@ -10,7 +10,7 @@ package org.opendaylight.yangtools.rfc8040.parser;
 import java.io.IOException;
 import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.BeforeAll;
-import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
+import org.opendaylight.yangtools.yang.model.spi.source.URLYangTextSource;
 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
 import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
@@ -42,7 +42,7 @@ abstract class AbstractYangDataTest {
     static StatementStreamSource sourceForResource(final String resourceName) {
         try {
             return YangStatementStreamSource.create(
-                YangTextSource.forResource(AbstractYangDataTest.class, resourceName));
+                new URLYangTextSource(AbstractYangDataTest.class.getResource(resourceName)));
         } catch (IOException | YangSyntaxErrorException e) {
             throw new IllegalArgumentException("Failed to create source", e);
         }
index 601731c0d925eb268cdb85198662537eb93cf151..c557f80020d8ad696d4e7d9431f95a7db386e6bc 100644 (file)
@@ -17,7 +17,7 @@ import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.common.XMLNamespace;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
-import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
+import org.opendaylight.yangtools.yang.model.spi.source.URLYangTextSource;
 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
 import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource;
@@ -41,15 +41,16 @@ class MountPointTest {
         final var context = reactor.newBuild()
             .addLibSources(
                 YangStatementStreamSource.create(
-                    YangTextSource.forResource(MountPointTest.class, "/ietf-inet-types@2013-07-15.yang")),
+                    new URLYangTextSource(MountPointTest.class.getResource("/ietf-inet-types@2013-07-15.yang"))),
                 YangStatementStreamSource.create(
-                    YangTextSource.forResource(MountPointTest.class, "/ietf-yang-schema-mount@2019-01-14.yang")),
+                    new URLYangTextSource(MountPointTest.class.getResource("/ietf-yang-schema-mount@2019-01-14.yang"))),
                 YangStatementStreamSource.create(
-                    YangTextSource.forResource(MountPointTest.class, "/ietf-yang-types@2013-07-15.yang")))
+                    new URLYangTextSource(MountPointTest.class.getResource("/ietf-yang-types@2013-07-15.yang"))))
             .addSources(
-                YangStatementStreamSource.create(YangTextSource.forResource(MountPointTest.class, "/example-grp.yang")),
                 YangStatementStreamSource.create(
-                    YangTextSource.forResource(MountPointTest.class, "/example-uses.yang")))
+                    new URLYangTextSource(MountPointTest.class.getResource("/example-grp.yang"))),
+                YangStatementStreamSource.create(
+                    new URLYangTextSource(MountPointTest.class.getResource("/example-uses.yang"))))
             .buildEffective();
 
         assertEquals(5, context.getModules().size());
index 0ea631801e48fe539c5e384b3c9fdd89c413b8eb..2c97abf9766a3a2e13c8afe9299a6b42e2ecec16 100644 (file)
@@ -14,7 +14,7 @@ import org.junit.jupiter.api.Test;
 import org.opendaylight.yangtools.rfc8639.model.api.SubscribedNotificationsConstants;
 import org.opendaylight.yangtools.rfc8639.model.api.SubscriptionStateNotificationEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
+import org.opendaylight.yangtools.yang.model.spi.source.URLYangTextSource;
 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
 import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource;
@@ -30,25 +30,25 @@ class SubscribedNotificationsTest {
 
         final var context = reactor.newBuild()
             .addLibSources(
-                YangStatementStreamSource.create(YangTextSource.forResource(
-                    SubscribedNotificationsTest.class, "/ietf-inet-types@2013-07-15.yang")),
-                YangStatementStreamSource.create(YangTextSource.forResource(
-                    SubscribedNotificationsTest.class, "/ietf-interfaces@2018-02-20.yang")),
-                YangStatementStreamSource.create(YangTextSource.forResource(
-                    SubscribedNotificationsTest.class, "/ietf-ip@2018-02-22.yang")),
-                YangStatementStreamSource.create(YangTextSource.forResource(
-                    SubscribedNotificationsTest.class, "/ietf-netconf-acm@2018-02-14.yang")),
-                YangStatementStreamSource.create(YangTextSource.forResource(
-                    SubscribedNotificationsTest.class, "/ietf-network-instance@2019-01-21.yang")),
-                YangStatementStreamSource.create(YangTextSource.forResource(
-                    SubscribedNotificationsTest.class, "/ietf-restconf@2017-01-26.yang")),
-                YangStatementStreamSource.create(YangTextSource.forResource(
-                    SubscribedNotificationsTest.class, "/ietf-yang-schema-mount@2019-01-14.yang")),
-                YangStatementStreamSource.create(YangTextSource.forResource(
-                    SubscribedNotificationsTest.class, "/ietf-yang-types@2013-07-15.yang")))
+                YangStatementStreamSource.create(new URLYangTextSource(
+                    SubscribedNotificationsTest.class.getResource("/ietf-inet-types@2013-07-15.yang"))),
+                YangStatementStreamSource.create(new URLYangTextSource(
+                    SubscribedNotificationsTest.class.getResource("/ietf-interfaces@2018-02-20.yang"))),
+                YangStatementStreamSource.create(new URLYangTextSource(
+                    SubscribedNotificationsTest.class.getResource("/ietf-ip@2018-02-22.yang"))),
+                YangStatementStreamSource.create(new URLYangTextSource(
+                    SubscribedNotificationsTest.class.getResource("/ietf-netconf-acm@2018-02-14.yang"))),
+                YangStatementStreamSource.create(new URLYangTextSource(
+                    SubscribedNotificationsTest.class.getResource("/ietf-network-instance@2019-01-21.yang"))),
+                YangStatementStreamSource.create(new URLYangTextSource(
+                    SubscribedNotificationsTest.class.getResource("/ietf-restconf@2017-01-26.yang"))),
+                YangStatementStreamSource.create(new URLYangTextSource(
+                    SubscribedNotificationsTest.class.getResource("/ietf-yang-schema-mount@2019-01-14.yang"))),
+                YangStatementStreamSource.create(new URLYangTextSource(
+                    SubscribedNotificationsTest.class.getResource("/ietf-yang-types@2013-07-15.yang"))))
             .addSources(
-                YangStatementStreamSource.create(YangTextSource.forResource(
-                    SubscribedNotificationsTest.class, "/ietf-subscribed-notifications@2019-09-09.yang")))
+                YangStatementStreamSource.create(new URLYangTextSource(
+                    SubscribedNotificationsTest.class.getResource("/ietf-subscribed-notifications@2019-09-09.yang"))))
             .buildEffective();
 
         final var notifications = context.getModuleStatement(SubscribedNotificationsConstants.RFC8639_MODULE)
index b8707cf65b1b9742989448419ec0a41da2e5d3a9..dfb4870b6d94a7c5da35bb52abdb2bc73e2cd1b0 100644 (file)
@@ -21,7 +21,7 @@ import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
 import org.opendaylight.yangtools.rfc8819.model.api.ModuleTagEffectiveStatement;
 import org.opendaylight.yangtools.rfc8819.model.api.Tag;
-import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
+import org.opendaylight.yangtools.yang.model.spi.source.URLYangTextSource;
 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
 import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
@@ -89,7 +89,8 @@ public class ModuleTagTest {
 
     private static YangStatementStreamSource moduleFromResources(final String resourceName) {
         try {
-            return YangStatementStreamSource.create(YangTextSource.forResource(ModuleTagTest.class, resourceName));
+            return YangStatementStreamSource.create(new URLYangTextSource(
+                ModuleTagTest.class.getResource(resourceName)));
         } catch (final YangSyntaxErrorException | IOException e) {
             throw new IllegalStateException("Failed to find resource " + resourceName, e);
         }
index 3e64b0027a56a14921898a35006338705c74d0c0..850928fff156607dd523ad090fd5cfdd407bd3c8 100644 (file)
@@ -17,6 +17,7 @@ import com.google.common.collect.Multimap;
 import com.google.common.util.concurrent.FluentFuture;
 import java.io.IOException;
 import java.net.URL;
+import java.nio.charset.StandardCharsets;
 import java.time.Duration;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -50,6 +51,7 @@ import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource.Cost
 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider;
 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry;
 import org.opendaylight.yangtools.yang.model.spi.source.DelegatedYangTextSource;
+import org.opendaylight.yangtools.yang.model.spi.source.URLYangTextSource;
 import org.opendaylight.yangtools.yang.model.spi.source.YangIRSchemaSource;
 import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
 import org.opendaylight.yangtools.yang.parser.api.YangParserFactory;
@@ -177,7 +179,7 @@ public final class YangTextSchemaContextResolver implements AutoCloseable, Schem
             throws SchemaSourceException, IOException, YangSyntaxErrorException {
         final String path = url.getPath();
         final String fileName = path.substring(path.lastIndexOf('/') + 1);
-        return registerSource(YangTextSource.forURL(url, guessSourceIdentifier(fileName)));
+        return registerSource(new URLYangTextSource(guessSourceIdentifier(fileName), url, StandardCharsets.UTF_8));
     }
 
     /**
index 13e484a5671a8ce4f9153fc7923a1960026c9cf2..dfcf47e204db9d044aa4c5f2b244fa8e4f31500a 100644 (file)
@@ -16,17 +16,17 @@ import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
 import org.opendaylight.yangtools.yang.model.api.meta.DeclarationInText;
 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
-import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
+import org.opendaylight.yangtools.yang.model.spi.source.URLYangTextSource;
 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
 
-public class YT1193Test {
+class YT1193Test {
     @Test
     void testDeclarationReference() throws Exception {
         final var declaredRoots = new DefaultYangParserFactory()
             .createParser(YangParserConfiguration.builder().retainDeclarationReferences(true).build())
-            .addSource(YangTextSource.forResource(getClass(), "/yt1193/foo.yang"))
-            .addSource(YangTextSource.forResource(getClass(), "/yt1193/bar.yang"))
-            .addSource(YangTextSource.forResource(getClass(), "/yt1193/baz.yang"))
+            .addSource(new URLYangTextSource(YT1193Test.class.getResource("/yt1193/foo.yang")))
+            .addSource(new URLYangTextSource(YT1193Test.class.getResource("/yt1193/bar.yang")))
+            .addSource(new URLYangTextSource(YT1193Test.class.getResource("/yt1193/baz.yang")))
             .buildDeclaredModel();
         assertEquals(3, declaredRoots.size());
 
index a192c0ceb2c4818058e7f4a03be4679c7b0f1245..8289b2da2b60987991e923fe16246fa23447c8bc 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.yangtools.yang.parser.repo;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 
 import com.google.common.collect.SetMultimap;
@@ -20,8 +22,8 @@ import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactoryConfiguration;
+import org.opendaylight.yangtools.yang.model.spi.source.URLYangTextSource;
 import org.opendaylight.yangtools.yang.model.spi.source.YangIRSchemaSource;
-import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
 import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
 import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer;
 
@@ -61,13 +63,19 @@ public abstract class AbstractSchemaRepositoryTest {
             .createEffectiveModelContext(requiredSources);
     }
 
-    private static SettableSchemaProvider<YangIRSchemaSource> assertYangTextResource(final String resourceName) {
+    static final SettableSchemaProvider<YangIRSchemaSource> assertYangTextResource(final String resourceName) {
         final YangIRSchemaSource yangSource;
         try {
-            yangSource = TextToIRTransformer.transformText(YangTextSource.forResource(resourceName));
+            yangSource = TextToIRTransformer.transformText(
+                new URLYangTextSource(AbstractSchemaRepositoryTest.class.getResource(resourceName)));
         } catch (YangSyntaxErrorException | IOException e) {
             throw new AssertionError("Failed to parse " + resourceName, e);
         }
         return SettableSchemaProvider.createImmediate(yangSource, YangIRSchemaSource.class);
     }
+
+    static final void assertSchemaContext(final EffectiveModelContext schemaContext, final int moduleSize) {
+        assertNotNull(schemaContext);
+        assertEquals(moduleSize, schemaContext.getModuleStatements().size());
+    }
 }
index 3e34069c7da01b88dfd0dba31d6a1edcb933248a..559842afde95e4931a719826ca233ee8a9afd182 100644 (file)
@@ -18,7 +18,7 @@ import org.opendaylight.yangtools.yang.common.UnresolvedQName.Unqualified;
 import org.opendaylight.yangtools.yang.model.api.source.SourceDependency.BelongsTo;
 import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
 import org.opendaylight.yangtools.yang.model.spi.source.SourceInfo;
-import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
+import org.opendaylight.yangtools.yang.model.spi.source.URLYangTextSource;
 import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangIRSourceInfoExtractor;
 
 class DependencyResolverTest {
@@ -66,7 +66,7 @@ class DependencyResolverTest {
         final var map = new HashMap<SourceIdentifier, SourceInfo>();
         for (var resourceName : resourceNames) {
             final var info = YangIRSourceInfoExtractor.forYangText(
-                YangTextSource.forResource(DependencyResolverTest.class, resourceName));
+                new URLYangTextSource(DependencyResolverTest.class.getResource(resourceName)));
             map.put(info.sourceId(), info);
         }
         return new RevisionDependencyResolver(map);
index 3ba24706e08bccd9cc1d27812601282c9bc0c7dd..df95c30ae07beb9c79aac47729d1fe3d075e7c96 100644 (file)
@@ -20,10 +20,8 @@ import org.junit.jupiter.api.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.spi.source.YangIRSchemaSource;
-import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
-import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer;
 
-public class MultipleRevImportBug6875Test {
+class MultipleRevImportBug6875Test extends AbstractSchemaRepositoryTest {
     private static final String BAR_NS = "bar";
     private static final String BAR_REV_1 = "2017-02-06";
     private static final String BAR_REV_2 = "1999-01-01";
@@ -31,13 +29,13 @@ public class MultipleRevImportBug6875Test {
     private static final String FOO_NS = "foo";
 
     @Test
-    public void testYang11() throws Exception {
+    void testYang11() throws Exception {
         final var sharedSchemaRepository = new SharedSchemaRepository("shared-schema-repo-multiple-rev-import-test");
 
-        final var foo = getSourceProvider("/rfc7950/bug6875/yang1-1/foo.yang");
-        final var bar1 = getSourceProvider("/rfc7950/bug6875/yang1-1/bar@1999-01-01.yang");
-        final var bar2 = getSourceProvider("/rfc7950/bug6875/yang1-1/bar@2017-02-06.yang");
-        final var bar3 = getSourceProvider("/rfc7950/bug6875/yang1-1/bar@1970-01-01.yang");
+        final var foo = assertYangTextResource("/rfc7950/bug6875/yang1-1/foo.yang");
+        final var bar1 = assertYangTextResource("/rfc7950/bug6875/yang1-1/bar@1999-01-01.yang");
+        final var bar2 = assertYangTextResource("/rfc7950/bug6875/yang1-1/bar@2017-02-06.yang");
+        final var bar3 = assertYangTextResource("/rfc7950/bug6875/yang1-1/bar@1970-01-01.yang");
 
         setAndRegister(sharedSchemaRepository, foo);
         setAndRegister(sharedSchemaRepository, bar1);
@@ -69,12 +67,12 @@ public class MultipleRevImportBug6875Test {
     }
 
     @Test
-    public void testYang10() throws Exception {
+    void testYang10() throws Exception {
         final var sharedSchemaRepository = new SharedSchemaRepository("shared-schema-repo-multiple-rev-import-test");
 
-        final var foo = getSourceProvider("/rfc7950/bug6875/yang1-0/foo.yang");
-        final var bar1 = getSourceProvider("/rfc7950/bug6875/yang1-0/bar@1999-01-01.yang");
-        final var bar2 = getSourceProvider("/rfc7950/bug6875/yang1-0/bar@2017-02-06.yang");
+        final var foo = assertYangTextResource("/rfc7950/bug6875/yang1-0/foo.yang");
+        final var bar1 = assertYangTextResource("/rfc7950/bug6875/yang1-0/bar@1999-01-01.yang");
+        final var bar2 = assertYangTextResource("/rfc7950/bug6875/yang1-0/bar@2017-02-06.yang");
 
         setAndRegister(sharedSchemaRepository, foo);
         setAndRegister(sharedSchemaRepository, bar1);
@@ -95,13 +93,6 @@ public class MultipleRevImportBug6875Test {
         source.setResult();
     }
 
-    private static SettableSchemaProvider<YangIRSchemaSource> getSourceProvider(final String resourceName)
-            throws Exception {
-        return SettableSchemaProvider.createImmediate(
-            TextToIRTransformer.transformText(YangTextSource.forResource(resourceName)),
-            YangIRSchemaSource.class);
-    }
-
     private static QName foo(final String localName) {
         return QName.create(FOO_NS, localName);
     }
index bb79fabfa9a0b01344f25941a23e97684aee1b43..239e66b532258a91d234c5df7eed3fd278cf7ab4 100644 (file)
@@ -7,53 +7,31 @@
  */
 package org.opendaylight.yangtools.yang.parser.repo;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
+import com.google.common.util.concurrent.Futures;
 import org.junit.jupiter.api.Test;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.spi.source.YangIRSchemaSource;
-import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
-import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer;
 
-public class OpenconfigVerSharedSchemaRepositoryTest {
+class OpenconfigVerSharedSchemaRepositoryTest extends AbstractSchemaRepositoryTest {
     @Test
-    public void testSharedSchemaRepository() throws Exception {
+    void testSharedSchemaRepository() throws Exception {
         final var sharedSchemaRepository = new SharedSchemaRepository("shared-schema-repo-test");
 
-        final var bar = getImmediateYangSourceProviderFromResource(
-                "/openconfig-version/shared-schema-repository/bar@2016-01-01.yang");
+        final var bar = assertYangTextResource("/openconfig-version/shared-schema-repository/bar@2016-01-01.yang");
         bar.register(sharedSchemaRepository);
         bar.setResult();
-        final var foo = getImmediateYangSourceProviderFromResource(
-                "/openconfig-version/shared-schema-repository/foo.yang");
+        final var foo = assertYangTextResource("/openconfig-version/shared-schema-repository/foo.yang");
         foo.register(sharedSchemaRepository);
         foo.setResult();
-        final var semVer = getImmediateYangSourceProviderFromResource(
-                "/openconfig-version/shared-schema-repository/openconfig-extensions.yang");
+        final var semVer = assertYangTextResource(
+            "/openconfig-version/shared-schema-repository/openconfig-extensions.yang");
         semVer.register(sharedSchemaRepository);
         semVer.setResult();
 
         final var fact = sharedSchemaRepository.createEffectiveModelContextFactory();
         final var inetAndTopologySchemaContextFuture =
                 fact.createEffectiveModelContext(bar.getId(), foo.getId(), semVer.getId());
-        assertTrue(inetAndTopologySchemaContextFuture.isDone());
-        assertSchemaContext(inetAndTopologySchemaContextFuture.get(), 3);
+        assertSchemaContext(Futures.getDone(inetAndTopologySchemaContextFuture), 3);
 
         final var barSchemaContextFuture = fact.createEffectiveModelContext(bar.getId(), semVer.getId());
-        assertTrue(barSchemaContextFuture.isDone());
-        assertSchemaContext(barSchemaContextFuture.get(), 2);
-    }
-
-    private static void assertSchemaContext(final EffectiveModelContext schemaContext, final int moduleSize) {
-        assertNotNull(schemaContext);
-        assertEquals(moduleSize, schemaContext.getModules().size());
-    }
-
-    static SettableSchemaProvider<YangIRSchemaSource> getImmediateYangSourceProviderFromResource(
-            final String resourceName) throws Exception {
-        return SettableSchemaProvider.createImmediate(
-            TextToIRTransformer.transformText(YangTextSource.forResource(resourceName)), YangIRSchemaSource.class);
+        assertSchemaContext(Futures.getDone(barSchemaContextFuture), 2);
     }
 }
index ddfd17e5028be4ccd497ec1c45253a92f9650a9b..26a6953ffc3991facd8a55940baea786583dc8c5 100644 (file)
@@ -23,11 +23,12 @@ import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceExcepti
 import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactoryConfiguration;
 import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource;
 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider;
+import org.opendaylight.yangtools.yang.model.spi.source.URLYangTextSource;
 import org.opendaylight.yangtools.yang.model.spi.source.YangIRSchemaSource;
 import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
 import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer;
 
-public class SharedEffectiveModelContextFactoryTest {
+class SharedEffectiveModelContextFactoryTest {
     private final SharedSchemaRepository repository = new SharedSchemaRepository("test");
     private final SchemaContextFactoryConfiguration config = SchemaContextFactoryConfiguration.getDefault();
 
@@ -35,9 +36,9 @@ public class SharedEffectiveModelContextFactoryTest {
     private SourceIdentifier s2;
 
     @BeforeEach
-    public void setUp() {
-        final var source1 = YangTextSource.forResource("/ietf/ietf-inet-types@2010-09-24.yang");
-        final var source2 = YangTextSource.forResource("/ietf/iana-timezones@2012-07-09.yang");
+    void setUp() {
+        final var source1 = assertYangText("/ietf/ietf-inet-types@2010-09-24.yang");
+        final var source2 = assertYangText("/ietf/iana-timezones@2012-07-09.yang");
         s1 = new SourceIdentifier("ietf-inet-types", "2010-09-24");
         s2 = new SourceIdentifier("iana-timezones", "2012-07-09");
 
@@ -52,20 +53,20 @@ public class SharedEffectiveModelContextFactoryTest {
     }
 
     @Test
-    public void testCreateSchemaContextWithDuplicateRequiredSources() throws Exception {
+    void testCreateSchemaContextWithDuplicateRequiredSources() throws Exception {
         final var sharedSchemaContextFactory = new SharedEffectiveModelContextFactory(repository, config);
         final var schemaContext = sharedSchemaContextFactory.createEffectiveModelContext(s1, s1, s2);
         assertNotNull(schemaContext.get());
     }
 
     @Test
-    public void testSourceRegisteredWithDifferentSI() throws Exception {
-        final var source1 = YangTextSource.forResource("/ietf/ietf-inet-types@2010-09-24.yang");
-        final var source2 = YangTextSource.forResource("/ietf/iana-timezones@2012-07-09.yang");
+    void testSourceRegisteredWithDifferentSI() throws Exception {
+        final var source1 = assertYangText("/ietf/ietf-inet-types@2010-09-24.yang");
+        final var source2 = assertYangText("/ietf/iana-timezones@2012-07-09.yang");
         s1 = source1.sourceId();
         s2 = source2.sourceId();
 
-        final var provider = SharedSchemaRepositoryTest.getImmediateYangSourceProviderFromResource(
+        final var provider = AbstractSchemaRepositoryTest.assertYangTextResource(
             "/no-revision/imported@2012-12-12.yang");
         provider.setResult();
         provider.register(repository);
@@ -82,11 +83,11 @@ public class SharedEffectiveModelContextFactoryTest {
     }
 
     @Test
-    public void testTransientFailureWhilreRetrievingSchemaSource() throws Exception {
+    void testTransientFailureWhilreRetrievingSchemaSource() throws Exception {
         final SourceIdentifier s3 = new SourceIdentifier("network-topology", "2013-10-21");
 
         repository.registerSchemaSource(new TransientFailureProvider(
-            YangTextSource.forResource("/ietf/network-topology@2013-10-21.yang")),
+            assertYangText("/ietf/network-topology@2013-10-21.yang")),
             PotentialSchemaSource.create(s3, YangTextSource.class, 1));
 
         final var sharedSchemaContextFactory = new SharedEffectiveModelContextFactory(repository, config);
@@ -101,6 +102,10 @@ public class SharedEffectiveModelContextFactoryTest {
         assertNotNull(schemaContext.get());
     }
 
+    private static URLYangTextSource assertYangText(final String resourceName) {
+        return new URLYangTextSource(AbstractSchemaRepositoryTest.class.getResource(resourceName));
+    }
+
     /**
      * Schema source provider that fails on first attempt of getSource() and succeeds on every subsequent call
      * to simulate transient failures of source retrieval.
index 79311a99a0e3f0156b33bd1f2cb4bb385a2f93dd..de01a3e5d8aed89f86d9a8a4f2c3ff7144171702 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.yangtools.yang.parser.repo;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertSame;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -20,16 +19,15 @@ import static org.mockito.Mockito.verify;
 
 import java.util.concurrent.ExecutionException;
 import org.junit.jupiter.api.Test;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
 import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
+import org.opendaylight.yangtools.yang.model.spi.source.URLYangTextSource;
 import org.opendaylight.yangtools.yang.model.spi.source.YangIRSchemaSource;
-import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
 import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer;
 
-public class SharedSchemaRepositoryTest {
+class SharedSchemaRepositoryTest extends AbstractSchemaRepositoryTest {
     @Test
-    public void testSourceWithAndWithoutRevision() throws Exception {
+    void testSourceWithAndWithoutRevision() throws Exception {
         final var sharedSchemaRepository = new SharedSchemaRepository("netconf-mounts");
 
         final var idNoRevision = loadAndRegisterSource(sharedSchemaRepository, "/no-revision/imported.yang");
@@ -43,7 +41,7 @@ public class SharedSchemaRepositoryTest {
 
     private static SourceIdentifier loadAndRegisterSource(final SharedSchemaRepository sharedSchemaRepository,
             final String resourceName) throws Exception {
-        final var sourceProvider = getImmediateYangSourceProviderFromResource(resourceName);
+        final var sourceProvider = assertYangTextResource(resourceName);
         sourceProvider.setResult();
         final var idNoRevision = sourceProvider.getId();
         sourceProvider.register(sharedSchemaRepository);
@@ -51,11 +49,10 @@ public class SharedSchemaRepositoryTest {
     }
 
     @Test
-    public void testSimpleSchemaContext() throws Exception {
+    void testSimpleSchemaContext() throws Exception {
         final var sharedSchemaRepository = new SharedSchemaRepository("netconf-mounts");
 
-        final var remoteInetTypesYang =
-            getImmediateYangSourceProviderFromResource("/ietf/ietf-inet-types@2010-09-24.yang");
+        final var remoteInetTypesYang = assertYangTextResource("/ietf/ietf-inet-types@2010-09-24.yang");
         remoteInetTypesYang.register(sharedSchemaRepository);
         final var registeredSourceFuture = sharedSchemaRepository.getSchemaSource(
             remoteInetTypesYang.getId(), YangIRSchemaSource.class);
@@ -85,19 +82,16 @@ public class SharedSchemaRepositoryTest {
     }
 
     @Test
-    public void testTwoSchemaContextsSharingSource() throws Exception {
+    void testTwoSchemaContextsSharingSource() throws Exception {
         final var sharedSchemaRepository = new SharedSchemaRepository("netconf-mounts");
 
-        final var remoteInetTypesYang =
-            getImmediateYangSourceProviderFromResource("/ietf/ietf-inet-types@2010-09-24.yang");
+        final var remoteInetTypesYang = assertYangTextResource("/ietf/ietf-inet-types@2010-09-24.yang");
         remoteInetTypesYang.register(sharedSchemaRepository);
         remoteInetTypesYang.setResult();
-        final var remoteTopologyYang =
-            getImmediateYangSourceProviderFromResource("/ietf/network-topology@2013-10-21.yang");
+        final var remoteTopologyYang = assertYangTextResource("/ietf/network-topology@2013-10-21.yang");
         remoteTopologyYang.register(sharedSchemaRepository);
         remoteTopologyYang.setResult();
-        final var remoteModuleNoRevYang =
-            getImmediateYangSourceProviderFromResource("/no-revision/module-without-revision.yang");
+        final var remoteModuleNoRevYang = assertYangTextResource("/no-revision/module-without-revision.yang");
         remoteModuleNoRevYang.register(sharedSchemaRepository);
 
         final var fact = sharedSchemaRepository.createEffectiveModelContextFactory();
@@ -116,11 +110,10 @@ public class SharedSchemaRepositoryTest {
     }
 
     @Test
-    public void testFailedSchemaContext() throws Exception {
+    void testFailedSchemaContext() throws Exception {
         final var sharedSchemaRepository = new SharedSchemaRepository("netconf-mounts");
 
-        final var remoteInetTypesYang =
-            getImmediateYangSourceProviderFromResource("/ietf/ietf-inet-types@2010-09-24.yang");
+        final var remoteInetTypesYang = assertYangTextResource("/ietf/ietf-inet-types@2010-09-24.yang");
         remoteInetTypesYang.register(sharedSchemaRepository);
 
         final var fact = sharedSchemaRepository.createEffectiveModelContextFactory();
@@ -136,11 +129,10 @@ public class SharedSchemaRepositoryTest {
     }
 
     @Test
-    public void testDifferentCosts() throws Exception {
+    void testDifferentCosts() throws Exception {
         final var sharedSchemaRepository = new SharedSchemaRepository("netconf-mounts");
 
-        final var immediateInetTypesYang = spy(
-            getImmediateYangSourceProviderFromResource("/ietf/ietf-inet-types@2010-09-24.yang"));
+        final var immediateInetTypesYang = spy(assertYangTextResource("/ietf/ietf-inet-types@2010-09-24.yang"));
         immediateInetTypesYang.register(sharedSchemaRepository);
         immediateInetTypesYang.setResult();
 
@@ -159,20 +151,10 @@ public class SharedSchemaRepositoryTest {
         verify(immediateInetTypesYang).getSource(id);
     }
 
-    private static void assertSchemaContext(final EffectiveModelContext schemaContext, final int moduleSize) {
-        assertNotNull(schemaContext);
-        assertEquals(moduleSize, schemaContext.getModules().size());
-    }
-
     static SettableSchemaProvider<YangIRSchemaSource> getRemoteYangSourceProviderFromResource(final String resourceName)
             throws Exception {
-        return SettableSchemaProvider.createRemote(
-            TextToIRTransformer.transformText(YangTextSource.forResource(resourceName)), YangIRSchemaSource.class);
-    }
-
-    static SettableSchemaProvider<YangIRSchemaSource> getImmediateYangSourceProviderFromResource(
-            final String resourceName) throws Exception {
-        return SettableSchemaProvider.createImmediate(
-            TextToIRTransformer.transformText(YangTextSource.forResource(resourceName)), YangIRSchemaSource.class);
+        return SettableSchemaProvider.createRemote(TextToIRTransformer.transformText(
+            new URLYangTextSource(SharedSchemaRepositoryTest.class.getResource(resourceName))),
+            YangIRSchemaSource.class);
     }
 }
index 4cfd3b3f0a7cf4741f2ffd12a8eed334f9ac078b..0df6bec0b6cb1c62e5216bee2193636e37bbcb67 100644 (file)
@@ -17,22 +17,17 @@ import org.junit.jupiter.api.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.stmt.FeatureSet;
 import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactoryConfiguration;
-import org.opendaylight.yangtools.yang.model.spi.source.YangIRSchemaSource;
-import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
-import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer;
 
-public class SharedSchemaRepositoryWithFeaturesTest {
+class SharedSchemaRepositoryWithFeaturesTest extends AbstractSchemaRepositoryTest {
     @Test
-    public void testSharedSchemaRepositoryWithSomeFeaturesSupported() throws Exception {
+    void testSharedSchemaRepositoryWithSomeFeaturesSupported() throws Exception {
         final var supportedFeatures = FeatureSet.of(QName.create("foobar-namespace", "test-feature-1"));
 
         final var sharedSchemaRepository = new SharedSchemaRepository("shared-schema-repo-with-features-test");
 
-        final var foobar = getImmediateYangSourceProviderFromResource(
-            "/if-feature-resolution-test/shared-schema-repository/foobar.yang");
+        final var foobar = assertYangTextResource("/if-feature-resolution-test/shared-schema-repository/foobar.yang");
         foobar.register(sharedSchemaRepository);
         foobar.setResult();
 
@@ -60,11 +55,10 @@ public class SharedSchemaRepositoryWithFeaturesTest {
     }
 
     @Test
-    public void testSharedSchemaRepositoryWithAllFeaturesSupported() throws Exception {
+    void testSharedSchemaRepositoryWithAllFeaturesSupported() throws Exception {
         final var sharedSchemaRepository = new SharedSchemaRepository("shared-schema-repo-with-features-test");
 
-        final var foobar = getImmediateYangSourceProviderFromResource(
-            "/if-feature-resolution-test/shared-schema-repository/foobar.yang");
+        final var foobar = assertYangTextResource("/if-feature-resolution-test/shared-schema-repository/foobar.yang");
         foobar.register(sharedSchemaRepository);
         foobar.setResult();
 
@@ -94,11 +88,10 @@ public class SharedSchemaRepositoryWithFeaturesTest {
     }
 
     @Test
-    public void testSharedSchemaRepositoryWithNoFeaturesSupported() throws Exception {
+    void testSharedSchemaRepositoryWithNoFeaturesSupported() throws Exception {
         final var sharedSchemaRepository = new SharedSchemaRepository("shared-schema-repo-with-features-test");
 
-        final var foobar = getImmediateYangSourceProviderFromResource(
-            "/if-feature-resolution-test/shared-schema-repository/foobar.yang");
+        final var foobar = assertYangTextResource("/if-feature-resolution-test/shared-schema-repository/foobar.yang");
         foobar.register(sharedSchemaRepository);
         foobar.setResult();
 
@@ -117,15 +110,4 @@ public class SharedSchemaRepositoryWithFeaturesTest {
         assertInstanceOf(LeafSchemaNode.class,
             testContainerC.dataChildByName(QName.create(module.getQNameModule(), "test-leaf-c")));
     }
-
-    private static SettableSchemaProvider<YangIRSchemaSource> getImmediateYangSourceProviderFromResource(
-            final String resourceName) throws Exception {
-        return SettableSchemaProvider.createImmediate(
-            TextToIRTransformer.transformText(YangTextSource.forResource(resourceName)), YangIRSchemaSource.class);
-    }
-
-    private static void assertSchemaContext(final SchemaContext schemaContext, final int moduleSize) {
-        assertNotNull(schemaContext);
-        assertEquals(moduleSize, schemaContext.getModules().size());
-    }
 }
index 77e19efb6360be33f48f48f34546f20f64eb0ce4..74fd6e2c34534c02ccd7deb2c16eb583ce5a1e1d 100644 (file)
@@ -28,6 +28,7 @@ import org.opendaylight.yangtools.yang.common.YangConstants;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.source.SourceRepresentation;
 import org.opendaylight.yangtools.yang.model.api.stmt.FeatureSet;
+import org.opendaylight.yangtools.yang.model.spi.source.URLYangTextSource;
 import org.opendaylight.yangtools.yang.model.spi.source.YangTextSource;
 import org.opendaylight.yangtools.yang.parser.api.YangParser;
 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
@@ -108,7 +109,7 @@ public final class YangParserTestUtils {
     public static EffectiveModelContext parseYangResource(final String resource, final YangParserConfiguration config,
             final Set<QName> supportedFeatures) {
         return parseYangSources(config, supportedFeatures,
-            YangTextSource.forResource(YangParserTestUtils.class, resource));
+            new URLYangTextSource(YangParserTestUtils.class.getResource(resource)));
     }
 
     /**
@@ -275,11 +276,9 @@ public final class YangParserTestUtils {
     }
 
     public static EffectiveModelContext parseYangResources(final Class<?> clazz, final Collection<String> resources) {
-        final var sources = new ArrayList<YangTextSource>(resources.size());
-        for (final String r : resources) {
-            sources.add(YangTextSource.forResource(clazz, r));
-        }
-        return parseSources(YangParserConfiguration.DEFAULT, null, sources);
+        return parseSources(YangParserConfiguration.DEFAULT, null, resources.stream()
+            .map(resource -> new URLYangTextSource(clazz.getResource(resource)))
+            .toList());
     }
 
     /**