karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject [3/3] karaf git commit: Extract port update into class
Date Tue, 15 Aug 2017 14:41:54 GMT
Extract port update into class


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/ecf6a8dc
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/ecf6a8dc
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/ecf6a8dc

Branch: refs/heads/master
Commit: ecf6a8dc79cb6f36054f13376772428d9d58634e
Parents: 8a18da5
Author: Christian Schneider <chris@die-schneider.net>
Authored: Tue Aug 15 16:41:45 2017 +0200
Committer: Christian Schneider <chris@die-schneider.net>
Committed: Tue Aug 15 16:41:45 2017 +0200

----------------------------------------------------------------------
 .../karaf/jaas/modules/ldap/LdapCacheTest.java  | 26 +---------
 .../modules/ldap/LdapCaseInsensitiveDNTest.java | 28 +---------
 .../jaas/modules/ldap/LdapLoginModuleTest.java  | 31 +----------
 .../ldap/LdapLoginModuleWithEscapesTest.java    | 32 +-----------
 .../jaas/modules/ldap/LdapPropsUpdater.java     | 54 ++++++++++++++++++++
 .../ldap/LdapSpecialCharsInPasswordTest.java    | 26 +---------
 6 files changed, 61 insertions(+), 136 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/ecf6a8dc/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/ldap/LdapCacheTest.java
----------------------------------------------------------------------
diff --git a/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/ldap/LdapCacheTest.java
b/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/ldap/LdapCacheTest.java
index 87dde8f..1b88a16 100644
--- a/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/ldap/LdapCacheTest.java
+++ b/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/ldap/LdapCacheTest.java
@@ -23,12 +23,9 @@ import javax.naming.directory.DirContext;
 import javax.security.auth.Subject;
 import javax.security.auth.callback.CallbackHandler;
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.security.Principal;
 
-import org.apache.commons.io.IOUtils;
 import org.apache.directory.server.annotations.CreateLdapServer;
 import org.apache.directory.server.annotations.CreateTransport;
 import org.apache.directory.server.core.annotations.ApplyLdifFiles;
