Bug 6869: [Yang 1.1] Allow if-feature in bit, enum, refine & identity
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / StmtTestUtils.java
index e6336f273b31e682bd4119f82315136a95944a53..a3435cabc5203c3d1b1cbf55dd8906ac4dbae51b 100644 (file)
@@ -17,11 +17,14 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 import java.util.Set;
+import java.util.function.Predicate;
+import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.repo.api.IfFeaturePredicates;
 import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
@@ -98,13 +101,13 @@ public class StmtTestUtils {
 
     public static SchemaContext parseYangSources(final StatementStreamSource... sources) throws SourceException,
             ReactorException {
-        return parseYangSources(StatementParserMode.DEFAULT_MODE, sources);
+        return parseYangSources(StatementParserMode.DEFAULT_MODE, IfFeaturePredicates.ALL_FEATURES, sources);
     }
 
-    public static SchemaContext parseYangSources(final StatementParserMode statementParserMode, final StatementStreamSource... sources)
+    public static SchemaContext parseYangSources(final StatementParserMode statementParserMode, final Predicate<QName> ifFeaturePredicate, final StatementStreamSource... sources)
             throws SourceException, ReactorException {
 
-        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(statementParserMode);
+        final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(statementParserMode, ifFeaturePredicate);
         reactor.addSources(sources);
 
         return reactor.buildEffective();
@@ -112,10 +115,10 @@ public class StmtTestUtils {
 
     public static SchemaContext parseYangSources(final File... files) throws SourceException, ReactorException,
             FileNotFoundException {
-        return parseYangSources(StatementParserMode.DEFAULT_MODE, files);
+        return parseYangSources(StatementParserMode.DEFAULT_MODE, IfFeaturePredicates.ALL_FEATURES, files);
     }
 
-    public static SchemaContext parseYangSources(final StatementParserMode statementParserMode, final File... files) throws SourceException,
+    public static SchemaContext parseYangSources(final StatementParserMode statementParserMode, final Predicate<QName> ifFeaturePredicate, final File... files) throws SourceException,
             ReactorException, FileNotFoundException {
 
         final StatementStreamSource[] sources = new StatementStreamSource[files.length];
@@ -124,7 +127,7 @@ public class StmtTestUtils {
             sources[i] = new YangStatementSourceImpl(new NamedFileInputStream(files[i], files[i].getPath()));
         }
 
-        return parseYangSources(statementParserMode, sources);
+        return parseYangSources(statementParserMode, ifFeaturePredicate, sources);
     }
 
     public static SchemaContext parseYangSources(final Collection<File> files) throws SourceException, ReactorException,
@@ -134,7 +137,7 @@ public class StmtTestUtils {
 
     public static SchemaContext parseYangSources(final Collection<File> files, final StatementParserMode statementParserMode)
             throws SourceException, ReactorException, FileNotFoundException {
-        return parseYangSources(statementParserMode, files.toArray(new File[files.size()]));
+        return parseYangSources(statementParserMode, IfFeaturePredicates.ALL_FEATURES, files.toArray(new File[files.size()]));
     }
 
     public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath) throws SourceException,
@@ -144,14 +147,20 @@ public class StmtTestUtils {
 
     public static SchemaContext parseYangSource(final String yangSourcePath) throws SourceException, ReactorException,
             FileNotFoundException, URISyntaxException {
-        return parseYangSource(yangSourcePath, StatementParserMode.DEFAULT_MODE);
+        return parseYangSource(yangSourcePath, StatementParserMode.DEFAULT_MODE, IfFeaturePredicates.ALL_FEATURES);
+    }
+
+    public static SchemaContext parseYangSource(final String yangSourcePath, final Predicate<QName> ifFeaturesPredicate)
+            throws SourceException, FileNotFoundException, ReactorException, URISyntaxException {
+        return parseYangSource(yangSourcePath, StatementParserMode.DEFAULT_MODE, ifFeaturesPredicate);
     }
 
-    public static SchemaContext parseYangSource(final String yangSourcePath, final StatementParserMode statementParserMode)
+    public static SchemaContext parseYangSource(final String yangSourcePath,
+            final StatementParserMode statementParserMode, final Predicate<QName> ifFeaturePredicate)
             throws SourceException, ReactorException, FileNotFoundException, URISyntaxException {
         final URL source = StmtTestUtils.class.getResource(yangSourcePath);
         final File sourceFile = new File(source.toURI());
-        return parseYangSources(statementParserMode, sourceFile);
+        return parseYangSources(statementParserMode, ifFeaturePredicate, sourceFile);
     }
 
     public static SchemaContext parseYangSources(final String yangSourcesDirectoryPath, final StatementParserMode statementParserMode)
@@ -160,7 +169,7 @@ public class StmtTestUtils {
         final URL resourceDir = StmtTestUtils.class.getResource(yangSourcesDirectoryPath);
         final File testSourcesDir = new File(resourceDir.toURI());
 
-        return parseYangSources(statementParserMode, testSourcesDir.listFiles(YANG_FILE_FILTER));
+        return parseYangSources(statementParserMode, IfFeaturePredicates.ALL_FEATURES, testSourcesDir.listFiles(YANG_FILE_FILTER));
     }
 
     public static SchemaContext parseYinSources(final String yinSourcesDirectoryPath, final StatementParserMode statementParserMode)