BUG-865: Migrate tests to non-deprecated API 80/26980/5
authorRobert Varga <rovarga@cisco.com>
Mon, 14 Sep 2015 21:23:50 +0000 (23:23 +0200)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 18 Sep 2015 08:42:17 +0000 (08:42 +0000)
Prepare for the deprecated methods being removed

Change-Id: I0cbf84b4bda3535e70cd8dbe24e1708d6127e5de
Signed-off-by: Robert Varga <rovarga@cisco.com>
13 files changed:
code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/ModuleInfoBackedContext.java
code-generator/binding-type-provider/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/BaseYangTypesTest.java
code-generator/binding-type-provider/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderModel.java
code-generator/binding-type-provider/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderTest.java
code-generator/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/unified/doc/generator/maven/DocGenTest.java
code-generator/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/unified/doc/generator/maven/YangModuleInfoCompilationTest.java
code-generator/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/wadl/generator/maven/WadlGenTest.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/NormalizedDataBuilderTest.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/dom/serializer/NormalizedNodeXmlTranslationTest.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/Bug2690FixTest.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/ListConstraintsValidationTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserWithContextTest.java

index b20a1700e12441f4f5ce4026b657c8c6c32b4ca9..04ae277387a991e09ba995bb3535e86c3782b908 100644 (file)
@@ -10,10 +10,11 @@ package org.opendaylight.yangtools.sal.binding.generator.impl;
 import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
+import com.google.common.io.ByteSource;
 import java.io.IOException;
 import java.io.InputStream;
 import java.lang.ref.WeakReference;
-import java.util.Set;
+import java.util.Collection;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import org.opendaylight.yangtools.concepts.AbstractObjectRegistration;
@@ -23,17 +24,16 @@ import org.opendaylight.yangtools.sal.binding.generator.api.ModuleInfoRegistry;
 import org.opendaylight.yangtools.util.ClassLoaderUtils;
 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
 import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