@@ -57,30 +54,9 @@ import static org.junit.Assert.assertTrue;
 )
 public class LdapCacheTest extends AbstractLdapTestUnit {
 
-    private static boolean portUpdated;
-
     @Before
     public void updatePort() throws Exception {
-        if (!portUpdated) {
-            String basedir = System.getProperty("basedir");
-            if (basedir == null) {
-                basedir = new File(".").getCanonicalPath();
-            }
-
-            // Read in ldap.properties and substitute in the correct port
-            File f = new File(basedir + "/src/test/resources/org/apache/karaf/jaas/modules/ldap/ldap.properties");
-
-            FileInputStream inputStream = new FileInputStream(f);
-            String content = IOUtils.toString(inputStream, "UTF-8");
-            inputStream.close();
-            content = content.replaceAll("portno", "" + getLdapServer().getPort());
-
-            File f2 = new File(basedir + "/target/test-classes/org/apache/karaf/jaas/modules/ldap/ldap.properties");
-            FileOutputStream outputStream = new FileOutputStream(f2);
-            IOUtils.write(content, outputStream, "UTF-8");
-            outputStream.close();
-            portUpdated = true;
-        }
+        LdapPropsUpdater.updatePort("org/apache/karaf/jaas/modules/ldap/ldap.properties",
getLdapServer().getPort());
     }
 
     @After

http://git-wip-us.apache.org/repos/asf/karaf/blob/ecf6a8dc/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/ldap/LdapCaseInsensitiveDNTest.java
----------------------------------------------------------------------
diff --git a/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/ldap/LdapCaseInsensitiveDNTest.java
b/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/ldap/LdapCaseInsensitiveDNTest.java
index e4d2035..bcf460d 100644
--- a/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/ldap/LdapCaseInsensitiveDNTest.java
+++ b/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/ldap/LdapCaseInsensitiveDNTest.java
@@ -19,20 +19,17 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.security.Principal;
 
 import javax.security.auth.Subject;
 
-import org.apache.commons.io.IOUtils;
-import org.apache.directory.server.core.integ.FrameworkRunner;
 import org.apache.directory.server.annotations.CreateLdapServer;
 import org.apache.directory.server.annotations.CreateTransport;
 import org.apache.directory.server.core.annotations.ApplyLdifFiles;
 import org.apache.directory.server.core.annotations.CreateDS;
 import org.apache.directory.server.core.annotations.CreatePartition;
+import org.apache.directory.server.core.integ.FrameworkRunner;
 import org.apache.felix.utils.properties.Properties;
 import org.apache.karaf.jaas.boot.principal.RolePrincipal;
 import org.apache.karaf.jaas.boot.principal.UserPrincipal;
@@ -50,31 +47,10 @@ import org.junit.runner.RunWith;
 )
 public class LdapCaseInsensitiveDNTest extends LdapLoginModuleTest {
     
-    private static boolean portUpdated;
-    
     @Before
     @Override
     public void updatePort() throws Exception {
-        if (!portUpdated) {
-            String basedir = System.getProperty("basedir");
-            if (basedir == null) {
-                basedir = new File(".").getCanonicalPath();
-            }
-
-            // Read in ldap.properties and substitute in the correct port
-            File f = new File(basedir + "/src/test/resources/org/apache/karaf/jaas/modules/ldap/ldapCaseInsensitiveDN.properties");
-
-            FileInputStream inputStream = new FileInputStream(f);
-            String content = IOUtils.toString(inputStream, "UTF-8");
-            inputStream.close();
-            content = content.replaceAll("portno", "" + getLdapServer().getPort());
-
-            File f2 = new File(basedir + "/target/test-classes/org/apache/karaf/jaas/modules/ldap/ldapCaseInsensitiveDN.properties");
-            FileOutputStream outputStream = new FileOutputStream(f2);
-            IOUtils.write(content, outputStream, "UTF-8");
-            outputStream.close();
-            portUpdated = true;
-        }
+        LdapPropsUpdater.updatePort("org/apache/karaf/jaas/modules/ldap/ldapCaseInsensitiveDN.properties",
getLdapServer().getPort());
     }
     
     @Test

http://git-wip-us.apache.org/repos/asf/karaf/blob/ecf6a8dc/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/ldap/LdapLoginModuleTest.java
----------------------------------------------------------------------
diff --git a/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/ldap/LdapLoginModuleTest.java
b/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/ldap/LdapLoginModuleTest.java
index 186bdb2..140d5df 100644
--- a/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/ldap/LdapLoginModuleTest.java
+++ b/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/ldap/LdapLoginModuleTest.java
@@ -17,7 +17,6 @@ package org.apache.karaf.jaas.modules.ldap;
 
 import org.apache.directory.server.core.integ.AbstractLdapTestUnit;
 import org.apache.directory.server.core.integ.FrameworkRunner;
-import org.apache.commons.io.IOUtils;
 import org.apache.directory.server.annotations.CreateLdapServer;
 import org.apache.directory.server.annotations.CreateTransport;
 import org.apache.directory.server.core.annotations.ApplyLdifFiles;
@@ -37,9 +36,6 @@ import javax.security.auth.Subject;
 import javax.security.auth.login.LoginException;
 
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.security.Principal;
 import java.util.ArrayList;
@@ -59,37 +55,12 @@ import static org.junit.Assert.fail;
         "org/apache/karaf/jaas/modules/ldap/example.com.ldif"
 )
 public class LdapLoginModuleTest extends AbstractLdapTestUnit {
-    
-    private static final String PROPS_PATH = "org/apache/karaf/jaas/modules/ldap/ldap.properties";
-    private static boolean portUpdated;
 
     @Before
     public void updatePort() throws Exception {
-        if (!portUpdated) {
-            String basedir = System.getProperty("basedir");
-            if (basedir == null) {
-                basedir = new File(".").getCanonicalPath();
-            }
-
-            // Read in ldap.properties and substitute in the correct port
-            String content = readProperties(basedir + "/src/test/resources/" + PROPS_PATH);
-            content = content.replaceAll("portno", "" + getLdapServer().getPort());
-            writeProperties(basedir + "/target/test-classes/" + PROPS_PATH, content);
-            portUpdated = true;
-        }
-    }
-
-    private String readProperties(String path) throws FileNotFoundException, IOException
{
-        try (FileInputStream inputStream = new FileInputStream(new File(path))) {;
-            return IOUtils.toString(inputStream, "UTF-8");
-        }
+        LdapPropsUpdater.updatePort("org/apache/karaf/jaas/modules/ldap/ldap.properties",
getLdapServer().getPort());
     }
 
-    private void writeProperties(String path, String content) throws FileNotFoundException,
IOException {
-        try (FileOutputStream outputStream = new FileOutputStream(new File(path))) {
-            IOUtils.write(content, outputStream, "UTF-8");
-        }
-    }
             
     @After
     public void tearDown() {

http://git-wip-us.apache.org/repos/asf/karaf/blob/ecf6a8dc/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/ldap/LdapLoginModuleWithEscapesTest.java
----------------------------------------------------------------------
diff --git a/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/ldap/LdapLoginModuleWithEscapesTest.java
b/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/ldap/LdapLoginModuleWithEscapesTest.java
index 9dc2272..c05a39a 100644
--- a/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/ldap/LdapLoginModuleWithEscapesTest.java
+++ b/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/ldap/LdapLoginModuleWithEscapesTest.java
@@ -15,18 +15,12 @@
  */
 package org.apache.karaf.jaas.modules.ldap;
 
-import org.apache.directory.server.core.integ.FrameworkRunner;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-
-import org.apache.commons.io.IOUtils;
 import org.apache.directory.server.annotations.CreateLdapServer;
 import org.apache.directory.server.annotations.CreateTransport;
 import org.apache.directory.server.core.annotations.ApplyLdifFiles;
 import org.apache.directory.server.core.annotations.CreateDS;
 import org.apache.directory.server.core.annotations.CreatePartition;
+import org.apache.directory.server.core.integ.FrameworkRunner;
 import org.junit.Before;
 import org.junit.runner.RunWith;
 
@@ -39,31 +33,9 @@ import org.junit.runner.RunWith;
 )
 public class LdapLoginModuleWithEscapesTest extends LdapLoginModuleTest {
     
-    private static boolean portUpdated;
-
     @Before
     @Override
     public void updatePort() throws Exception {
-        if (!portUpdated) {
-            String basedir = System.getProperty("basedir");
-            if (basedir == null) {
-                basedir = new File(".").getCanonicalPath();
-            }
-
-            // Read in ldap.properties and substitute in the correct port
-            File f = new File(basedir + "/src/test/resources/org/apache/karaf/jaas/modules/ldap/ldap.properties");
-
-            FileInputStream inputStream = new FileInputStream(f);
-            String content = IOUtils.toString(inputStream, "UTF-8");
-            inputStream.close();
-            content = content.replaceAll("portno", "" + getLdapServer().getPort());
-
-            File f2 = new File(basedir + "/target/test-classes/org/apache/karaf/jaas/modules/ldap/ldap.properties");
-            FileOutputStream outputStream = new FileOutputStream(f2);
-            IOUtils.write(content, outputStream, "UTF-8");
-            outputStream.close();
-            portUpdated = true;
-        }
+        LdapPropsUpdater.updatePort("org/apache/karaf/jaas/modules/ldap/ldap.properties",
getLdapServer().getPort());
     }
 }
-            
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/karaf/blob/ecf6a8dc/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/ldap/LdapPropsUpdater.java
----------------------------------------------------------------------
diff --git a/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/ldap/LdapPropsUpdater.java
b/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/ldap/LdapPropsUpdater.java
new file mode 100644
index 0000000..54c4a90
--- /dev/null
+++ b/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/ldap/LdapPropsUpdater.java
@@ -0,0 +1,54 @@
+/*
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *  under the License.
+ */
+package org.apache.karaf.jaas.modules.ldap;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import org.apache.commons.io.IOUtils;
+
+public class LdapPropsUpdater {
+
+    private LdapPropsUpdater() {
+    }
+
+    public static void updatePort(String propsPath, int port) throws IOException {
+        String basedir = System.getProperty("basedir");
+        if (basedir == null) {
+            basedir = new File(".").getCanonicalPath();
+        }
+
+        // Read in ldap.properties and substitute in the correct port
+        String content = readProperties(basedir + "/src/test/resources/" + propsPath);
+        content = content.replaceAll("portno", "" + port);
+        writeProperties(basedir + "/target/test-classes/" + propsPath, content);
+    }
+    
+    private static String readProperties(String path) throws FileNotFoundException, IOException
{
+        try (FileInputStream inputStream = new FileInputStream(new File(path))) {;
+            return IOUtils.toString(inputStream, "UTF-8");
+        }
+    }
+
+    private static void writeProperties(String path, String content) throws FileNotFoundException,
IOException {
+        try (FileOutputStream outputStream = new FileOutputStream(new File(path))) {
+            IOUtils.write(content, outputStream, "UTF-8");
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/karaf/blob/ecf6a8dc/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/ldap/LdapSpecialCharsInPasswordTest.java
----------------------------------------------------------------------
diff --git a/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/ldap/LdapSpecialCharsInPasswordTest.java
b/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/ldap/LdapSpecialCharsInPasswordTest.java
index 7f5a90a..f188cc2 100644
--- a/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/ldap/LdapSpecialCharsInPasswordTest.java
+++ b/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/ldap/LdapSpecialCharsInPasswordTest.java
@@ -16,11 +16,8 @@
 package org.apache.karaf.jaas.modules.ldap;
 
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.IOException;
 
-import org.apache.commons.io.IOUtils;
 import org.apache.directory.api.ldap.model.constants.SchemaConstants;
 import org.apache.directory.api.ldap.model.message.ModifyRequest;
 import org.apache.directory.api.ldap.model.message.ModifyRequestImpl;
@@ -47,32 +44,12 @@ import org.junit.runner.RunWith;
 )
 public class LdapSpecialCharsInPasswordTest extends LdapLoginModuleTest {
     
-    private static boolean portUpdated;
     private static final String NEW_CONNECTION_PASSWORD = "#a&b{>c=<12~d%";
     
     @Before
     @Override
     public void updatePort() throws Exception {
-        if (!portUpdated) {
-            String basedir = System.getProperty("basedir");
-            if (basedir == null) {
-                basedir = new File(".").getCanonicalPath();
-            }
-
-            // Read in ldap.properties and substitute in the correct port
-            File f = new File(basedir + "/src/test/resources/org/apache/karaf/jaas/modules/ldap/ldap_special_char_in_password.properties");
-
-            FileInputStream inputStream = new FileInputStream(f);
-            String content = IOUtils.toString(inputStream, "UTF-8");
-            inputStream.close();
-            content = content.replaceAll("portno", "" + getLdapServer().getPort());
-
-            File f2 = new File(basedir + "/target/test-classes/org/apache/karaf/jaas/modules/ldap/ldap_special_char_in_password.properties");
-            FileOutputStream outputStream = new FileOutputStream(f2);
-            IOUtils.write(content, outputStream, "UTF-8");
-            outputStream.close();
-            portUpdated = true;
-        }
+        LdapPropsUpdater.updatePort("org/apache/karaf/jaas/modules/ldap/ldap_special_char_in_password.properties",
getLdapServer().getPort());
     }
 
     protected Properties ldapLoginModuleOptions() throws IOException {
@@ -101,4 +78,3 @@ public class LdapSpecialCharsInPasswordTest extends LdapLoginModuleTest
{
         connection.close();
     }
 }
-            
\ No newline at end of file


Mime
View raw message