From e182798c1f8e7cdaa63662e2290c85a27e5a8c6c Mon Sep 17 00:00:00 2001 From: Martin Vitez Date: Mon, 17 Feb 2014 12:54:30 +0100 Subject: [PATCH] Fixed incorrect path construction in JUnit tests. Change-Id: I0a9d73876ea0dd6263d414e91070d405fef9069b Signed-off-by: Martin Vitez --- .../impl/GeneratedTypesStringTest.java | 5 +- .../generator/impl/GeneratedTypesTest.java | 50 +++++----- .../util/BindingGeneratorUtilTest.java | 8 +- .../test/ClassCodeGeneratorTest.java | 5 +- .../generator/test/CompilationTestUtils.java | 5 +- ...InnerClassForBitsAndUnionInLeavesTest.java | 8 +- .../doc/generator/maven/DocGenTest.java | 5 +- .../wadl/generator/maven/WadlGenTest.java | 5 +- .../yang/data/impl/XmlTreeBuilderTest.java | 8 +- .../plugin/it/YangToSourcesPluginTestIT.java | 25 ++--- .../plugin/GenerateSourcesTest.java | 5 +- .../yang2sources/plugin/UtilTest.java | 7 +- .../yang/parser/impl/AugmentTest.java | 8 +- .../yang/parser/impl/GroupingTest.java | 9 +- .../yangtools/yang/parser/impl/TestUtils.java | 9 +- .../yang/parser/impl/TwoRevisionsTest.java | 2 +- .../yang/parser/impl/TypesResolutionTest.java | 7 +- .../yang/parser/impl/UsesAugmentTest.java | 7 +- .../parser/impl/YangParserNegativeTest.java | 93 +++++++++---------- .../parser/impl/YangParserSimpleTest.java | 5 +- .../yang/parser/impl/YangParserTest.java | 29 +++--- .../impl/YangParserWithContextTest.java | 56 +++++------ 22 files changed, 186 insertions(+), 175 deletions(-) diff --git a/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GeneratedTypesStringTest.java b/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GeneratedTypesStringTest.java index 5aacf67c09..ada474a78e 100644 --- a/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GeneratedTypesStringTest.java +++ b/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GeneratedTypesStringTest.java @@ -10,6 +10,7 @@ package org.opendaylight.yangtools.sal.binding.generator.impl; import static org.junit.Assert.*; import java.io.File; +import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -31,9 +32,9 @@ public class GeneratedTypesStringTest { private final static List testModels = new ArrayList(); @BeforeClass - public static void loadTestResources() { + public static void loadTestResources() throws URISyntaxException { final File listModelFile = new File(GeneratedTypesStringTest.class.getResource("/simple-string-demo.yang") - .getPath()); + .toURI()); testModels.add(listModelFile); } diff --git a/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GeneratedTypesTest.java b/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GeneratedTypesTest.java index 913d0b6a2d..d23beef44c 100644 --- a/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GeneratedTypesTest.java +++ b/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GeneratedTypesTest.java @@ -10,6 +10,8 @@ package org.opendaylight.yangtools.sal.binding.generator.impl; import static org.junit.Assert.*; import java.io.File; +import java.net.URI; +import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -28,7 +30,7 @@ import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; public class GeneratedTypesTest { - private SchemaContext resolveSchemaContextFromFiles(final String... yangFiles) { + private SchemaContext resolveSchemaContextFromFiles(final URI... yangFiles) { final YangModelParser parser = new YangParserImpl(); final List inputFiles = new ArrayList(); @@ -41,9 +43,9 @@ public class GeneratedTypesTest { } @Test - public void testMultipleModulesResolving() { - final String topologyPath = getClass().getResource("/abstract-topology.yang").getPath(); - final String typesPath = getClass().getResource("/ietf-inet-types@2010-09-24.yang").getPath(); + public void testMultipleModulesResolving() throws URISyntaxException { + final URI topologyPath = getClass().getResource("/abstract-topology.yang").toURI(); + final URI typesPath = getClass().getResource("/ietf-inet-types@2010-09-24.yang").toURI(); final SchemaContext context = resolveSchemaContextFromFiles(topologyPath, typesPath); assertNotNull(context); @@ -55,17 +57,15 @@ public class GeneratedTypesTest { } @Test - public void testLeafrefResolving() { - final String topologyPath = getClass().getResource("/leafref-test-models/abstract-topology@2013-02-08.yang") - .getPath(); - final String interfacesPath = getClass().getResource("/leafref-test-models/ietf-interfaces@2012-11-15.yang") - .getPath(); - // final String ifTypePath = getClass().getResource( - // "/leafref-test-models/iana-if-type@2012-06-05.yang").getPath(); - final String inetTypesPath = getClass().getResource("/leafref-test-models/ietf-inet-types@2010-09-24.yang") - .getPath(); - final String yangTypesPath = getClass().getResource("/leafref-test-models/ietf-yang-types@2010-09-24.yang") - .getPath(); + public void testLeafrefResolving() throws URISyntaxException { + final URI topologyPath = getClass().getResource("/leafref-test-models/abstract-topology@2013-02-08.yang") + .toURI(); + final URI interfacesPath = getClass().getResource("/leafref-test-models/ietf-interfaces@2012-11-15.yang") + .toURI(); + final URI inetTypesPath = getClass().getResource("/leafref-test-models/ietf-inet-types@2010-09-24.yang") + .toURI(); + final URI yangTypesPath = getClass().getResource("/leafref-test-models/ietf-yang-types@2010-09-24.yang") + .toURI(); assertNotNull(topologyPath); assertNotNull(interfacesPath); @@ -253,8 +253,8 @@ public class GeneratedTypesTest { } @Test - public void testContainerResolving() { - final String filePath = getClass().getResource("/simple-container-demo.yang").getPath(); + public void testContainerResolving() throws URISyntaxException { + final URI filePath = getClass().getResource("/simple-container-demo.yang").toURI(); final SchemaContext context = resolveSchemaContextFromFiles(filePath); assert (context != null); @@ -338,8 +338,8 @@ public class GeneratedTypesTest { } @Test - public void testLeafListResolving() { - final String filePath = getClass().getResource("/simple-leaf-list-demo.yang").getPath(); + public void testLeafListResolving() throws URISyntaxException { + final URI filePath = getClass().getResource("/simple-leaf-list-demo.yang").toURI(); final SchemaContext context = resolveSchemaContextFromFiles(filePath); assertNotNull(context); @@ -422,8 +422,8 @@ public class GeneratedTypesTest { } @Test - public void testListResolving() { - final String filePath = getClass().getResource("/simple-list-demo.yang").getPath(); + public void testListResolving() throws URISyntaxException { + final URI filePath = getClass().getResource("/simple-list-demo.yang").toURI(); final SchemaContext context = resolveSchemaContextFromFiles(filePath); assertNotNull(context); @@ -545,8 +545,8 @@ public class GeneratedTypesTest { } @Test - public void testListCompositeKeyResolving() { - final String filePath = getClass().getResource("/list-composite-key.yang").getPath(); + public void testListCompositeKeyResolving() throws URISyntaxException { + final URI filePath = getClass().getResource("/list-composite-key.yang").toURI(); final SchemaContext context = resolveSchemaContextFromFiles(filePath); assertNotNull(context); @@ -598,8 +598,8 @@ public class GeneratedTypesTest { } @Test - public void testGeneratedTypes() { - final String filePath = getClass().getResource("/demo-topology.yang").getPath(); + public void testGeneratedTypes() throws URISyntaxException { + final URI filePath = getClass().getResource("/demo-topology.yang").toURI(); final SchemaContext context = resolveSchemaContextFromFiles(filePath); assertNotNull(context); diff --git a/code-generator/binding-generator-util/src/test/java/org/opendaylight/yangtools/binding/generator/util/BindingGeneratorUtilTest.java b/code-generator/binding-generator-util/src/test/java/org/opendaylight/yangtools/binding/generator/util/BindingGeneratorUtilTest.java index 4f458c0c7e..4b7a86539d 100644 --- a/code-generator/binding-generator-util/src/test/java/org/opendaylight/yangtools/binding/generator/util/BindingGeneratorUtilTest.java +++ b/code-generator/binding-generator-util/src/test/java/org/opendaylight/yangtools/binding/generator/util/BindingGeneratorUtilTest.java @@ -13,6 +13,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import java.io.File; +import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -30,7 +31,12 @@ public class BindingGeneratorUtilTest { private static List loadTestResources(String testFile) { final List testModels = new ArrayList(); - final File listModelFile = new File(BindingGeneratorUtilTest.class.getResource(testFile).getPath()); + File listModelFile; + try { + listModelFile = new File(BindingGeneratorUtilTest.class.getResource(testFile).toURI()); + } catch (URISyntaxException e) { + throw new IllegalArgumentException("Failed to load sources from " + testFile); + } testModels.add(listModelFile); return testModels; } diff --git a/code-generator/binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/ClassCodeGeneratorTest.java b/code-generator/binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/ClassCodeGeneratorTest.java index 4efffc1d7c..c6220c0a6c 100644 --- a/code-generator/binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/ClassCodeGeneratorTest.java +++ b/code-generator/binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/ClassCodeGeneratorTest.java @@ -10,6 +10,7 @@ package org.opendaylight.yangtools.sal.java.api.generator.test; import static org.junit.Assert.*; import java.io.File; +import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -38,9 +39,9 @@ public class ClassCodeGeneratorTest { private final static List testModels = new ArrayList(); @BeforeClass - public static void loadTestResources() { + public static void loadTestResources() throws URISyntaxException { final File listModelFile = new File(ClassCodeGeneratorTest.class - .getResource("/list-composite-key.yang").getPath()); + .getResource("/list-composite-key.yang").toURI()); testModels.add(listModelFile); } diff --git a/code-generator/binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/CompilationTestUtils.java b/code-generator/binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/CompilationTestUtils.java index f0f869f7bb..eec32cca49 100644 --- a/code-generator/binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/CompilationTestUtils.java +++ b/code-generator/binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/CompilationTestUtils.java @@ -16,6 +16,7 @@ import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.ParameterizedType; +import java.net.URI; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -410,8 +411,8 @@ public class CompilationTestUtils { return result; } - static List getSourceFiles(String path) throws FileNotFoundException { - final String resPath = BaseCompilationTest.class.getResource(path).getPath(); + static List getSourceFiles(String path) throws Exception { + final URI resPath = BaseCompilationTest.class.getResource(path).toURI(); final File sourcesDir = new File(resPath); if (sourcesDir.exists()) { final List sourceFiles = new ArrayList<>(); diff --git a/code-generator/binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/GenerateInnerClassForBitsAndUnionInLeavesTest.java b/code-generator/binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/GenerateInnerClassForBitsAndUnionInLeavesTest.java index 56061856a1..70fe5df6a0 100644 --- a/code-generator/binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/GenerateInnerClassForBitsAndUnionInLeavesTest.java +++ b/code-generator/binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/GenerateInnerClassForBitsAndUnionInLeavesTest.java @@ -10,6 +10,8 @@ package org.opendaylight.yangtools.sal.java.api.generator.test; import static org.junit.Assert.assertTrue; import java.io.File; +import java.net.URI; +import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -28,7 +30,7 @@ import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; public class GenerateInnerClassForBitsAndUnionInLeavesTest { - private SchemaContext resolveSchemaContextFromFiles(final String... yangFiles) { + private SchemaContext resolveSchemaContextFromFiles(final URI... yangFiles) { final YangModelParser parser = new YangParserImpl(); final List inputFiles = new ArrayList(); @@ -41,8 +43,8 @@ public class GenerateInnerClassForBitsAndUnionInLeavesTest { } @Test - public void testInnerClassCreationForBitsAndUnionsInLeafes() { - final String yangTypesPath = getClass().getResource("/bit_and_union_in_leaf.yang").getPath(); + public void testInnerClassCreationForBitsAndUnionsInLeafes() throws URISyntaxException { + final URI yangTypesPath = getClass().getResource("/bit_and_union_in_leaf.yang").toURI(); final SchemaContext context = resolveSchemaContextFromFiles(yangTypesPath); assertTrue(context != null); diff --git a/code-generator/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/unified/doc/generator/maven/DocGenTest.java b/code-generator/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/unified/doc/generator/maven/DocGenTest.java index e5f3bd0a77..b15193d2ce 100644 --- a/code-generator/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/unified/doc/generator/maven/DocGenTest.java +++ b/code-generator/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/unified/doc/generator/maven/DocGenTest.java @@ -11,6 +11,7 @@ import static org.junit.Assert.assertTrue; import java.io.File; import java.io.FileNotFoundException; +import java.net.URI; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -55,8 +56,8 @@ public class DocGenTest { generator.generateSources(context, GENERATOR_OUTPUT_DIR, modulesToBuild); } - private static List getSourceFiles(String path) throws FileNotFoundException { - final String resPath = DocGenTest.class.getResource(path).getPath(); + private static List getSourceFiles(String path) throws Exception { + final URI resPath = DocGenTest.class.getResource(path).toURI(); final File sourcesDir = new File(resPath); if (sourcesDir.exists()) { final List sourceFiles = new ArrayList<>(); diff --git a/code-generator/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/wadl/generator/maven/WadlGenTest.java b/code-generator/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/wadl/generator/maven/WadlGenTest.java index 78c8dff2ae..174baf72c0 100644 --- a/code-generator/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/wadl/generator/maven/WadlGenTest.java +++ b/code-generator/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/yangtools/yang/wadl/generator/maven/WadlGenTest.java @@ -11,6 +11,7 @@ import static org.junit.Assert.*; import java.io.File; import java.io.FileNotFoundException; +import java.net.URI; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -57,8 +58,8 @@ public class WadlGenTest { assertEquals(3, generatedWadlFiles.size()); } - private static List getSourceFiles(String path) throws FileNotFoundException { - final String resPath = WadlGenTest.class.getResource(path).getPath(); + private static List getSourceFiles(String path) throws Exception { + final URI resPath = WadlGenTest.class.getResource(path).toURI(); final File sourcesDir = new File(resPath); if (sourcesDir.exists()) { final List sourceFiles = new ArrayList<>(); diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/XmlTreeBuilderTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/XmlTreeBuilderTest.java index 3cddd8c844..b302c84b99 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/XmlTreeBuilderTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/XmlTreeBuilderTest.java @@ -11,8 +11,10 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import java.io.File; import java.io.FileInputStream; import java.io.InputStream; +import java.net.URI; import java.util.List; import javax.xml.stream.XMLStreamException; @@ -40,8 +42,8 @@ public class XmlTreeBuilderTest { */ @Before public void setUp() throws Exception { - final String inputFile = getClass().getResource("/rpc-getDeviceEquipment.xml").getPath(); - inputStream = new FileInputStream(inputFile); + final URI inputFile = getClass().getResource("/rpc-getDeviceEquipment.xml").toURI(); + inputStream = new FileInputStream(new File(inputFile)); } /** @@ -123,4 +125,4 @@ public class XmlTreeBuilderTest { List compositesByName = params.get(0).getCompositesByName("param"); assertEquals(2, compositesByName.size()); } -} \ No newline at end of file +} diff --git a/yang/yang-maven-plugin-it/src/test/java/org/opendaylight/yangtools/yang2sources/plugin/it/YangToSourcesPluginTestIT.java b/yang/yang-maven-plugin-it/src/test/java/org/opendaylight/yangtools/yang2sources/plugin/it/YangToSourcesPluginTestIT.java index feb051e820..1967c2a633 100644 --- a/yang/yang-maven-plugin-it/src/test/java/org/opendaylight/yangtools/yang2sources/plugin/it/YangToSourcesPluginTestIT.java +++ b/yang/yang-maven-plugin-it/src/test/java/org/opendaylight/yangtools/yang2sources/plugin/it/YangToSourcesPluginTestIT.java @@ -15,6 +15,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +import java.net.URISyntaxException; import java.net.URL; import java.util.Properties; @@ -31,7 +32,7 @@ public class YangToSourcesPluginTestIT { // TODO Test yang files in transitive dependencies @Test - public void testYangRootNotExist() { + public void testYangRootNotExist() throws URISyntaxException { try { setUp("YangRootNotExist/", false); } catch (VerificationException e) { @@ -47,13 +48,13 @@ public class YangToSourcesPluginTestIT { } @Test - public void testCorrect() throws VerificationException { + public void testCorrect() throws Exception { Verifier v = setUp("Correct/", false); verifyCorrectLog(v); } @Test - public void testAdditionalConfiguration() throws VerificationException { + public void testAdditionalConfiguration() throws Exception { Verifier v = setUp("AdditionalConfig/", false); v.verifyTextInLog("[DEBUG] yang-to-sources: Additional configuration picked up for : org.opendaylight.yangtools.yang2sources.spi.CodeGeneratorTestImpl: {nm1=abcd=a.b.c.d, nm2=abcd2=a.b.c.d.2}"); v.verifyTextInLog("[DEBUG] yang-to-sources: Additional configuration picked up for : org.opendaylight.yangtools.yang2sources.spi.CodeGeneratorTestImpl: {c1=config}"); @@ -65,7 +66,7 @@ public class YangToSourcesPluginTestIT { } @Test - public void testMissingYangInDep() throws VerificationException { + public void testMissingYangInDep() throws Exception { try { setUp("MissingYangInDep/", false); } catch (VerificationException e) { @@ -86,14 +87,14 @@ public class YangToSourcesPluginTestIT { } @Test - public void testNoGenerators() throws VerificationException { + public void testNoGenerators() throws Exception { Verifier v = setUp("NoGenerators/", false); v.verifyErrorFreeLog(); v.verifyTextInLog("[WARNING] yang-to-sources: No code generators provided"); } @Test - public void testUnknownGenerator() throws VerificationException { + public void testUnknownGenerator() throws Exception { Verifier v = setUp("UnknownGenerator/", true); v.verifyTextInLog("[ERROR] yang-to-sources: Unable to generate sources with unknown generator"); v.verifyTextInLog("java.lang.ClassNotFoundException: unknown"); @@ -103,7 +104,7 @@ public class YangToSourcesPluginTestIT { } @Test - public void testNoYangFiles() throws VerificationException { + public void testNoYangFiles() throws Exception { Verifier v = setUp("NoYangFiles/", false); v.verifyTextInLog("[INFO] yang-to-sources: No input files found"); } @@ -125,10 +126,10 @@ public class YangToSourcesPluginTestIT { } static Verifier setUp(String project, boolean ignoreF) - throws VerificationException { + throws VerificationException, URISyntaxException { final URL path = YangToSourcesPluginTestIT.class.getResource("/" + project + "pom.xml"); - File parent = new File(path.getPath()); + File parent = new File(path.toURI()); Verifier verifier = new Verifier(parent.getParent()); if (ignoreF) verifier.addCliOption("-fn"); @@ -139,15 +140,15 @@ public class YangToSourcesPluginTestIT { } @Test - public void testNoOutputDir() throws VerificationException { + public void testNoOutputDir() throws Exception { Verifier v = YangToSourcesPluginTestIT.setUp("NoOutputDir/", false); verifyCorrectLog(v); } @Test - public void testFindResourceOnCp() throws VerificationException { + public void testFindResourceOnCp() throws Exception { Verifier v1 = new Verifier(new File(getClass().getResource( - "/GenerateTest1/pom.xml").getPath()).getParent()); + "/GenerateTest1/pom.xml").toURI()).getParent()); v1.setSystemProperties(props); v1.executeGoal("clean"); v1.executeGoal("package"); diff --git a/yang/yang-maven-plugin/src/test/java/org/opendaylight/yangtools/yang2sources/plugin/GenerateSourcesTest.java b/yang/yang-maven-plugin/src/test/java/org/opendaylight/yangtools/yang2sources/plugin/GenerateSourcesTest.java index a48124028a..3ab8a8c228 100644 --- a/yang/yang-maven-plugin/src/test/java/org/opendaylight/yangtools/yang2sources/plugin/GenerateSourcesTest.java +++ b/yang/yang-maven-plugin/src/test/java/org/opendaylight/yangtools/yang2sources/plugin/GenerateSourcesTest.java @@ -19,7 +19,6 @@ import java.util.Collection; import java.util.Map; import java.util.Set; -import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.logging.Log; import org.apache.maven.project.MavenProject; import org.junit.Before; @@ -43,10 +42,10 @@ public class GenerateSourcesTest { private MavenProject project; @Before - public void setUp() throws MojoFailureException { + public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - yang = new File(getClass().getResource("/yang/mock.yang").getFile()).getParent(); + yang = new File(getClass().getResource("/yang/mock.yang").toURI()).getParent(); outDir = new File("/outputDir"); YangProvider mock = mock(YangProvider.class); doNothing().when(mock).addYangsToMetaInf(any(Log.class), any(MavenProject.class), any(File.class), diff --git a/yang/yang-maven-plugin/src/test/java/org/opendaylight/yangtools/yang2sources/plugin/UtilTest.java b/yang/yang-maven-plugin/src/test/java/org/opendaylight/yangtools/yang2sources/plugin/UtilTest.java index b647760340..6945ef9303 100644 --- a/yang/yang-maven-plugin/src/test/java/org/opendaylight/yangtools/yang2sources/plugin/UtilTest.java +++ b/yang/yang-maven-plugin/src/test/java/org/opendaylight/yangtools/yang2sources/plugin/UtilTest.java @@ -10,7 +10,6 @@ package org.opendaylight.yangtools.yang2sources.plugin; import static org.junit.Assert.*; import java.io.File; -import java.io.FileNotFoundException; import java.util.Collection; import org.junit.Test; @@ -18,10 +17,8 @@ import org.junit.Test; public class UtilTest { @Test - public void testCache() throws FileNotFoundException { - String yang = new File(getClass().getResource("/yang/mock.yang") - .getFile()) - .getParent(); + public void testCache() throws Exception { + String yang = new File(getClass().getResource("/yang/mock.yang").toURI()).getParent(); Collection files = Util.listFiles(new File(yang)); Collection files2 = Util.listFiles(new File(yang)); assertTrue(files == files2); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/AugmentTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/AugmentTest.java index c362a2179c..011f4cd8c5 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/AugmentTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/AugmentTest.java @@ -66,7 +66,7 @@ public class AugmentTest { @Test public void testAugmentParsing() throws Exception { - modules = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment").getPath()); + modules = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment").toURI()); SchemaPath expectedSchemaPath; List qnames = new ArrayList<>(); qnames.add(q0); @@ -171,7 +171,7 @@ public class AugmentTest { @Test public void testAugmentResolving() throws Exception { - modules = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment").getPath()); + modules = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment").toURI()); Module module2 = TestUtils.findModule(modules, "bar"); ContainerSchemaNode interfaces = (ContainerSchemaNode) module2.getDataChildByName("interfaces"); ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName("ifEntry"); @@ -233,7 +233,7 @@ public class AugmentTest { @Test public void testAugmentedChoice() throws Exception { - modules = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment").getPath()); + modules = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-augment").toURI()); Module module2 = TestUtils.findModule(modules, "bar"); ContainerSchemaNode interfaces = (ContainerSchemaNode) module2.getDataChildByName("interfaces"); ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName("ifEntry"); @@ -338,7 +338,7 @@ public class AugmentTest { @Test public void testAugmentRpc() throws Exception { - modules = TestUtils.loadModules(getClass().getResource("/augment-test/rpc").getPath()); + modules = TestUtils.loadModules(getClass().getResource("/augment-test/rpc").toURI()); final URI NS_BAR = URI.create("urn:opendaylight:bar"); final URI NS_FOO = URI.create("urn:opendaylight:foo"); final Date revision = new SimpleDateFormat("yyyy-MM-dd").parse("2013-10-11"); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/GroupingTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/GroupingTest.java index 2adb544f5a..163ee55851 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/GroupingTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/GroupingTest.java @@ -12,6 +12,7 @@ import static org.junit.Assert.*; import java.io.File; import java.io.FileNotFoundException; import java.net.URI; +import java.net.URISyntaxException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Collections; @@ -43,8 +44,8 @@ public class GroupingTest { private Set modules; @Before - public void init() throws FileNotFoundException { - modules = TestUtils.loadModules(getClass().getResource("/model").getPath()); + public void init() throws FileNotFoundException, URISyntaxException { + modules = TestUtils.loadModules(getClass().getResource("/model").toURI()); assertEquals(3, modules.size()); } @@ -345,8 +346,8 @@ public class GroupingTest { } @Test - public void testCascadeUses() throws FileNotFoundException, ParseException { - File yangFile = new File(getClass().getResource("/grouping-test/cascade-uses.yang").getPath()); + public void testCascadeUses() throws Exception { + File yangFile = new File(getClass().getResource("/grouping-test/cascade-uses.yang").toURI()); YangModelParser parser = new YangParserImpl(); modules = parser.parseYangModels(Collections.singletonList(yangFile)); assertEquals(1, modules.size()); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/TestUtils.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/TestUtils.java index e66a8dc0b0..2f23d12e37 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/TestUtils.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/TestUtils.java @@ -23,17 +23,14 @@ final class TestUtils { private TestUtils() { } - public static Set loadModules(String resourceDirectory) throws FileNotFoundException { - YangModelParser parser = new YangParserImpl(); - return loadModules(resourceDirectory, parser); - } - public static Set loadModules(String resourceDirectory, YangModelParser parser) throws FileNotFoundException { + public static Set loadModules(URI resourceDirectory) throws FileNotFoundException { + final YangModelParser parser = new YangParserImpl(); final File testDir = new File(resourceDirectory); final String[] fileList = testDir.list(); final List testFiles = new ArrayList<>(); if (fileList == null) { - throw new FileNotFoundException(resourceDirectory); + throw new FileNotFoundException(resourceDirectory.toString()); } for (String fileName : fileList) { testFiles.add(new File(testDir, fileName)); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/TwoRevisionsTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/TwoRevisionsTest.java index 82519d82d4..9b6277e689 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/TwoRevisionsTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/TwoRevisionsTest.java @@ -22,7 +22,7 @@ public class TwoRevisionsTest { public void testTwoRevisions() throws Exception { YangModelParser parser = new YangParserImpl(); - Set modules = TestUtils.loadModules(getClass().getResource("/ietf").getPath(), parser); + Set modules = TestUtils.loadModules(getClass().getResource("/ietf").toURI()); assertEquals(2, TestUtils.findModules(modules, "network-topology").size()); SchemaContext schemaContext = parser.resolveSchemaContext(modules); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/TypesResolutionTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/TypesResolutionTest.java index d471d85dbc..224d91aae7 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/TypesResolutionTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/TypesResolutionTest.java @@ -10,7 +10,6 @@ package org.opendaylight.yangtools.yang.parser.impl; import static org.junit.Assert.*; import java.io.File; -import java.io.FileNotFoundException; import java.net.URI; import java.util.List; import java.util.Set; @@ -40,9 +39,9 @@ public class TypesResolutionTest { private Set testedModules; @Before - public void init() throws FileNotFoundException { - File yangFile = new File(getClass().getResource("/types/custom-types-test@2012-4-4.yang").getPath()); - File dependenciesDir = new File(getClass().getResource("/ietf").getPath()); + public void init() throws Exception { + File yangFile = new File(getClass().getResource("/types/custom-types-test@2012-4-4.yang").toURI()); + File dependenciesDir = new File(getClass().getResource("/ietf").toURI()); YangModelParser parser = new YangParserImpl(); testedModules = parser.parseYangModels(yangFile, dependenciesDir); assertEquals(4, testedModules.size()); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/UsesAugmentTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/UsesAugmentTest.java index 1d760b870c..c713f759f1 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/UsesAugmentTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/UsesAugmentTest.java @@ -11,6 +11,7 @@ import static org.junit.Assert.*; import java.io.FileNotFoundException; import java.net.URI; +import java.net.URISyntaxException; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -113,7 +114,7 @@ public class UsesAugmentTest { */ @Test public void testAugmentInUses() throws Exception { - modules = TestUtils.loadModules(getClass().getResource("/grouping-test").getPath()); + modules = TestUtils.loadModules(getClass().getResource("/grouping-test").toURI()); Module testModule = TestUtils.findModule(modules, "uses-grouping"); LinkedList path = new LinkedList<>(); @@ -609,8 +610,8 @@ public class UsesAugmentTest { } @Test - public void testTypedefs() throws FileNotFoundException { - modules = TestUtils.loadModules(getClass().getResource("/grouping-test").getPath()); + public void testTypedefs() throws FileNotFoundException, URISyntaxException { + modules = TestUtils.loadModules(getClass().getResource("/grouping-test").toURI()); Module testModule = TestUtils.findModule(modules, "grouping-definitions"); Set> types = testModule.getTypeDefinitions(); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserNegativeTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserNegativeTest.java index d11a422432..52c7cfcb34 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserNegativeTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserNegativeTest.java @@ -22,10 +22,10 @@ import org.opendaylight.yangtools.yang.parser.util.YangValidationException; public class YangParserNegativeTest { @Test - public void testInvalidImport() throws IOException { + public void testInvalidImport() throws Exception { + File yang = new File(getClass().getResource("/negative-scenario/testfile1.yang").toURI()); try { - try (InputStream stream = new FileInputStream(getClass().getResource("/negative-scenario/testfile1.yang") - .getPath())) { + try (InputStream stream = new FileInputStream(yang)) { TestUtils.loadModule(stream); fail("ValidationException should by thrown"); } @@ -35,10 +35,10 @@ public class YangParserNegativeTest { } @Test - public void testTypeNotFound() throws IOException { + public void testTypeNotFound() throws Exception { + File yang = new File(getClass().getResource("/negative-scenario/testfile2.yang").toURI()); try { - try (InputStream stream = new FileInputStream(getClass().getResource("/negative-scenario/testfile2.yang") - .getPath())) { + try (InputStream stream = new FileInputStream(yang)) { TestUtils.loadModule(stream); fail("YangParseException should by thrown"); } @@ -48,14 +48,14 @@ public class YangParserNegativeTest { } @Test - public void testInvalidAugmentTarget() throws IOException { + public void testInvalidAugmentTarget() throws Exception { + File yang1 = new File(getClass().getResource("/negative-scenario/testfile0.yang").toURI()); + File yang2 = new File(getClass().getResource("/negative-scenario/testfile3.yang").toURI()); try { final List streams = new ArrayList<>(2); - try (InputStream testFile0 = new FileInputStream(getClass() - .getResource("/negative-scenario/testfile0.yang").getPath())) { + try (InputStream testFile0 = new FileInputStream(yang1)) { streams.add(testFile0); - try (InputStream testFile3 = new FileInputStream(getClass().getResource( - "/negative-scenario/testfile3.yang").getPath())) { + try (InputStream testFile3 = new FileInputStream(yang2)) { streams.add(testFile3); assertEquals("Expected loaded files count is 2", 2, streams.size()); TestUtils.loadModules(streams); @@ -70,10 +70,10 @@ public class YangParserNegativeTest { } @Test - public void testInvalidRefine() throws IOException { + public void testInvalidRefine() throws Exception { + File yang = new File(getClass().getResource("/negative-scenario/testfile4.yang").toURI()); try { - try (InputStream stream = new FileInputStream(getClass().getResource("/negative-scenario/testfile4.yang") - .getPath())) { + try (InputStream stream = new FileInputStream(yang)) { TestUtils.loadModule(stream); fail("YangParseException should by thrown"); } @@ -83,10 +83,10 @@ public class YangParserNegativeTest { } @Test - public void testInvalidLength() throws IOException { + public void testInvalidLength() throws Exception { + File yang = new File(getClass().getResource("/negative-scenario/testfile5.yang").toURI()); try { - try (InputStream stream = new FileInputStream(getClass().getResource("/negative-scenario/testfile5.yang") - .getPath())) { + try (InputStream stream = new FileInputStream(yang)) { TestUtils.loadModule(stream); fail("YangParseException should by thrown"); } @@ -96,10 +96,10 @@ public class YangParserNegativeTest { } @Test - public void testInvalidRange() throws IOException { + public void testInvalidRange() throws Exception { + File yang = new File(getClass().getResource("/negative-scenario/testfile6.yang").toURI()); try { - try (InputStream stream = new FileInputStream(getClass().getResource("/negative-scenario/testfile6.yang") - .getPath())) { + try (InputStream stream = new FileInputStream(yang)) { TestUtils.loadModule(stream); fail("YangParseException should by thrown"); } @@ -109,10 +109,10 @@ public class YangParserNegativeTest { } @Test - public void testDuplicateContainer() throws IOException { + public void testDuplicateContainer() throws Exception { + File yang = new File(getClass().getResource("/negative-scenario/duplicity/container.yang").toURI()); try { - try (InputStream stream = new FileInputStream(getClass().getResource( - "/negative-scenario/duplicity/container.yang").getPath())) { + try (InputStream stream = new FileInputStream(yang)) { TestUtils.loadModule(stream); fail("YangParseException should by thrown"); } @@ -123,10 +123,10 @@ public class YangParserNegativeTest { } @Test - public void testDuplicateContainerList() throws IOException { + public void testDuplicateContainerList() throws Exception { + File yang = new File(getClass().getResource("/negative-scenario/duplicity/container-list.yang").toURI()); try { - try (InputStream stream = new FileInputStream(getClass().getResource( - "/negative-scenario/duplicity/container-list.yang").getPath())) { + try (InputStream stream = new FileInputStream(yang)) { TestUtils.loadModule(stream); fail("YangParseException should by thrown"); } @@ -137,10 +137,10 @@ public class YangParserNegativeTest { } @Test - public void testDuplicateContainerLeaf() throws IOException { + public void testDuplicateContainerLeaf() throws Exception { + File yang = new File(getClass().getResource("/negative-scenario/duplicity/container-leaf.yang").toURI()); try { - try (InputStream stream = new FileInputStream(getClass().getResource( - "/negative-scenario/duplicity/container-leaf.yang").getPath())) { + try (InputStream stream = new FileInputStream(yang)) { TestUtils.loadModule(stream); fail("YangParseException should by thrown"); } @@ -151,10 +151,10 @@ public class YangParserNegativeTest { } @Test - public void testDuplicateTypedef() throws IOException { + public void testDuplicateTypedef() throws Exception { + File yang = new File(getClass().getResource("/negative-scenario/duplicity/typedef.yang").toURI()); try { - try (InputStream stream = new FileInputStream(getClass().getResource( - "/negative-scenario/duplicity/typedef.yang").getPath())) { + try (InputStream stream = new FileInputStream(yang)) { TestUtils.loadModule(stream); fail("YangParseException should by thrown"); } @@ -166,11 +166,10 @@ public class YangParserNegativeTest { @Test public void testDuplicityInAugmentTarget1() throws Exception { + File yang1 = new File(getClass().getResource("/negative-scenario/duplicity/augment0.yang").toURI()); + File yang2 = new File(getClass().getResource("/negative-scenario/duplicity/augment1.yang").toURI()); try { - try (InputStream stream1 = new FileInputStream(getClass().getResource( - "/negative-scenario/duplicity/augment0.yang").getPath()); - InputStream stream2 = new FileInputStream(getClass().getResource( - "/negative-scenario/duplicity/augment1.yang").getPath())) { + try (InputStream stream1 = new FileInputStream(yang1); InputStream stream2 = new FileInputStream(yang2)) { TestUtils.loadModules(Arrays.asList(stream1, stream2)); fail("YangParseException should by thrown"); } @@ -182,11 +181,10 @@ public class YangParserNegativeTest { @Test public void testDuplicityInAugmentTarget2() throws Exception { + File yang1 = new File(getClass().getResource("/negative-scenario/duplicity/augment0.yang").toURI()); + File yang2 = new File(getClass().getResource("/negative-scenario/duplicity/augment2.yang").toURI()); try { - try (InputStream stream1 = new FileInputStream(getClass().getResource( - "/negative-scenario/duplicity/augment0.yang").getPath()); - InputStream stream2 = new FileInputStream(getClass().getResource( - "/negative-scenario/duplicity/augment2.yang").getPath())) { + try (InputStream stream1 = new FileInputStream(yang1); InputStream stream2 = new FileInputStream(yang2)) { TestUtils.loadModules(Arrays.asList(stream1, stream2)); fail("YangParseException should by thrown"); } @@ -197,12 +195,11 @@ public class YangParserNegativeTest { } @Test - public void testMandatoryInAugment() throws IOException { + public void testMandatoryInAugment() throws Exception { + File yang1 = new File(getClass().getResource("/negative-scenario/testfile8.yang").toURI()); + File yang2 = new File(getClass().getResource("/negative-scenario/testfile7.yang").toURI()); try { - try (InputStream stream1 = new FileInputStream(getClass().getResource("/negative-scenario/testfile8.yang") - .getPath()); - InputStream stream2 = new FileInputStream(getClass().getResource( - "/negative-scenario/testfile7.yang").getPath())) { + try (InputStream stream1 = new FileInputStream(yang1); InputStream stream2 = new FileInputStream(yang2)) { TestUtils.loadModules(Arrays.asList(stream1, stream2)); fail("YangParseException should by thrown"); } @@ -215,7 +212,7 @@ public class YangParserNegativeTest { @Test public void testWrongDependenciesDir() throws Exception { try { - File yangFile = new File(getClass().getResource("/types/custom-types-test@2012-4-4.yang").getPath()); + File yangFile = new File(getClass().getResource("/types/custom-types-test@2012-4-4.yang").toURI()); File dependenciesDir = new File("/invalid"); YangModelParser parser = new YangParserImpl(); parser.parseYangModels(yangFile, dependenciesDir); @@ -229,8 +226,8 @@ public class YangParserNegativeTest { @Test public void testWrongDependenciesDir2() throws Exception { try { - File yangFile = new File(getClass().getResource("/types/custom-types-test@2012-4-4.yang").getPath()); - File dependenciesDir = new File(getClass().getResource("/model").getPath()); + File yangFile = new File(getClass().getResource("/types/custom-types-test@2012-4-4.yang").toURI()); + File dependenciesDir = new File(getClass().getResource("/model").toURI()); YangModelParser parser = new YangParserImpl(); parser.parseYangModels(yangFile, dependenciesDir); fail("Exception should by thrown"); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserSimpleTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserSimpleTest.java index 65142b962c..dfbcc74e47 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserSimpleTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserSimpleTest.java @@ -9,7 +9,6 @@ package org.opendaylight.yangtools.yang.parser.impl; import static org.junit.Assert.*; -import java.io.FileNotFoundException; import java.net.URI; import java.text.DateFormat; import java.text.ParseException; @@ -33,9 +32,9 @@ public class YangParserSimpleTest { private Set modules; @Before - public void init() throws FileNotFoundException, ParseException { + public void init() throws Exception { snRev = simpleDateFormat.parse("2013-07-30"); - modules = TestUtils.loadModules(getClass().getResource("/simple-test").getPath()); + modules = TestUtils.loadModules(getClass().getResource("/simple-test").toURI()); } @Test diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserTest.java index 7465b3478c..0d2f1dffc9 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserTest.java @@ -14,6 +14,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.net.URI; +import java.net.URISyntaxException; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -56,13 +57,13 @@ public class YangParserTest { private Set modules; @Before - public void init() throws FileNotFoundException, ParseException { + public void init() throws Exception { DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); fooRev = simpleDateFormat.parse("2013-02-27"); barRev = simpleDateFormat.parse("2013-07-03"); bazRev = simpleDateFormat.parse("2013-02-27"); - modules = TestUtils.loadModules(getClass().getResource("/model").getPath()); + modules = TestUtils.loadModules(getClass().getResource("/model").toURI()); assertEquals(3, modules.size()); } @@ -801,28 +802,28 @@ public class YangParserTest { } @Test - public void testParseMethod1() throws ParseException { - File yangFile = new File(getClass().getResource("/parse-methods/m1.yang").getPath()); - File dependenciesDir = new File(getClass().getResource("/parse-methods").getPath()); + public void testParseMethod1() throws Exception { + File yangFile = new File(getClass().getResource("/parse-methods/m1.yang").toURI()); + File dependenciesDir = new File(getClass().getResource("/parse-methods").toURI()); YangModelParser parser = new YangParserImpl(); modules = parser.parseYangModels(yangFile, dependenciesDir); assertEquals(6, modules.size()); } @Test - public void testParseMethod2() throws ParseException { - File yangFile = new File(getClass().getResource("/parse-methods/m1.yang").getPath()); - File dependenciesDir = new File(getClass().getResource("/parse-methods/dependencies").getPath()); + public void testParseMethod2() throws Exception { + File yangFile = new File(getClass().getResource("/parse-methods/m1.yang").toURI()); + File dependenciesDir = new File(getClass().getResource("/parse-methods/dependencies").toURI()); YangModelParser parser = new YangParserImpl(); modules = parser.parseYangModels(yangFile, dependenciesDir); assertEquals(6, modules.size()); } @Test - public void testSorting() throws FileNotFoundException { + public void testSorting() throws Exception { // Correct order: m2, m4, m6, m8, m7, m6, m3, m1 - File yangFile = new File(getClass().getResource("/sorting-test/m1.yang").getPath()); - File dependenciesDir = new File(getClass().getResource("/sorting-test").getPath()); + File yangFile = new File(getClass().getResource("/sorting-test/m1.yang").toURI()); + File dependenciesDir = new File(getClass().getResource("/sorting-test").toURI()); YangModelParser parser = new YangParserImpl(); modules = parser.parseYangModels(yangFile, dependenciesDir); SchemaContext ctx = new SchemaContextImpl(modules); @@ -914,9 +915,9 @@ public class YangParserTest { } @Test - public void testSubmodules() { - String yangFilePath = getClass().getResource("/submodule-test/subfoo.yang").getPath(); - String directoryPath = getClass().getResource("/model").getPath(); + public void testSubmodules() throws URISyntaxException { + URI yangFilePath = getClass().getResource("/submodule-test/subfoo.yang").toURI(); + URI directoryPath = getClass().getResource("/model").toURI(); File directory = new File(directoryPath); File yangFile = new File(yangFilePath); diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserWithContextTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserWithContextTest.java index 28ce35975a..e498675270 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserWithContextTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/YangParserWithContextTest.java @@ -42,12 +42,12 @@ public class YangParserWithContextTest { @Test public void testTypeFromContext() throws Exception { String resource = "/ietf/ietf-inet-types@2010-09-24.yang"; - InputStream stream = new FileInputStream(getClass().getResource(resource).getPath()); + InputStream stream = new FileInputStream(new File(getClass().getResource(resource).toURI())); SchemaContext context = parser.resolveSchemaContext(TestUtils.loadModules(Lists.newArrayList(stream))); stream.close(); resource = "/context-test/test1.yang"; - InputStream stream2 = new FileInputStream(getClass().getResource(resource).getPath()); + InputStream stream2 = new FileInputStream(new File(getClass().getResource(resource).toURI())); Module module = TestUtils.loadModuleWithContext("test1", stream2, context); stream2.close(); assertNotNull(module); @@ -79,13 +79,14 @@ public class YangParserWithContextTest { @Test public void testUsesFromContext() throws Exception { SchemaContext context; - try (InputStream stream1 = new FileInputStream(getClass().getResource("/model/baz.yang").getPath()); - InputStream stream2 = new FileInputStream(getClass().getResource("/model/bar.yang").getPath()); - InputStream stream3 = new FileInputStream(getClass().getResource("/model/foo.yang").getPath())) { + 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()))) { context = parser.resolveSchemaContext(TestUtils.loadModules(Lists.newArrayList(stream1, stream2, stream3))); } Module testModule; - try (InputStream stream = new FileInputStream(getClass().getResource("/context-test/test2.yang").getPath())) { + try (InputStream stream = new FileInputStream(new File(getClass().getResource("/context-test/test2.yang") + .toURI()))) { testModule = TestUtils.loadModuleWithContext("test2", stream, context); } assertNotNull(testModule); @@ -182,13 +183,14 @@ public class YangParserWithContextTest { @Test public void testUsesRefineFromContext() throws Exception { SchemaContext context; - try (InputStream stream1 = new FileInputStream(getClass().getResource("/model/baz.yang").getPath()); - InputStream stream2 = new FileInputStream(getClass().getResource("/model/bar.yang").getPath()); - InputStream stream3 = new FileInputStream(getClass().getResource("/model/foo.yang").getPath())) { + 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()))) { context = parser.resolveSchemaContext(TestUtils.loadModules(Lists.newArrayList(stream1, stream2, stream3))); } Module module; - try (InputStream stream = new FileInputStream(getClass().getResource("/context-test/test2.yang").getPath())) { + try (InputStream stream = new FileInputStream(new File(getClass().getResource("/context-test/test2.yang") + .toURI()))) { module = TestUtils.loadModuleWithContext("test2", stream, context); } assertNotNull(module); @@ -258,13 +260,14 @@ public class YangParserWithContextTest { @Test public void testIdentity() throws Exception { SchemaContext context; - File yangFile = new File(getClass().getResource("/types/custom-types-test@2012-4-4.yang").getPath()); - File dependenciesDir = new File(getClass().getResource("/ietf").getPath()); + File yangFile = new File(getClass().getResource("/types/custom-types-test@2012-4-4.yang").toURI()); + File dependenciesDir = new File(getClass().getResource("/ietf").toURI()); YangModelParser parser = new YangParserImpl(); context = parser.resolveSchemaContext(parser.parseYangModels(yangFile, dependenciesDir)); Module module; - try (InputStream stream = new FileInputStream(getClass().getResource("/context-test/test3.yang").getPath())) { + try (InputStream stream = new FileInputStream(new File(getClass().getResource("/context-test/test3.yang") + .toURI()))) { module = TestUtils.loadModuleWithContext("test3", stream, context); } assertNotNull(module); @@ -290,13 +293,14 @@ public class YangParserWithContextTest { @Test public void testUnknownNodes() throws Exception { SchemaContext context; - File yangFile = new File(getClass().getResource("/types/custom-types-test@2012-4-4.yang").getPath()); - File dependenciesDir = new File(getClass().getResource("/ietf").getPath()); + File yangFile = new File(getClass().getResource("/types/custom-types-test@2012-4-4.yang").toURI()); + File dependenciesDir = new File(getClass().getResource("/ietf").toURI()); YangModelParser parser = new YangParserImpl(); context = parser.resolveSchemaContext(parser.parseYangModels(yangFile, dependenciesDir)); Module module; - try (InputStream stream = new FileInputStream(getClass().getResource("/context-test/test3.yang").getPath())) { + try (InputStream stream = new FileInputStream(new File(getClass().getResource("/context-test/test3.yang") + .toURI()))) { module = TestUtils.loadModuleWithContext("test3", stream, context); } @@ -321,18 +325,18 @@ public class YangParserWithContextTest { SchemaContext context; String resource = "/context-augment-test/test4.yang"; - try (InputStream stream = new FileInputStream(getClass().getResource(resource).getPath())) { + try (InputStream stream = new FileInputStream(new File(getClass().getResource(resource).toURI()))) { context = parser.resolveSchemaContext(TestUtils.loadModules(Lists.newArrayList(stream))); } // load another modules and parse them against already existing context Set modules; - try (InputStream stream1 = new FileInputStream(getClass().getResource("/context-augment-test/test1.yang") - .getPath()); - InputStream stream2 = new FileInputStream(getClass().getResource("/context-augment-test/test2.yang") - .getPath()); - InputStream stream3 = new FileInputStream(getClass().getResource("/context-augment-test/test3.yang") - .getPath())) { + try (InputStream stream1 = new FileInputStream(new File(getClass().getResource( + "/context-augment-test/test1.yang").toURI())); + InputStream stream2 = new FileInputStream(new File(getClass().getResource( + "/context-augment-test/test2.yang").toURI())); + InputStream stream3 = new FileInputStream(new File(getClass().getResource( + "/context-augment-test/test3.yang").toURI()))) { List input = Lists.newArrayList(stream1, stream2, stream3); modules = TestUtils.loadModulesWithContext(input, context); } @@ -366,14 +370,14 @@ public class YangParserWithContextTest { SchemaContext context; String resource = "/model/bar.yang"; - try (InputStream stream = new FileInputStream(getClass().getResource(resource).getPath())) { + try (InputStream stream = new FileInputStream(new File(getClass().getResource(resource).toURI()))) { context = parser.resolveSchemaContext(TestUtils.loadModules(Lists.newArrayList(stream))); } // load another modules and parse them against already existing context Set modules; - try (InputStream stream = new FileInputStream(getClass().getResource("/context-test/deviation-test.yang") - .getPath())) { + try (InputStream stream = new FileInputStream(new File(getClass().getResource( + "/context-test/deviation-test.yang").toURI()))) { List input = Lists.newArrayList(stream); modules = TestUtils.loadModulesWithContext(input, context); } -- 2.36.6