Fix transformation of URL to file path

Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/6a466b89
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/6a466b89
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/6a466b89

Branch: refs/heads/master
Commit: 6a466b892be63e22c92fba5b5cc62764a008ef6d
Parents: 42e9aad
Author: Svetoslav Neykov <[email protected]>
Authored: Fri May 29 14:41:49 2015 +0300
Committer: Svetoslav Neykov <[email protected]>
Committed: Fri May 29 14:41:49 2015 +0300

----------------------------------------------------------------------
 .../launcher/BrooklynWebServerTest.java         | 21 ++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6a466b89/usage/launcher/src/test/java/brooklyn/launcher/BrooklynWebServerTest.java
----------------------------------------------------------------------
diff --git 
a/usage/launcher/src/test/java/brooklyn/launcher/BrooklynWebServerTest.java 
b/usage/launcher/src/test/java/brooklyn/launcher/BrooklynWebServerTest.java
index 98b2f2d..8a688c8 100644
--- a/usage/launcher/src/test/java/brooklyn/launcher/BrooklynWebServerTest.java
+++ b/usage/launcher/src/test/java/brooklyn/launcher/BrooklynWebServerTest.java
@@ -24,6 +24,8 @@ import static org.testng.Assert.fail;
 
 import java.io.File;
 import java.io.FileInputStream;
+import java.net.URISyntaxException;
+import java.net.URL;
 import java.security.KeyStore;
 import java.security.SecureRandom;
 import java.util.List;
@@ -183,9 +185,24 @@ public class BrooklynWebServerTest {
         keystore.load(instream, password.toCharArray());
         return keystore;
     }
+    
+    @Test
+    public void testGetFileFromUrl() throws Exception {
+        String url = "file:///tmp/special%40file%20with%20spaces";
+        String file = "/tmp/special@file with spaces";
+        assertEquals(getFile(new URL(url)), file);
+    }
 
-    private String getFile(String file) {
+    private String getFile(String classpathResource) {
         // this works because both IDE and Maven run tests with 
classes/resources on the file system
-        return new File(getClass().getResource("/" + 
file).getFile()).getAbsolutePath();
+        return getFile(getClass().getResource("/" + classpathResource));
+    }
+
+    private String getFile(URL url) {
+        try {
+            return new File(url.toURI()).getAbsolutePath();
+        } catch (URISyntaxException e) {
+            throw Exceptions.propagate(e);
+        }
     }
 }

Reply via email to