BUG-9043: Remove use of CheckedFuture from YANG components
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / parser / repo / SharedSchemaRepositoryTest.java
index 9a8790a428cf4f9eb1764d8c7941d86f1c9d2970..93ea3cd3c9d694e99e237c0fc55c8a66063ce220 100644 (file)
@@ -8,68 +8,95 @@
 
 package org.opendaylight.yangtools.yang.parser.repo;
 
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertFalse;
-import static junit.framework.Assert.assertNotNull;
-import static junit.framework.Assert.assertSame;
-import static junit.framework.Assert.assertTrue;
-import static junit.framework.Assert.fail;
+import static org.hamcrest.CoreMatchers.both;
+import static org.hamcrest.CoreMatchers.hasItem;
 import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.matchers.JUnitMatchers.both;
-import static org.junit.matchers.JUnitMatchers.hasItem;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
+import static org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceFilter.ALWAYS_ACCEPT;
 
-import com.google.common.base.Function;
-import com.google.common.base.Objects;
-import com.google.common.base.Optional;
-import com.google.common.collect.Collections2;
+import com.google.common.base.MoreObjects.ToStringHelper;
+import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
 import com.google.common.io.Files;
-import com.google.common.io.InputSupplier;
-import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.MoreExecutors;
+import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.Optional;
 import java.util.concurrent.ExecutionException;
-import org.apache.commons.io.IOUtils;
+import javax.annotation.Nonnull;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
+import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
 import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactory;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceFilter;
 import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
 import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource;
 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceListener;
