[java-idp-integration-tests] 01/02: Do not add new properties when replacing property values

Tom Zeller tzeller at dragonacea.biz
Wed Aug 29 17:01:11 EDT 2018


This is an automated email from the git hooks/post-receive script.

tzeller pushed a commit to branch master
in repository java-idp-integration-tests.

View the commit online:
http://git.shibboleth.net/view/?p=java-idp-integration-tests.git;a=commit;h=79080f1733ea95b1c6739166a17f44b14f12b812

commit 79080f1733ea95b1c6739166a17f44b14f12b812
Author: Tom Zeller <tzeller at dragonacea.biz>
AuthorDate: Wed Aug 29 15:57:49 2018 -0500

    Do not add new properties when replacing property values
    
    Previous default behavior was to add a property if it did not already
    exist in the properties file.
---
 .../shibboleth/idp/test/BaseIntegrationTest.java   | 28 +++++++++++++++++-----
 1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/src/test/java/net/shibboleth/idp/test/BaseIntegrationTest.java b/src/test/java/net/shibboleth/idp/test/BaseIntegrationTest.java
index 83c95a4..d9a2012 100644
--- a/src/test/java/net/shibboleth/idp/test/BaseIntegrationTest.java
+++ b/src/test/java/net/shibboleth/idp/test/BaseIntegrationTest.java
@@ -880,7 +880,7 @@ public abstract class BaseIntegrationTest
      */
     public void replaceLDAPProperty(@Nonnull @NotEmpty final String key, @Nonnull @NotEmpty final String value)
             throws IOException {
-        replaceProperty(pathToLDAPProperties, key, value);
+        replaceProperty(pathToLDAPProperties, key, value, false);
     }
 
     /**
@@ -891,22 +891,38 @@ public abstract class BaseIntegrationTest
      * @param value property value
      * @throws IOException if an I/O error occurs
      */
-    public void replaceProperty(@Nonnull final Path pathToPropertyFile,
-            @Nonnull @NotEmpty final String key,
+    public void replaceProperty(@Nonnull final Path pathToPropertyFile, @Nonnull @NotEmpty final String key,
             @Nonnull @NotEmpty final String value) throws IOException {
+        replaceProperty(pathToPropertyFile, key, value, false);
+    }
+
+    /**
+     * Replace a property in a properties file.
+     * 
+     * @param pathToPropertyFile path to the property file
+     * @param key property key
+     * @param value property value
+     * @param addNewProperties add new properties as well as replace existing
+     * @throws IOException if an I/O error occurs
+     */
+    public void replaceProperty(@Nonnull final Path pathToPropertyFile, @Nonnull @NotEmpty final String key,
+            @Nonnull @NotEmpty final String value, final boolean addNewProperties) throws IOException {
         Constraint.isNotNull(pathToPropertyFile, "Path to property file cannot be null nor empty");
         Constraint.isNotNull(StringSupport.trimOrNull(key), "Replacement property key cannot be null nor empty");
         Constraint.isNotNull(StringSupport.trimOrNull(value), "Replacement property value cannot be null nor empty");
 
-        log.debug("Replacing property '{}' with '{}' in file '{}'", key, value, pathToPropertyFile);
+        log.debug("Replace property '{}' with '{}' in file '{}'", key, value, pathToPropertyFile);
 
         final FileSystemResource propertyResource =
                 new FileSystemResource(pathToPropertyFile.toAbsolutePath().toString());
 
         final PropertiesWithComments pwc = new PropertiesWithComments();
         pwc.load(propertyResource.getInputStream());
-        pwc.replaceProperty(key, value);
-        pwc.store(propertyResource.getOutputStream());
+        boolean wasPropertyReplaced = pwc.replaceProperty(key, value);
+        if (wasPropertyReplaced || addNewProperties) {
+            log.debug("Replacing property '{}' with '{}' in file '{}'", key, value, pathToPropertyFile);
+            pwc.store(propertyResource.getOutputStream());
+        }
     }
 
     /**

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list