jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fschumac...@apache.org
Subject [jmeter] branch master updated: Use correct conversion for URLs to File
Date Wed, 25 Mar 2020 15:26:48 GMT
This is an automated email from the ASF dual-hosted git repository.

fschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git


The following commit(s) were added to refs/heads/master by this push:
     new 33e23b8  Use correct conversion for URLs to File
33e23b8 is described below

commit 33e23b80ebf7c769950c8d3852281f1cd63ad35d
Author: Felix Schumacher <felix.schumacher@internetallee.de>
AuthorDate: Wed Mar 25 16:23:40 2020 +0100

    Use correct conversion for URLs to File
    
    After using File directly for TemplateManager the tests failed for Files
    that are created by reading resources from classes, when those resources
    are located inside of directories containing spaces.
    
    Use Paths API to convert the URIs to Files that have correctly decoded
    names.
    
    Bugzilla Id: 64227
---
 .../jmeter/gui/action/template/TestTemplateManager.java   | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/components/src/test/java/org/apache/jmeter/gui/action/template/TestTemplateManager.java
b/src/components/src/test/java/org/apache/jmeter/gui/action/template/TestTemplateManager.java
index 791ff0a..7990339 100644
--- a/src/components/src/test/java/org/apache/jmeter/gui/action/template/TestTemplateManager.java
+++ b/src/components/src/test/java/org/apache/jmeter/gui/action/template/TestTemplateManager.java
@@ -26,6 +26,8 @@ import static org.junit.Assert.assertTrue;
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.net.URISyntaxException;
+import java.nio.file.Paths;
 import java.util.Collections;
 import java.util.Map;
 
@@ -52,7 +54,7 @@ public class TestTemplateManager extends JMeterTestCase {
     }
 
     private Map<String, Template> readTemplateFromFile() {
-        File xmlTemplate = new File(this.getClass().getResource("validTemplates.xml").getFile());
+        File xmlTemplate = getFileFromResource("validTemplates.xml");
         try {
             return TemplateManager.getInstance().parseTemplateFile(xmlTemplate);
         } catch (IOException | SAXException | ParserConfigurationException e) {
@@ -60,6 +62,14 @@ public class TestTemplateManager extends JMeterTestCase {
         }
     }
 
+    private File getFileFromResource(String resourceName) {
+        try {
+            return Paths.get(this.getClass().getResource(resourceName).toURI()).toFile();
+        } catch (URISyntaxException e) {
+            throw new RuntimeException("Can't read resource " + resourceName, e);
+        }
+    }
+
     @Test
     public void testValidTemplateFile() {
         Template testTemplate = templateMap.get("testTemplateWithParameters");
@@ -98,8 +108,7 @@ public class TestTemplateManager extends JMeterTestCase {
     @Test
     public void testInvalidTemplateXml() throws IOException, SAXException, ParserConfigurationException
{
         try {
-            String xmlTemplatePath = this.getClass().getResource("invalidTemplates.xml").getFile();
-            File templateFile = new File(xmlTemplatePath);
+            File templateFile = getFileFromResource("invalidTemplates.xml");
             TemplateManager.getInstance().parseTemplateFile(templateFile);
         } catch (SAXParseException ex) {
             assertTrue("Exception did not contains expected message, got:" + ex.getMessage(),


Mime
View raw message