-import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider;
 import org.opendaylight.yangtools.yang.model.repo.util.FilesystemSchemaSourceCache;
 import org.opendaylight.yangtools.yang.parser.util.ASTSchemaSource;
 import org.opendaylight.yangtools.yang.parser.util.TextToASTTransformer;
 
 public class SharedSchemaRepositoryTest {
 
+    @Test
+    public void testSourceWithAndWithoutRevision() throws Exception {
+        final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository("netconf-mounts");
+
+        final SourceIdentifier idNoRevision = loadAndRegisterSource(sharedSchemaRepository,
+            "/no-revision/imported.yang");
+        final SourceIdentifier id2 = loadAndRegisterSource(sharedSchemaRepository,
+            "/no-revision/imported@2012-12-12.yang");
+
+        ListenableFuture<ASTSchemaSource> source = sharedSchemaRepository.getSchemaSource(idNoRevision,
+            ASTSchemaSource.class);
+        assertEquals(idNoRevision, source.get().getIdentifier());
+        source = sharedSchemaRepository.getSchemaSource(id2, ASTSchemaSource.class);
+        assertEquals(id2, source.get().getIdentifier());
+    }
+
+    private static SourceIdentifier loadAndRegisterSource(final SharedSchemaRepository sharedSchemaRepository,
+            final String resourceName) throws Exception {
+        final SettableSchemaProvider<ASTSchemaSource> sourceProvider = getImmediateYangSourceProviderFromResource(
+            resourceName);
+        sourceProvider.setResult();
+        final SourceIdentifier idNoRevision = sourceProvider.getId();
+        sourceProvider.register(sharedSchemaRepository);
+        return idNoRevision;
+    }
+
     @Test
     public void testSimpleSchemaContext() throws Exception {
         final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository("netconf-mounts");
 
-        final SettableSchemaProvider<ASTSchemaSource> remoteInetTypesYang = getImmediateYangSourceProviderFromResource("/ietf/ietf-inet-types@2010-09-24.yang");
+        final SettableSchemaProvider<ASTSchemaSource> remoteInetTypesYang = getImmediateYangSourceProviderFromResource(
+            "/ietf/ietf-inet-types@2010-09-24.yang");
         remoteInetTypesYang.register(sharedSchemaRepository);
-        final CheckedFuture<ASTSchemaSource, SchemaSourceException> registeredSourceFuture = sharedSchemaRepository.getSchemaSource(remoteInetTypesYang.getId(), ASTSchemaSource.class);
+        final ListenableFuture<ASTSchemaSource> registeredSourceFuture = sharedSchemaRepository.getSchemaSource(
+            remoteInetTypesYang.getId(), ASTSchemaSource.class);
         assertFalse(registeredSourceFuture.isDone());
 
-        final SchemaContextFactory fact = sharedSchemaRepository.createSchemaContextFactory(SchemaSourceFilter.ALWAYS_ACCEPT);
-
-        final CheckedFuture<SchemaContext, SchemaResolutionException> schemaContextFuture
-                = fact.createSchemaContext(Lists.newArrayList(remoteInetTypesYang.getId()));
+        final SchemaContextFactory fact = sharedSchemaRepository.createSchemaContextFactory(ALWAYS_ACCEPT);
+        final ListenableFuture<SchemaContext> schemaContextFuture =
+                fact.createSchemaContext(ImmutableList.of(remoteInetTypesYang.getId()));
 
         assertFalse(schemaContextFuture.isDone());
 
@@ -79,68 +106,71 @@ public class SharedSchemaRepositoryTest {
 
         // Verify schema created successfully
         assertTrue(schemaContextFuture.isDone());
-        final SchemaContext firstSchemaContext = schemaContextFuture.checkedGet();
+        final SchemaContext firstSchemaContext = schemaContextFuture.get();
         assertSchemaContext(firstSchemaContext, 1);
 
         // Try same schema second time
-        final CheckedFuture<SchemaContext, SchemaResolutionException> secondSchemaFuture =
-                sharedSchemaRepository.createSchemaContextFactory(SchemaSourceFilter.ALWAYS_ACCEPT)
-                        .createSchemaContext(Lists.newArrayList(remoteInetTypesYang.getId()));
+        final ListenableFuture<SchemaContext> secondSchemaFuture = sharedSchemaRepository
+                .createSchemaContextFactory(ALWAYS_ACCEPT)
+                .createSchemaContext(ImmutableList.of(remoteInetTypesYang.getId()));
 
         // Verify second schema created successfully immediately
         assertTrue(secondSchemaFuture.isDone());
         // Assert same context instance is returned from first and second attempt
-        assertSame(firstSchemaContext, secondSchemaFuture.checkedGet());
+        assertSame(firstSchemaContext, secondSchemaFuture.get());
     }
 
     @Test
     public void testTwoSchemaContextsSharingSource() throws Exception {
         final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository("netconf-mounts");
 
-        final SettableSchemaProvider<ASTSchemaSource> remoteInetTypesYang = getImmediateYangSourceProviderFromResource("/ietf/ietf-inet-types@2010-09-24.yang");
+        final SettableSchemaProvider<ASTSchemaSource> remoteInetTypesYang = getImmediateYangSourceProviderFromResource(
+            "/ietf/ietf-inet-types@2010-09-24.yang");
         remoteInetTypesYang.register(sharedSchemaRepository);
         remoteInetTypesYang.setResult();
-        final SettableSchemaProvider<ASTSchemaSource> remoteTopologyYang = getImmediateYangSourceProviderFromResource("/ietf/network-topology@2013-10-21.yang");
+        final SettableSchemaProvider<ASTSchemaSource> remoteTopologyYang = getImmediateYangSourceProviderFromResource(
+            "/ietf/network-topology@2013-10-21.yang");
         remoteTopologyYang.register(sharedSchemaRepository);
         remoteTopologyYang.setResult();
-        final SettableSchemaProvider<ASTSchemaSource> remoteModuleNoRevYang = getImmediateYangSourceProviderFromResource("/no-revision/module-without-revision.yang");
+        final SettableSchemaProvider<ASTSchemaSource> remoteModuleNoRevYang =
+                getImmediateYangSourceProviderFromResource("/no-revision/module-without-revision.yang");
         remoteModuleNoRevYang.register(sharedSchemaRepository);
 
-        final SchemaContextFactory fact = sharedSchemaRepository.createSchemaContextFactory(SchemaSourceFilter.ALWAYS_ACCEPT);
-
-        final CheckedFuture<SchemaContext, SchemaResolutionException> inetAndTopologySchemaContextFuture
-                = fact.createSchemaContext(Lists.newArrayList(remoteInetTypesYang.getId(), remoteTopologyYang.getId()));
+        final SchemaContextFactory fact = sharedSchemaRepository.createSchemaContextFactory(ALWAYS_ACCEPT);
+        final ListenableFuture<SchemaContext> inetAndTopologySchemaContextFuture = fact
+                .createSchemaContext(ImmutableList.of(remoteInetTypesYang.getId(), remoteTopologyYang.getId()));
         assertTrue(inetAndTopologySchemaContextFuture.isDone());
-        assertSchemaContext(inetAndTopologySchemaContextFuture.checkedGet(), 2);
+        assertSchemaContext(inetAndTopologySchemaContextFuture.get(), 2);
 
-        final CheckedFuture<SchemaContext, SchemaResolutionException> inetAndNoRevSchemaContextFuture
-                = fact.createSchemaContext(Lists.newArrayList(remoteInetTypesYang.getId(), remoteModuleNoRevYang.getId()));
+        final ListenableFuture<SchemaContext> inetAndNoRevSchemaContextFuture =
+                fact.createSchemaContext(ImmutableList.of(remoteInetTypesYang.getId(), remoteModuleNoRevYang.getId()));
         assertFalse(inetAndNoRevSchemaContextFuture.isDone());
 
         remoteModuleNoRevYang.setResult();
         assertTrue(inetAndNoRevSchemaContextFuture.isDone());
-        assertSchemaContext(inetAndNoRevSchemaContextFuture.checkedGet(), 2);
+        assertSchemaContext(inetAndNoRevSchemaContextFuture.get(), 2);
     }
 
     @Test
     public void testFailedSchemaContext() throws Exception {
         final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository("netconf-mounts");
 
-        final SettableSchemaProvider<ASTSchemaSource> remoteInetTypesYang = getImmediateYangSourceProviderFromResource("/ietf/ietf-inet-types@2010-09-24.yang");
+        final SettableSchemaProvider<ASTSchemaSource> remoteInetTypesYang = getImmediateYangSourceProviderFromResource(
+            "/ietf/ietf-inet-types@2010-09-24.yang");
         remoteInetTypesYang.register(sharedSchemaRepository);
 
-        final SchemaContextFactory fact = sharedSchemaRepository.createSchemaContextFactory(SchemaSourceFilter.ALWAYS_ACCEPT);
+        final SchemaContextFactory fact = sharedSchemaRepository.createSchemaContextFactory(ALWAYS_ACCEPT);
 
         // Make source appear
         final Throwable ex = new IllegalStateException("failed schema");
         remoteInetTypesYang.setException(ex);
 
-        final CheckedFuture<SchemaContext, SchemaResolutionException> schemaContextFuture
-                = fact.createSchemaContext(Lists.newArrayList(remoteInetTypesYang.getId()));
+        final ListenableFuture<SchemaContext> schemaContextFuture = fact.createSchemaContext(
+            ImmutableList.of(remoteInetTypesYang.getId()));
 
         try {
-            schemaContextFuture.checkedGet();
-        } catch (final SchemaResolutionException e) {
+            schemaContextFuture.get();
+        } catch (final ExecutionException e) {
             assertNotNull(e.getCause());
             assertNotNull(e.getCause().getCause());
             assertSame(ex, e.getCause().getCause());
@@ -154,20 +184,22 @@ public class SharedSchemaRepositoryTest {
     public void testDifferentCosts() throws Exception {
         final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository("netconf-mounts");
 
-        final SettableSchemaProvider<ASTSchemaSource> immediateInetTypesYang = spy(getImmediateYangSourceProviderFromResource("/ietf/ietf-inet-types@2010-09-24.yang"));
+        final SettableSchemaProvider<ASTSchemaSource> immediateInetTypesYang = spy(
+            getImmediateYangSourceProviderFromResource("/ietf/ietf-inet-types@2010-09-24.yang"));
         immediateInetTypesYang.register(sharedSchemaRepository);
         immediateInetTypesYang.setResult();
 
-        final SettableSchemaProvider<ASTSchemaSource> remoteInetTypesYang = spy(getRemoteYangSourceProviderFromResource("/ietf/ietf-inet-types@2010-09-24.yang"));
+        final SettableSchemaProvider<ASTSchemaSource> remoteInetTypesYang = spy(
+            getRemoteYangSourceProviderFromResource("/ietf/ietf-inet-types@2010-09-24.yang"));
         remoteInetTypesYang.register(sharedSchemaRepository);
         remoteInetTypesYang.setResult();
 
-        final SchemaContextFactory fact = sharedSchemaRepository.createSchemaContextFactory(SchemaSourceFilter.ALWAYS_ACCEPT);
+        final SchemaContextFactory fact = sharedSchemaRepository.createSchemaContextFactory(ALWAYS_ACCEPT);
 
-        final CheckedFuture<SchemaContext, SchemaResolutionException> schemaContextFuture
-                = fact.createSchemaContext(Lists.newArrayList(remoteInetTypesYang.getId()));
+        final ListenableFuture<SchemaContext> schemaContextFuture =
+                fact.createSchemaContext(ImmutableList.of(remoteInetTypesYang.getId()));
 
-        assertSchemaContext(schemaContextFuture.checkedGet(), 1);
+        assertSchemaContext(schemaContextFuture.get(), 1);
 
         final SourceIdentifier id = immediateInetTypesYang.getId();
         verify(remoteInetTypesYang, times(0)).getSource(id);
@@ -179,7 +211,7 @@ public class SharedSchemaRepositoryTest {
         final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository("netconf-mounts");
 
         class CountingSchemaListener implements SchemaSourceListener {
-            List<PotentialSchemaSource<?>> registeredSources = Lists.newArrayList();
+            List<PotentialSchemaSource<?>> registeredSources = new ArrayList<>();
 
             @Override
             public void schemaSourceEncountered(final SchemaSourceRepresentation source) {
@@ -203,34 +235,28 @@ public class SharedSchemaRepositoryTest {
         sharedSchemaRepository.registerSchemaSourceListener(listener);
 
         final File test = new File(storageDir, "test.yang");
-        Files.copy(new StringSupplier("content-test"), test);
+        Files.asCharSink(test, StandardCharsets.UTF_8).write("content-test");
 
         final File test2 = new File(storageDir, "test@2012-12-12.yang");
-        Files.copy(new StringSupplier("content-test-2012"), test2);
+        Files.asCharSink(test2, StandardCharsets.UTF_8).write("content-test-2012");
 
         final File test3 = new File(storageDir, "test@2013-12-12.yang");
-        Files.copy(new StringSupplier("content-test-2013"), test3);
+        Files.asCharSink(test3, StandardCharsets.UTF_8).write("content-test-2013");
 
         final File test4 = new File(storageDir, "module@2010-12-12.yang");
-        Files.copy(new StringSupplier("content-module-2010"), test4);
-
+        Files.asCharSink(test4, StandardCharsets.UTF_8).write("content-module-2010");
 
-        final FilesystemSchemaSourceCache<YangTextSchemaSource> cache = new FilesystemSchemaSourceCache<>(sharedSchemaRepository, YangTextSchemaSource.class, storageDir);
+        final FilesystemSchemaSourceCache<YangTextSchemaSource> cache = new FilesystemSchemaSourceCache<>(
+                sharedSchemaRepository, YangTextSchemaSource.class, storageDir);
         sharedSchemaRepository.registerSchemaSourceListener(cache);
 
         assertEquals(4, listener.registeredSources.size());
 
-        final Function<PotentialSchemaSource<?>, SourceIdentifier> potSourceToSID = new Function<PotentialSchemaSource<?>, SourceIdentifier>() {
-            @Override
-            public SourceIdentifier apply(final PotentialSchemaSource<?> input) {
-                return input.getSourceIdentifier();
-            }
-        };
-        assertThat(Collections2.transform(listener.registeredSources, potSourceToSID),
-                both(hasItem(new SourceIdentifier("test", Optional.<String>absent())))
-                        .and(hasItem(new SourceIdentifier("test", Optional.of("2012-12-12"))))
-                        .and(hasItem(new SourceIdentifier("test", Optional.of("2013-12-12"))))
-                        .and(hasItem(new SourceIdentifier("module", Optional.of("2010-12-12"))))
+        assertThat(Lists.transform(listener.registeredSources, PotentialSchemaSource::getSourceIdentifier),
+                both(hasItem(RevisionSourceIdentifier.create("test", Optional.empty())))
+                        .and(hasItem(RevisionSourceIdentifier.create("test", Optional.of("2012-12-12"))))
+                        .and(hasItem(RevisionSourceIdentifier.create("test", Optional.of("2013-12-12"))))
+                        .and(hasItem(RevisionSourceIdentifier.create("module", Optional.of("2010-12-12"))))
         );
     }
 
@@ -240,33 +266,33 @@ public class SharedSchemaRepositoryTest {
 
         final File storageDir = Files.createTempDir();
 
-        final FilesystemSchemaSourceCache<YangTextSchemaSource> cache = new FilesystemSchemaSourceCache<>(sharedSchemaRepository, YangTextSchemaSource.class, storageDir);
+        final FilesystemSchemaSourceCache<YangTextSchemaSource> cache = new FilesystemSchemaSourceCache<>(
+                sharedSchemaRepository, YangTextSchemaSource.class, storageDir);
         sharedSchemaRepository.registerSchemaSourceListener(cache);
 
-        final SourceIdentifier runningId = new SourceIdentifier("running", Optional.of("2012-12-12"));
+        final SourceIdentifier runningId = RevisionSourceIdentifier.create("running", Optional.of("2012-12-12"));
 
-        sharedSchemaRepository.registerSchemaSource(new SchemaSourceProvider<YangTextSchemaSource>() {
-            @Override
-            public CheckedFuture<YangTextSchemaSource, SchemaSourceException> getSource(final SourceIdentifier sourceIdentifier) {
-                return Futures.<YangTextSchemaSource, SchemaSourceException>immediateCheckedFuture(new YangTextSchemaSource(runningId) {
-                    @Override
-                    protected Objects.ToStringHelper addToStringAttributes(final Objects.ToStringHelper toStringHelper) {
-                        return toStringHelper;
-                    }
-
-                    @Override
-                    public InputStream openStream() throws IOException {
-                        return IOUtils.toInputStream("running");
-                    }
-                });
-            }
-        }, PotentialSchemaSource.create(runningId, YangTextSchemaSource.class, PotentialSchemaSource.Costs.REMOTE_IO.getValue()));
+        sharedSchemaRepository.registerSchemaSource(sourceIdentifier -> Futures.immediateFuture(
+            new YangTextSchemaSource(runningId) {
+                @Override
+                protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
+                    return toStringHelper;
+                }
+
+                @Override
+                public InputStream openStream() throws IOException {
+                    return new ByteArrayInputStream("running".getBytes(StandardCharsets.UTF_8));
+                }
+            }), PotentialSchemaSource.create(runningId, YangTextSchemaSource.class,
+                PotentialSchemaSource.Costs.REMOTE_IO.getValue()));
 
-        final TextToASTTransformer transformer = TextToASTTransformer.create(sharedSchemaRepository, sharedSchemaRepository);
+        final TextToASTTransformer transformer = TextToASTTransformer.create(sharedSchemaRepository,
+            sharedSchemaRepository);
         sharedSchemaRepository.registerSchemaSourceListener(transformer);
 
         // Request schema to make repository notify the cache
-        final CheckedFuture<SchemaContext, SchemaResolutionException> schemaFuture = sharedSchemaRepository.createSchemaContextFactory(SchemaSourceFilter.ALWAYS_ACCEPT).createSchemaContext(Lists.newArrayList(runningId));
+        final ListenableFuture<SchemaContext> schemaFuture = sharedSchemaRepository
+                .createSchemaContextFactory(ALWAYS_ACCEPT).createSchemaContext(ImmutableList.of(runningId));
         Futures.addCallback(schemaFuture, new FutureCallback<SchemaContext>() {
             @Override
             public void onSuccess(final SchemaContext result) {
@@ -274,13 +300,14 @@ public class SharedSchemaRepositoryTest {
             }
 
             @Override
-            public void onFailure(final Throwable t) {
-                // Creation of schema context fails, since we do not provide regular sources, but we just want to check cache
+            public void onFailure(@Nonnull final Throwable cause) {
+                // Creation of schema context fails, since we do not provide regular sources, but we just want
+                // to check cache
                 final List<File> cachedSchemas = Arrays.asList(storageDir.listFiles());
                 assertEquals(1, cachedSchemas.size());
                 assertEquals(Files.getNameWithoutExtension(cachedSchemas.get(0).getName()), "running@2012-12-12");
             }
-        });
+        }, MoreExecutors.directExecutor());
 
         try {
             schemaFuture.get();
@@ -293,33 +320,22 @@ public class SharedSchemaRepositoryTest {
         fail("Creation of schema context should fail from non-regular sources");
     }
 
-    private void assertSchemaContext(final SchemaContext schemaContext, final int moduleSize) {
+    private static void assertSchemaContext(final SchemaContext schemaContext, final int moduleSize) {
         assertNotNull(schemaContext);
         assertEquals(moduleSize, schemaContext.getModules().size());
     }
 
-    private SettableSchemaProvider<ASTSchemaSource> getRemoteYangSourceProviderFromResource(final String resourceName) throws Exception {
-        final ResourceYangSource yangSource = new ResourceYangSource(resourceName);
-        final CheckedFuture<ASTSchemaSource, SchemaSourceException> aSTSchemaSource = TextToASTTransformer.TRANSFORMATION.apply(yangSource);
-        return SettableSchemaProvider.createRemote(aSTSchemaSource.get(), ASTSchemaSource.class);
+    static SettableSchemaProvider<ASTSchemaSource> getRemoteYangSourceProviderFromResource(final String resourceName)
+            throws Exception {
+        final YangTextSchemaSource yangSource = YangTextSchemaSource.forResource(resourceName);
+        return SettableSchemaProvider.createRemote(TextToASTTransformer.transformText(yangSource),
+            ASTSchemaSource.class);
     }
 
-    private SettableSchemaProvider<ASTSchemaSource> getImmediateYangSourceProviderFromResource(final String resourceName) throws Exception {
-        final ResourceYangSource yangSource = new ResourceYangSource(resourceName);
-        final CheckedFuture<ASTSchemaSource, SchemaSourceException> aSTSchemaSource = TextToASTTransformer.TRANSFORMATION.apply(yangSource);
-        return SettableSchemaProvider.createImmediate(aSTSchemaSource.get(), ASTSchemaSource.class);
-    }
-
-    private class StringSupplier implements InputSupplier<InputStream> {
-        private final String s;
-
-        public StringSupplier(final String s) {
-            this.s = s;
-        }
-
-        @Override
-        public InputStream getInput() throws IOException {
-            return IOUtils.toInputStream(s);
-        }
+    static SettableSchemaProvider<ASTSchemaSource> getImmediateYangSourceProviderFromResource(final String resourceName)
+            throws Exception {
+        final YangTextSchemaSource yangSource = YangTextSchemaSource.forResource(resourceName);
+        return SettableSchemaProvider.createImmediate(TextToASTTransformer.transformText(yangSource),
+            ASTSchemaSource.class);
     }
 }