Remove deprecated SchemaRepository.createSchemaContextFactory()
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / parser / repo / SharedSchemaRepositoryWithFeaturesTest.java
index 3c4bf25ef922f2bbd139ac5c2524844df4875754..f6832e463a92996825226316bff2037bd2bd6626 100644 (file)
@@ -13,9 +13,9 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
+import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Lists;
-import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.ListenableFuture;
 import java.util.Set;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -24,34 +24,31 @@ 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.repo.api.SchemaContextFactory;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceFilter;
-import org.opendaylight.yangtools.yang.parser.util.ASTSchemaSource;
-import org.opendaylight.yangtools.yang.parser.util.TextToASTTransformer;
+import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.parser.rfc7950.repo.ASTSchemaSource;
+import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToASTTransformer;
 
 public class SharedSchemaRepositoryWithFeaturesTest {
 
     @Test
     public void testSharedSchemaRepositoryWithSomeFeaturesSupported() throws Exception {
-        final Set<QName> supportedFeatures = ImmutableSet.of(QName.create("foobar-namespace", "1970-01-01", "test-feature-1"));
+        final Set<QName> supportedFeatures = ImmutableSet.of(QName.create("foobar-namespace", "test-feature-1"));
 
         final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository(
                 "shared-schema-repo-with-features-test");
 
-        final SettableSchemaProvider<ASTSchemaSource> foobar = getImmediateYangSourceProviderFromResource
-                ("/if-feature-resolution-test/shared-schema-repository/foobar.yang");
+        final SettableSchemaProvider<ASTSchemaSource> foobar = getImmediateYangSourceProviderFromResource(
+            "/if-feature-resolution-test/shared-schema-repository/foobar.yang");
         foobar.register(sharedSchemaRepository);
         foobar.setResult();
 
-        final SchemaContextFactory fact = sharedSchemaRepository
-                .createSchemaContextFactory(SchemaSourceFilter.ALWAYS_ACCEPT);
-
-        final CheckedFuture<SchemaContext, SchemaResolutionException> testSchemaContextFuture =
-                fact.createSchemaContext(Lists.newArrayList(foobar.getId()), supportedFeatures);
+        final SchemaContextFactory fact = sharedSchemaRepository.createSchemaContextFactory();
+        final ListenableFuture<SchemaContext> testSchemaContextFuture =
+                fact.createSchemaContext(ImmutableList.of(foobar.getId()), supportedFeatures);
         assertTrue(testSchemaContextFuture.isDone());
-        assertSchemaContext(testSchemaContextFuture.checkedGet(), 1);
+        assertSchemaContext(testSchemaContextFuture.get(), 1);
 
-        final Module module = testSchemaContextFuture.checkedGet().findModuleByName("foobar", null);
+        final Module module = testSchemaContextFuture.get().findModules("foobar").iterator().next();
         assertNotNull(module);
         assertEquals(2, module.getChildNodes().size());
 
@@ -79,20 +76,18 @@ public class SharedSchemaRepositoryWithFeaturesTest {
         final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository(
                 "shared-schema-repo-with-features-test");
 
-        final SettableSchemaProvider<ASTSchemaSource> foobar = getImmediateYangSourceProviderFromResource
-                ("/if-feature-resolution-test/shared-schema-repository/foobar.yang");
+        final SettableSchemaProvider<ASTSchemaSource> foobar = getImmediateYangSourceProviderFromResource(
+            "/if-feature-resolution-test/shared-schema-repository/foobar.yang");
         foobar.register(sharedSchemaRepository);
         foobar.setResult();
 
-        final SchemaContextFactory fact = sharedSchemaRepository
-                .createSchemaContextFactory(SchemaSourceFilter.ALWAYS_ACCEPT);
-
-        final CheckedFuture<SchemaContext, SchemaResolutionException> testSchemaContextFuture = fact
-                .createSchemaContext(Lists.newArrayList(foobar.getId()));
+        final SchemaContextFactory fact = sharedSchemaRepository.createSchemaContextFactory();
+        final ListenableFuture<SchemaContext> testSchemaContextFuture =
+                fact.createSchemaContext(ImmutableList.of(foobar.getId()));
         assertTrue(testSchemaContextFuture.isDone());
-        assertSchemaContext(testSchemaContextFuture.checkedGet(), 1);
+        assertSchemaContext(testSchemaContextFuture.get(), 1);
 
-        final Module module = testSchemaContextFuture.checkedGet().findModuleByName("foobar", null);
+        final Module module = testSchemaContextFuture.get().findModules("foobar").iterator().next();
         assertNotNull(module);
         assertEquals(3, module.getChildNodes().size());
 
@@ -125,20 +120,18 @@ public class SharedSchemaRepositoryWithFeaturesTest {
         final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository(
                 "shared-schema-repo-with-features-test");
 
-        final SettableSchemaProvider<ASTSchemaSource> foobar = getImmediateYangSourceProviderFromResource
-                ("/if-feature-resolution-test/shared-schema-repository/foobar.yang");
+        final SettableSchemaProvider<ASTSchemaSource> foobar = getImmediateYangSourceProviderFromResource(
+            "/if-feature-resolution-test/shared-schema-repository/foobar.yang");
         foobar.register(sharedSchemaRepository);
         foobar.setResult();
 
-        final SchemaContextFactory fact = sharedSchemaRepository
-                .createSchemaContextFactory(SchemaSourceFilter.ALWAYS_ACCEPT);
-
-        final CheckedFuture<SchemaContext, SchemaResolutionException> testSchemaContextFuture = fact
-                .createSchemaContext(Lists.newArrayList(foobar.getId()), supportedFeatures);
+        final SchemaContextFactory fact = sharedSchemaRepository.createSchemaContextFactory();
+        final ListenableFuture<SchemaContext> testSchemaContextFuture =
+                fact.createSchemaContext(ImmutableList.of(foobar.getId()), supportedFeatures);
         assertTrue(testSchemaContextFuture.isDone());
-        assertSchemaContext(testSchemaContextFuture.checkedGet(), 1);
+        assertSchemaContext(testSchemaContextFuture.get(), 1);
 
-        final Module module = testSchemaContextFuture.checkedGet().findModuleByName("foobar", null);
+        final Module module = testSchemaContextFuture.get().findModules("foobar").iterator().next();
         assertNotNull(module);
         assertEquals(1, module.getChildNodes().size());
 
@@ -152,7 +145,7 @@ public class SharedSchemaRepositoryWithFeaturesTest {
 
     private static SettableSchemaProvider<ASTSchemaSource> getImmediateYangSourceProviderFromResource(
             final String resourceName) throws Exception {
-        final ResourceYangSource yangSource = new ResourceYangSource(resourceName);
+        final YangTextSchemaSource yangSource = YangTextSchemaSource.forResource(resourceName);
         return SettableSchemaProvider.createImmediate(TextToASTTransformer.transformText(yangSource),
             ASTSchemaSource.class);
     }