Migrate getDataChildByName() users
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / parser / repo / SharedSchemaRepositoryWithFeaturesTest.java
index 42c0b83360284720efa5236ec023309c140dfdf1..41473ea2130ad913e6ce2132e4761060e99350a7 100644 (file)
@@ -5,7 +5,6 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.yangtools.yang.parser.repo;
 
 import static org.junit.Assert.assertEquals;
@@ -14,45 +13,43 @@ import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
 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;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 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.SchemaSourceException;
-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.EffectiveModelContextFactory;
+import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactoryConfiguration;
+import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource;
+import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer;
 
 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<IRSchemaSource> 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 ListenableFuture<EffectiveModelContext> testSchemaContextFuture =
+                sharedSchemaRepository.createEffectiveModelContextFactory(
+                SchemaContextFactoryConfiguration.builder().setSupportedFeatures(supportedFeatures).build())
+                .createEffectiveModelContext(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(2, module.getChildNodes().size());
 
@@ -63,7 +60,7 @@ public class SharedSchemaRepositoryWithFeaturesTest {
                 QName.create(module.getQNameModule(), "test-leaf-a"));
         assertNotNull(testLeafA);
 
-        final ContainerSchemaNode testContainerB = (ContainerSchemaNode) module.getDataChildByName(
+        final ContainerSchemaNode testContainerB = (ContainerSchemaNode) module.dataChildByName(
                 QName.create(module.getQNameModule(), "test-container-b"));
         assertNull(testContainerB);
 
@@ -80,20 +77,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<IRSchemaSource> 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 EffectiveModelContextFactory fact = sharedSchemaRepository.createEffectiveModelContextFactory();
+        final ListenableFuture<EffectiveModelContext> testSchemaContextFuture =
+                fact.createEffectiveModelContext(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());
 
@@ -121,25 +116,22 @@ public class SharedSchemaRepositoryWithFeaturesTest {
 
     @Test
     public void testSharedSchemaRepositoryWithNoFeaturesSupported() throws Exception {
-        final Set<QName> supportedFeatures = ImmutableSet.of();
-
         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<IRSchemaSource> 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 ListenableFuture<EffectiveModelContext> testSchemaContextFuture =
+                sharedSchemaRepository.createEffectiveModelContextFactory(
+                    SchemaContextFactoryConfiguration.builder().setSupportedFeatures(ImmutableSet.of()).build())
+                .createEffectiveModelContext(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(1, module.getChildNodes().size());
 
@@ -151,11 +143,11 @@ public class SharedSchemaRepositoryWithFeaturesTest {
         assertNotNull(testLeafC);
     }
 
-    private static SettableSchemaProvider<ASTSchemaSource> getImmediateYangSourceProviderFromResource(
+    private static SettableSchemaProvider<IRSchemaSource> 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);
+        final YangTextSchemaSource yangSource = YangTextSchemaSource.forResource(resourceName);
+        return SettableSchemaProvider.createImmediate(TextToIRTransformer.transformText(yangSource),
+            IRSchemaSource.class);
     }
 
     private static void assertSchemaContext(final SchemaContext schemaContext, final int moduleSize) {