From 64cb165810e68656b711e4136e4a3ef4e80f8845 Mon Sep 17 00:00:00 2001
From: Nicolas Capponi <nicolas.capponi@forgerock.com>
Date: Thu, 19 Sep 2013 13:06:22 +0000
Subject: [PATCH] * Fixed failing test : ConnectionFactoryProviderTest unable to read truststore file when execution path contains whitespace (which is the case when running on Jenkins) * Avoid reading twice the value of trustStorePathArg and keyStorePathArg in getConnectionFactory method

---
 opendj3/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/ConnectionFactoryProvider.java     |    6 +++---
 opendj3/opendj-ldap-toolkit/src/test/java/com/forgerock/opendj/ldap/tools/ConnectionFactoryProviderTest.java |    5 ++++-
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/opendj3/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/ConnectionFactoryProvider.java b/opendj3/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/ConnectionFactoryProvider.java
index a2b4841..00051cc 100644
--- a/opendj3/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/ConnectionFactoryProvider.java
+++ b/opendj3/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/ConnectionFactoryProvider.java
@@ -378,7 +378,7 @@
             if (trustStorePathArg.isPresent()) {
                 // Check that the path exists and is readable
                 final String value = trustStorePathArg.getValue();
-                if (!canRead(trustStorePathArg.getValue())) {
+                if (!canReadPath(value)) {
                     final LocalizableMessage message = ERR_CANNOT_READ_TRUSTSTORE.get(value);
                     throw new ArgumentException(message);
                 }
@@ -387,7 +387,7 @@
             if (keyStorePathArg.isPresent()) {
                 // Check that the path exists and is readable
                 final String value = keyStorePathArg.getValue();
-                if (!canRead(keyStorePathArg.getValue())) {
+                if (!canReadPath(value)) {
                     final LocalizableMessage message = ERR_CANNOT_READ_KEYSTORE.get(value);
                     throw new ArgumentException(message);
                 }
@@ -464,7 +464,7 @@
      * @return <CODE>true</CODE> if we can read on the provided path and
      *         <CODE>false</CODE> otherwise.
      */
-    private boolean canRead(final String path) {
+    private boolean canReadPath(final String path) {
         boolean canRead;
         final File file = new File(path);
         canRead = file.exists() && file.canRead();
diff --git a/opendj3/opendj-ldap-toolkit/src/test/java/com/forgerock/opendj/ldap/tools/ConnectionFactoryProviderTest.java b/opendj3/opendj-ldap-toolkit/src/test/java/com/forgerock/opendj/ldap/tools/ConnectionFactoryProviderTest.java
index c1fd243..25f166e 100644
--- a/opendj3/opendj-ldap-toolkit/src/test/java/com/forgerock/opendj/ldap/tools/ConnectionFactoryProviderTest.java
+++ b/opendj3/opendj-ldap-toolkit/src/test/java/com/forgerock/opendj/ldap/tools/ConnectionFactoryProviderTest.java
@@ -27,6 +27,8 @@
 
 import static org.fest.assertions.Assertions.*;
 
+import java.io.File;
+
 import org.forgerock.i18n.LocalizableMessageBuilder;
 import org.forgerock.opendj.ldap.ConnectionFactory;
 import org.mockito.Mock;
@@ -54,7 +56,8 @@
     /** Issue OPENDJ-734 */
     public void getConnectionFactoryShouldAllowNullTrustStorePassword() throws Exception {
         // provide a trustStorePath but no password
-        String trustStorePath = getClass().getClassLoader().getResource("dummy-truststore").getFile();
+        String trustStorePath = new File(getClass().getClassLoader().getResource("dummy-truststore").toURI())
+                .getCanonicalPath();
         argParser.parseArguments(new String[] { "--useStartTLS", "--trustStorePath", trustStorePath });
 
         ConnectionFactory factory = connectionFactoryProvider.getConnectionFactory();

--
Gitblit v1.10.0