-import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider;
+import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class ModuleInfoBackedContext extends GeneratedClassLoadingStrategy //
-        implements //
-        ModuleInfoRegistry, SchemaContextProvider {
+public class ModuleInfoBackedContext extends GeneratedClassLoadingStrategy
+        implements ModuleInfoRegistry, SchemaContextProvider {
 
     private ModuleInfoBackedContext(final ClassLoadingStrategy loadingStrategy) {
         this.backingLoadingStrategy = loadingStrategy;
@@ -79,13 +79,12 @@ public class ModuleInfoBackedContext extends GeneratedClassLoadingStrategy //
 
     private synchronized Optional<SchemaContext> recreateSchemaContext() {
         try {
-            ImmutableList<InputStream> streams = getAvailableStreams();
+            Collection<ByteSource> streams = getAvailableStreams();
             YangParserImpl parser = new YangParserImpl();
-            Set<Module> modules = parser.parseYangModelsFromStreams(streams);
-            SchemaContext schemaContext = parser.resolveSchemaContext(modules);
+            SchemaContext schemaContext = parser.parseSources(streams);
             return Optional.of(schemaContext);
-        } catch (IOException e) {
-            LOG.error("Schema was not recreated.",e);
+        } catch (IOException | YangSyntaxErrorException e) {
+            LOG.error("Schema was not recreated.", e);
         }
         return Optional.absent();
     }
@@ -98,12 +97,19 @@ public class ModuleInfoBackedContext extends GeneratedClassLoadingStrategy //
         return recreateSchemaContext();
     }
 
-    private ImmutableList<InputStream> getAvailableStreams() throws IOException {
+    private Collection<ByteSource> getAvailableStreams() throws IOException {
         ImmutableSet<YangModuleInfo> moduleInfos = ImmutableSet.copyOf(sourceIdentifierToModuleInfo.values());
 
-        ImmutableList.Builder<InputStream> sourceStreams = ImmutableList.<InputStream> builder();
-        for (YangModuleInfo moduleInfo : moduleInfos) {
-            sourceStreams.add(moduleInfo.getModuleSourceStream());
+        ImmutableList.Builder<ByteSource> sourceStreams = ImmutableList.<ByteSource> builder();
+        for (final YangModuleInfo moduleInfo : moduleInfos) {
+            sourceStreams.add(new ByteSource() {
+
+                @Override
+                public InputStream openStream() throws IOException {
+                    return moduleInfo.getModuleSourceStream();
+                }
+            });
+            ;
         }
         return sourceStreams.build();
     }
index e7a425b5542e76c92a2cfa72be2b29661b9205de..fba48b2e9c3f29b86d671732272112b65b537d61 100644 (file)
@@ -10,7 +10,9 @@ package org.opendaylight.yangtools.sal.binding.yang.types;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
-import java.io.InputStream;
+import com.google.common.io.ByteSource;
+import com.google.common.io.Resources;
+import java.io.IOException;
 import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.util.Collections;
@@ -21,7 +23,6 @@ import org.junit.Test;
 import org.opendaylight.yangtools.binding.generator.util.BindingGeneratorUtil;
 import org.opendaylight.yangtools.sal.binding.generator.spi.TypeProvider;
 import org.opendaylight.yangtools.sal.binding.model.api.Type;
-import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
@@ -34,6 +35,7 @@ import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition;
 import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser;
+import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
 import org.opendaylight.yangtools.yang.model.util.ExtendedType;
 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
 
@@ -62,15 +64,12 @@ public class BaseYangTypesTest {
     private static EmptyTypeDefinition empty = null;
     private static BooleanTypeDefinition bool = null;
 
-    @SuppressWarnings("deprecation")
     @BeforeClass
-    public static void setup() {
-        final List<InputStream> modelsToParse = Collections
-            .singletonList(BaseYangTypesTest.class.getResourceAsStream("/base-yang-types.yang"));
+    public static void setup() throws IOException, YangSyntaxErrorException {
+        final List<ByteSource> modelsToParse = Collections
+            .singletonList(Resources.asByteSource(BaseYangTypesTest.class.getResource("/base-yang-types.yang")));
         final YangContextParser parser = new YangParserImpl();
-        final Set<Module> modules = parser.parseYangModelsFromStreams(modelsToParse);
-        assertTrue(!modules.isEmpty());
-        schemaContext = parser.resolveSchemaContext(modules);
+        schemaContext = parser.parseSources(modelsToParse);
         assertNotNull(schemaContext);
         initTypeDefinitionsFromSchemaContext();
     }
index a6d124ca23c53b210a66770512fa074966204a28..d3daa2e5afba60c415b5aab5832a230c4c05fc42 100644 (file)
@@ -7,12 +7,13 @@
  */
 package org.opendaylight.yangtools.sal.binding.yang.types;
 
-import java.io.InputStream;
+import com.google.common.io.ByteSource;
+import com.google.common.io.Resources;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Set;
-import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
 
 /**
@@ -29,22 +30,20 @@ final class TypeProviderModel {
     private static final String TEST_TYPE_PROVIDER_PATH = "/"+TEST_TYPE_PROVIDER_MODULE_NAME+".yang";
     private static final String TEST_TYPE_PROVIDER_B_PATH = "/test-type-provider-b.yang";
 
-    private static InputStream getInputStream(final String resourceName) {
-        return TypeProviderModel.class.getResourceAsStream(resourceName);
+    private static ByteSource getByteSource(final String resourceName) {
+        return Resources.asByteSource(TypeProviderModel.class.getResource(resourceName));
     }
 
-    private static List<InputStream> provideTestModelStreams() {
-        final List<InputStream> arrayList = new ArrayList<>();
+    private static List<ByteSource> provideTestModelStreams() {
+        final List<ByteSource> arrayList = new ArrayList<>();
 
-        arrayList.add(getInputStream(BASE_YANG_TYPES_PATH));
-        arrayList.add(getInputStream(TEST_TYPE_PROVIDER_PATH));
-        arrayList.add(getInputStream(TEST_TYPE_PROVIDER_B_PATH));
+        arrayList.add(getByteSource(BASE_YANG_TYPES_PATH));
+        arrayList.add(getByteSource(TEST_TYPE_PROVIDER_PATH));
+        arrayList.add(getByteSource(TEST_TYPE_PROVIDER_B_PATH));
         return arrayList;
     }
 
-    public static SchemaContext createTestContext() {
-        YangParserImpl parser = new YangParserImpl();
-        Set<Module> modules = parser.parseYangModelsFromStreams(provideTestModelStreams());
-        return parser.resolveSchemaContext(modules);
+    public static SchemaContext createTestContext() throws IOException, YangSyntaxErrorException {
+        return new YangParserImpl().parseSources(provideTestModelStreams());
     }
 }
index ee40141b0891565a7c844e0d5a95d8b474572210..727644b41770f026b1c886a5b555027c082ae7bd 100644 (file)
@@ -10,7 +10,7 @@ package org.opendaylight.yangtools.sal.binding.yang.types;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
-
+import java.io.IOException;
 import java.math.BigInteger;
 import java.util.List;
 import java.util.Set;
@@ -25,19 +25,33 @@ import org.opendaylight.yangtools.binding.generator.util.BindingGeneratorUtil;
 import org.opendaylight.yangtools.binding.generator.util.ReferencedTypeImpl;
 import org.opendaylight.yangtools.binding.generator.util.generated.type.builder.GeneratedTOBuilderImpl;
 import org.opendaylight.yangtools.sal.binding.generator.spi.TypeProvider;
-import org.opendaylight.yangtools.sal.binding.model.api.*;
+import org.opendaylight.yangtools.sal.binding.model.api.ConcreteType;
+import org.opendaylight.yangtools.sal.binding.model.api.Enumeration;
+import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject;
+import org.opendaylight.yangtools.sal.binding.model.api.ParameterizedType;
+import org.opendaylight.yangtools.sal.binding.model.api.Restrictions;
+import org.opendaylight.yangtools.sal.binding.model.api.Type;
 import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedTOBuilder;
-import org.opendaylight.yangtools.yang.model.api.*;
+import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
+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.api.SchemaNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
 import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
+import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
 
 /**
  * Test suite for testing public methods in TypeProviderImpl class
  *
  * @see org.opendaylight.yangtools.sal.binding.yang.types.TypeProviderImpl
  *
- * @author Lukas Sedlak <lsedlak@cisco.com>
+ * @author Lukas Sedlak &lt;lsedlak@cisco.com&gt;
  */
 @RunWith(JUnit4.class)
 public class TypeProviderTest {
@@ -53,7 +67,7 @@ public class TypeProviderTest {
     private SchemaNode schemaNode;
 
     @Before
-    public void setUp() {
+    public void setUp() throws IOException, YangSyntaxErrorException {
         MockitoAnnotations.initMocks(this);
         schemaContext = TypeProviderModel.createTestContext();
         assertNotNull(schemaContext);
@@ -303,7 +317,7 @@ public class TypeProviderTest {
         assertTrue(leafrefResolvedType2 instanceof ParameterizedType);
     }
 
-    private void setReferencedTypeForTypeProvider(TypeProvider provider) {
+    private void setReferencedTypeForTypeProvider(final TypeProvider provider) {
         final LeafSchemaNode enumLeafNode = provideLeafNodeFromTopLevelContainer(testTypeProviderModule, "foo",
             "resolve-direct-use-of-enum");
         final TypeDefinition<?> enumLeafTypedef = enumLeafNode.getType();
index 4e0e2541104256c6ab91f2cde0177bad9b310b11..1e9ae3586ee59aab7f510c26bf30decb1e3c435e 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.yangtools.yang.unified.doc.generator.maven;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
-
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.net.URI;
@@ -17,12 +16,9 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
-import java.util.Set;
-
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
-import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
 import org.opendaylight.yangtools.yang2sources.spi.BasicCodeGenerator;
@@ -52,14 +48,13 @@ public class DocGenTest {
     @Test
     public void testListGeneration() throws Exception {
         final List<File> sourceFiles = getSourceFiles("/doc-gen");
-        final Set<Module> modulesToBuild = parser.parseYangModels(sourceFiles);
-        final SchemaContext context = parser.resolveSchemaContext(modulesToBuild);
+        final SchemaContext context = parser.parseFiles(sourceFiles);
         final BasicCodeGenerator generator = new DocumentationGeneratorImpl();
-        Collection<File> generatedFiles = generator.generateSources(context, GENERATOR_OUTPUT_DIR, modulesToBuild);
+        Collection<File> generatedFiles = generator.generateSources(context, GENERATOR_OUTPUT_DIR, context.getModules());
         assertEquals(4, generatedFiles.size());
     }
 
-    private static List<File> getSourceFiles(String path) throws Exception {
+    private static List<File> getSourceFiles(final String path) throws Exception {
         final URI resPath = DocGenTest.class.getResource(path).toURI();
         final File sourcesDir = new File(resPath);
         if (sourcesDir.exists()) {
@@ -75,7 +70,7 @@ public class DocGenTest {
         }
     }
 
-    private static void deleteTestDir(File file) {
+    private static void deleteTestDir(final File file) {
         if (file.isDirectory()) {
             File[] filesToDelete = file.listFiles();
             if (filesToDelete != null) {
index 1a1052baa14838f604e6d1d6a068d785911ea126..ec026beec38be2fafc199ba76a9692eb69a37a68 100644 (file)
@@ -11,7 +11,6 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
-
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.lang.reflect.Method;
@@ -132,7 +131,7 @@ public class YangModuleInfoCompilationTest {
         cleanUp(sourcesOutputDir, compiledOutputDir);
     }
 
-    private void generateTestSources(String resourceDirPath, File sourcesOutputDir) throws Exception {
+    private static void generateTestSources(final String resourceDirPath, final File sourcesOutputDir) throws Exception {
         final List<File> sourceFiles = getSourceFiles(resourceDirPath);
         YangContextParser parser = new YangParserImpl();
         final SchemaContext context = parser.parseFiles(sourceFiles);
@@ -141,7 +140,7 @@ public class YangModuleInfoCompilationTest {
         codegen.generateSources(context, sourcesOutputDir, context.getModules());
     }
 
-    private static void testCompilation(File sourcesOutputDir, File compiledOutputDir) {
+    private static void testCompilation(final File sourcesOutputDir, final File compiledOutputDir) {
         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
         StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
         List<File> filesList = getJavaFiles(sourcesOutputDir);
@@ -151,7 +150,7 @@ public class YangModuleInfoCompilationTest {
         assertTrue(compiled);
     }
 
-    private static List<File> getJavaFiles(File directory) {
+    private static List<File> getJavaFiles(final File directory) {
         List<File> result = new ArrayList<>();
         File[] filesToRead = directory.listFiles();
         if (filesToRead != null) {
@@ -169,7 +168,7 @@ public class YangModuleInfoCompilationTest {
         return result;
     }
 
-    private static List<File> getSourceFiles(String path) throws Exception {
+    private static List<File> getSourceFiles(final String path) throws Exception {
         final URI resPath = YangModuleInfoCompilationTest.class.getResource(path).toURI();
         final File sourcesDir = new File(resPath);
         final URI currentDir = new File(System.getProperty("user.dir")).toURI();
@@ -188,7 +187,7 @@ public class YangModuleInfoCompilationTest {
         }
     }
 
-    private static void deleteTestDir(File file) {
+    private static void deleteTestDir(final File file) {
         if (file.isDirectory()) {
             File[] filesToDelete = file.listFiles();
             if (filesToDelete != null) {
@@ -202,7 +201,7 @@ public class YangModuleInfoCompilationTest {
         }
     }
 
-    private static Method assertContainsMethod(Class<?> clazz, Class<?> returnType, String name, Class<?>... args) {
+    private static Method assertContainsMethod(final Class<?> clazz, final Class<?> returnType, final String name, final Class<?>... args) {
         try {
             Method m = clazz.getDeclaredMethod(name, args);
             assertEquals(returnType, m.getReturnType());
@@ -213,7 +212,7 @@ public class YangModuleInfoCompilationTest {
         }
     }
 
-    private static void cleanUp(File... resourceDirs) {
+    private static void cleanUp(final File... resourceDirs) {
         for (File resourceDir : resourceDirs) {
             if (resourceDir.exists()) {
                 deleteTestDir(resourceDir);
index 4485b429a67a2b0eb1a1d387cd0f4e79e6912ecb..5c8eb4ea7b3fd750b99d9829f686ffeaa3ee2448 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.yangtools.yang.wadl.generator.maven;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
-
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.net.URI;
@@ -17,12 +16,9 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
-import java.util.Set;
-
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
-import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
 import org.opendaylight.yangtools.yang2sources.spi.BasicCodeGenerator;
@@ -52,14 +48,13 @@ public class WadlGenTest {
     @Test
     public void testListGeneration() throws Exception {
         final List<File> sourceFiles = getSourceFiles("/wadl-gen");
-        final Set<Module> modulesToBuild = parser.parseYangModels(sourceFiles);
-        final SchemaContext context = parser.resolveSchemaContext(modulesToBuild);
+        final SchemaContext context = parser.parseFiles(sourceFiles);
         final BasicCodeGenerator generator = new WadlGenerator();
-        Collection<File> generatedWadlFiles = generator.generateSources(context, GENERATOR_OUTPUT_DIR, modulesToBuild);
+        Collection<File> generatedWadlFiles = generator.generateSources(context, GENERATOR_OUTPUT_DIR, context.getModules());
         assertEquals(3, generatedWadlFiles.size());
     }
 
-    private static List<File> getSourceFiles(String path) throws Exception {
+    private static List<File> getSourceFiles(final String path) throws Exception {
         final URI resPath = WadlGenTest.class.getResource(path).toURI();
         final File sourcesDir = new File(resPath);
         if (sourcesDir.exists()) {
@@ -75,7 +70,7 @@ public class WadlGenTest {
         }
     }
 
-    private static void deleteTestDir(File file) {
+    private static void deleteTestDir(final File file) {
         if (file.isDirectory()) {
             File[] filesToDelete = file.listFiles();
             if (filesToDelete != null) {
index 71440c23a9c7cc774fba8140a9b60315204c89ec..38cdb287e40528bb23b6dccfeac9a3d22229a7ff 100644 (file)
@@ -12,11 +12,12 @@ import com.google.common.base.Preconditions;
 import com.google.common.collect.Collections2;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
-import java.io.InputStream;
+import com.google.common.io.ByteSource;
+import com.google.common.io.Resources;
+import java.io.IOException;
 import java.net.URI;
 import java.util.Collections;
 import java.util.List;
-import java.util.Set;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -41,6 +42,7 @@ import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
 
 public class NormalizedDataBuilderTest {
@@ -48,19 +50,18 @@ public class NormalizedDataBuilderTest {
     private ContainerSchemaNode containerNode;
     private SchemaContext schema;
 
-    SchemaContext parseTestSchema(final String... yangPath) {
+    SchemaContext parseTestSchema(final String... yangPath) throws IOException, YangSyntaxErrorException {
         YangParserImpl yangParserImpl = new YangParserImpl();
-        Set<Module> modules = yangParserImpl.parseYangModelsFromStreams(getTestYangs(yangPath));
-        return yangParserImpl.resolveSchemaContext(modules);
+        return yangParserImpl.parseSources(getTestYangs(yangPath));
     }
 
-    List<InputStream> getTestYangs(final String... yangPaths) {
+    List<ByteSource> getTestYangs(final String... yangPaths) {
 
         return Lists.newArrayList(Collections2.transform(Lists.newArrayList(yangPaths),
-                new Function<String, InputStream>() {
+                new Function<String, ByteSource>() {
             @Override
-            public InputStream apply(final String input) {
-                InputStream resourceAsStream = getClass().getResourceAsStream(input);
+            public ByteSource apply(final String input) {
+                ByteSource resourceAsStream = Resources.asByteSource(getClass().getResource(input));
                 Preconditions.checkNotNull(resourceAsStream, "File %s was null", resourceAsStream);
                 return resourceAsStream;
             }
index 830e7a2ebd14cd1450c18bbdf615a9581b7f8bbc..3d95e76f4a06f251f342eb0edd2e4f4f96cf58bd 100644 (file)
@@ -17,6 +17,8 @@ import com.google.common.collect.Collections2;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
+import com.google.common.io.ByteSource;
+import com.google.common.io.Resources;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.StringWriter;
@@ -70,9 +72,9 @@ import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNo
 import org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.DomUtils;
 import org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.parser.DomToNormalizedNodeParserFactory;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -243,7 +245,7 @@ public class NormalizedNodeXmlTranslationTest {
         return new YangInstanceIdentifier.AugmentationIdentifier(qn);
     }
 
-    public NormalizedNodeXmlTranslationTest(final String yangPath, final String xmlPath, final ContainerNode expectedNode) {
+    public NormalizedNodeXmlTranslationTest(final String yangPath, final String xmlPath, final ContainerNode expectedNode) throws IOException, YangSyntaxErrorException {
         schema = parseTestSchema(yangPath);
         this.xmlPath = xmlPath;
         this.containerNode = (ContainerSchemaNode) NormalizedDataBuilderTest.getSchemaNode(schema, "test", "container");
@@ -255,21 +257,21 @@ public class NormalizedNodeXmlTranslationTest {
     private final String xmlPath;
 
 
-    SchemaContext parseTestSchema(final String... yangPath) {
+    SchemaContext parseTestSchema(final String... yangPath) throws IOException, YangSyntaxErrorException {
         final YangParserImpl yangParserImpl = new YangParserImpl();
-        final Set<Module> modules = yangParserImpl.parseYangModelsFromStreams(getTestYangs(yangPath));
-        return yangParserImpl.resolveSchemaContext(modules);
+        return yangParserImpl.parseSources(getTestYangs(yangPath));
     }
 
-    List<InputStream> getTestYangs(final String... yangPaths) {
+    List<ByteSource> getTestYangs(final String... yangPaths) {
 
         return Lists.newArrayList(Collections2.transform(Lists.newArrayList(yangPaths),
-                new Function<String, InputStream>() {
+                new Function<String, ByteSource>() {
             @Override
-            public InputStream apply(final String input) {
-                final InputStream resourceAsStream = NormalizedDataBuilderTest.class.getResourceAsStream(input);
-                Preconditions.checkNotNull(resourceAsStream, "File %s was null", resourceAsStream);
-                return resourceAsStream;
+            public ByteSource apply(final String input) {
+                final ByteSource source = Resources.asByteSource(
+                    NormalizedDataBuilderTest.class.getResource(input));
+                Preconditions.checkNotNull(source, "File %s was null", source);
+                return source;
             }
         }));
     }
index 11756e40d0ab1c7e46cf8de41fcd55f7574ba14c..825605b498972dd45a4a1ab0813703761bdb024e 100644 (file)
@@ -11,9 +11,10 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import com.google.common.base.Optional;
-import java.io.InputStream;
+import com.google.common.io.ByteSource;
+import com.google.common.io.Resources;
+import java.io.IOException;
 import java.util.Collections;
-import java.util.Set;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -27,8 +28,8 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailed
 import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
-import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
 
 public class Bug2690FixTest {
@@ -39,7 +40,7 @@ public class Bug2690FixTest {
     private InMemoryDataTree inMemoryDataTree;
 
     @Before
-    public void prepare() {
+    public void prepare() throws IOException, YangSyntaxErrorException {
         schemaContext = createTestContext();
         assertNotNull("Schema context must not be null.", schemaContext);
         rootOper = RootModificationApplyOperation.from(SchemaAwareApplyOperation.from(schemaContext, TreeType.OPERATIONAL));
@@ -47,18 +48,13 @@ public class Bug2690FixTest {
         inMemoryDataTree.setSchemaContext(schemaContext);
     }
 
-    public static final InputStream getDatastoreTestInputStream() {
-        return getInputStream(ODL_DATASTORE_TEST_YANG);
+    private static ByteSource getInputStream() {
+        return Resources.asByteSource(TestModel.class.getResource(ODL_DATASTORE_TEST_YANG));
     }
 
-    private static InputStream getInputStream(final String resourceName) {
-        return TestModel.class.getResourceAsStream(ODL_DATASTORE_TEST_YANG);
-    }
-
-    public static SchemaContext createTestContext() {
+    public static SchemaContext createTestContext() throws IOException, YangSyntaxErrorException {
         final YangParserImpl parser = new YangParserImpl();
-        final Set<Module> modules = parser.parseYangModelsFromStreams(Collections.singletonList(getDatastoreTestInputStream()));
-        return parser.resolveSchemaContext(modules);
+        return parser.parseSources(Collections.singletonList(getInputStream()));
     }
 
     @Test
index 6494bc36c5ac53650b539fd4222eab94e772c0b6..cd8574768f2ff768565b98c08b9106cce1d051b7 100644 (file)
@@ -10,11 +10,12 @@ package org.opendaylight.yangtools.yang.data.impl.schema.tree;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import com.google.common.base.Optional;
-import java.io.InputStream;
+import com.google.common.io.ByteSource;
+import com.google.common.io.Resources;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
-import java.util.Set;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -36,8 +37,8 @@ import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLe
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUnkeyedListEntryNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUnkeyedListNodeBuilder;
-import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -75,7 +76,7 @@ public class ListConstraintsValidationTest {
             .node(UNKEYED_LIST_QNAME).build();
 
     @Before
-    public void prepare() {
+    public void prepare() throws IOException, YangSyntaxErrorException {
         schemaContext = createTestContext();
         assertNotNull("Schema context must not be null.", schemaContext);
         rootOper = RootModificationApplyOperation.from(SchemaAwareApplyOperation.from(schemaContext, TreeType.OPERATIONAL));
@@ -91,18 +92,13 @@ public class ListConstraintsValidationTest {
 
     }
 
-    public static final InputStream getDatastoreTestInputStream() {
-        return getInputStream(CONSTRAINTS_VALIDATION_TEST_YANG);
+    private static ByteSource getInputStream() {
+        return Resources.asByteSource(TestModel.class.getResource(CONSTRAINTS_VALIDATION_TEST_YANG));
     }
 
-    private static InputStream getInputStream(final String resourceName) {
-        return TestModel.class.getResourceAsStream(CONSTRAINTS_VALIDATION_TEST_YANG);
-    }
-
-    public static SchemaContext createTestContext() {
+    public static SchemaContext createTestContext() throws IOException, YangSyntaxErrorException {
         final YangParserImpl parser = new YangParserImpl();
-        final Set<Module> modules = parser.parseYangModelsFromStreams(Collections.singletonList(getDatastoreTestInputStream()));
-        return parser.resolveSchemaContext(modules);
+        return parser.parseSources(Collections.singletonList(getInputStream()));
     }
 
     @Test
index 31bf09927da46b11aff8ef53e95920110482b751..6a9c42397bf2bdb55d136a6c0700b4a4c9495e77 100644 (file)
@@ -29,9 +29,7 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
 import java.util.Iterator;
-import java.util.LinkedHashSet;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
 import org.junit.Before;
 import org.junit.Test;
@@ -866,22 +864,6 @@ public class YangParserTest {
         assertSetEquals(newModules, modules);
         ctx = new SchemaContextImpl(newModules, Collections.<ModuleIdentifier, String> emptyMap());
         assertSetEquals(newModules, ctx.getModules());
-        // ##########
-        Map<File, Module> mapped = parser.parseYangModelsMapped(testFiles);
-        newModules = new LinkedHashSet<>(mapped.values());
-        assertSetEquals(newModules, modules);
-        ctx = new SchemaContextImpl(newModules, Collections.<ModuleIdentifier, String> emptyMap());
-        assertSetEquals(newModules, ctx.getModules());
-        // ##########
-        streams.clear();
-        for (File f : testFiles) {
-            streams.add(new FileInputStream(f));
-        }
-        Map<InputStream, Module> mappedStreams = parser.parseYangModelsFromStreamsMapped(streams);
-        newModules = new LinkedHashSet<>(mappedStreams.values());
-        assertSetEquals(newModules, modules);
-        ctx = new SchemaContextImpl(newModules, Collections.<ModuleIdentifier, String> emptyMap());
-        assertSetEquals(newModules, ctx.getModules());
     }
 
     private static void checkOrder(final Collection<Module> modules) {
index cf5ab060bf31d3cc37655876c0e8a3ab5a55ecc2..2cc44843738d78867fd9f25cc79f530f0522e37d 100644 (file)
@@ -12,8 +12,11 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import com.google.common.collect.Lists;
+import com.google.common.io.ByteSource;
+import com.google.common.io.Resources;
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.IOException;
 import java.io.InputStream;
 import java.math.BigInteger;
 import java.net.URI;
@@ -47,21 +50,27 @@ import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.UsesNode;
 import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
 import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser;
+import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
 import org.opendaylight.yangtools.yang.model.util.ExtendedType;
 
 public class YangParserWithContextTest {
     private final DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
     private final YangParserImpl parser = new YangParserImpl();
 
+    private final SchemaContext createContext(final String... resources) throws IOException, YangSyntaxErrorException {
+        final List<ByteSource> srcs = new ArrayList<>(resources.length);
+        for (String resource : resources) {
+            srcs.add(Resources.asByteSource(getClass().getResource(resource)));
+        }
+
+        return parser.parseSources(srcs);
+    }
+
     @Test
     public void testTypeFromContext() throws Exception {
-        String resource = "/ietf/ietf-inet-types@2010-09-24.yang";
-        InputStream stream = new FileInputStream(new File(getClass().getResource(resource).toURI()));
-        SchemaContext context = parser.resolveSchemaContext(TestUtils.loadModules(Lists.newArrayList(stream)));
-        stream.close();
+        SchemaContext context = createContext("/ietf/ietf-inet-types@2010-09-24.yang");
 
-        resource = "/context-test/test1.yang";
-        InputStream stream2 = new FileInputStream(new File(getClass().getResource(resource).toURI()));
+        InputStream stream2 = new FileInputStream(new File(getClass().getResource("/context-test/test1.yang").toURI()));
         Module module = TestUtils.loadModuleWithContext("test1", stream2, context);
         stream2.close();
         assertNotNull(module);
@@ -90,15 +99,7 @@ public class YangParserWithContextTest {
 
     @Test
     public void testUsesFromContext() throws Exception {
-        SchemaContext context;
-        try (InputStream stream1 = new FileInputStream(new File(getClass().getResource("/model/baz.yang").toURI()));
-                InputStream stream2 = new FileInputStream(new File(getClass().getResource("/model/bar.yang").toURI()));
-                InputStream stream3 = new FileInputStream(new File(getClass().getResource("/model/foo.yang").toURI()));
-                InputStream stream4 = new FileInputStream(
-                        new File(getClass().getResource("/model/subfoo.yang").toURI()))) {
-            context = parser.resolveSchemaContext(TestUtils.loadModules(Lists.newArrayList(stream1, stream2, stream3,
-                    stream4)));
-        }
+        SchemaContext context = createContext("/model/baz.yang", "/model/bar.yang", "/model/foo.yang", "/model/subfoo.yang");
         Module testModule;
         try (InputStream stream = new FileInputStream(new File(getClass().getResource("/context-test/test2.yang")
                 .toURI()))) {
@@ -197,15 +198,8 @@ public class YangParserWithContextTest {
 
     @Test
     public void testUsesRefineFromContext() throws Exception {
-        SchemaContext context;
-        try (InputStream stream1 = new FileInputStream(new File(getClass().getResource("/model/baz.yang").toURI()));
-                InputStream stream2 = new FileInputStream(new File(getClass().getResource("/model/bar.yang").toURI()));
-                InputStream stream3 = new FileInputStream(new File(getClass().getResource("/model/foo.yang").toURI()));
-                InputStream stream4 = new FileInputStream(
-                        new File(getClass().getResource("/model/subfoo.yang").toURI()))) {
-            context = parser.resolveSchemaContext(TestUtils.loadModules(Lists.newArrayList(stream1, stream2, stream3,
-                    stream4)));
-        }
+        SchemaContext context = createContext("/model/baz.yang", "/model/bar.yang", "/model/foo.yang", "/model/subfoo.yang");
+
         Module module;
         try (InputStream stream = new FileInputStream(new File(getClass().getResource("/context-test/test2.yang")
                 .toURI()))) {
@@ -371,12 +365,8 @@ public class YangParserWithContextTest {
     @Test
     public void testDeviation() throws Exception {
         // load first module
-        SchemaContext context;
-        String resource = "/model/bar.yang";
-
-        try (InputStream stream = new FileInputStream(new File(getClass().getResource(resource).toURI()))) {
-            context = parser.resolveSchemaContext(TestUtils.loadModules(Lists.newArrayList(stream)));
-        }
+        SchemaContext context = parser.parseFiles(Collections.singleton(
+            new File(getClass().getResource("/model/bar.yang").toURI())));
 
         // load another modules and parse them against already existing context
         Set<Module> modules;