Repository: nifi
Updated Branches:
  refs/heads/master 96a766464 -> bc50329d5


NIFI-2688 Fixed regex pattern for European and Australian time zones in 
serialized nifi.properties.

This closes #974.


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

Branch: refs/heads/master
Commit: bc50329d5e3df2ce5bb7b9d3a1f8d4413ee24da0
Parents: 96a7664
Author: Andy LoPresto <[email protected]>
Authored: Tue Aug 30 20:14:34 2016 -0700
Committer: Andy LoPresto <[email protected]>
Committed: Wed Aug 31 15:21:04 2016 -0700

----------------------------------------------------------------------
 .../properties/ConfigEncryptionToolTest.groovy  | 54 ++++++++++++++++----
 1 file changed, 44 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/bc50329d/nifi-toolkit/nifi-toolkit-encrypt-config/src/test/groovy/org/apache/nifi/properties/ConfigEncryptionToolTest.groovy
----------------------------------------------------------------------
diff --git 
a/nifi-toolkit/nifi-toolkit-encrypt-config/src/test/groovy/org/apache/nifi/properties/ConfigEncryptionToolTest.groovy
 
b/nifi-toolkit/nifi-toolkit-encrypt-config/src/test/groovy/org/apache/nifi/properties/ConfigEncryptionToolTest.groovy
index 3458703..f471e5f 100644
--- 
a/nifi-toolkit/nifi-toolkit-encrypt-config/src/test/groovy/org/apache/nifi/properties/ConfigEncryptionToolTest.groovy
+++ 
b/nifi-toolkit/nifi-toolkit-encrypt-config/src/test/groovy/org/apache/nifi/properties/ConfigEncryptionToolTest.groovy
@@ -119,14 +119,24 @@ class ConfigEncryptionToolTest extends GroovyTestCase {
      */
     private static Set getFilePermissions(File file) {
         if (SystemUtils.IS_OS_WINDOWS) {
-           return [file.canRead() ? "OWNER_READ" : "",
-            file.canWrite() ? "OWNER_WRITE" : "",
-            file.canExecute() ? "OWNER_EXECUTE" : ""].findAll { it } as Set
+            return [file.canRead() ? "OWNER_READ" : "",
+                    file.canWrite() ? "OWNER_WRITE" : "",
+                    file.canExecute() ? "OWNER_EXECUTE" : ""].findAll { it } 
as Set
         } else {
             return Files.getPosixFilePermissions(file?.toPath())
         }
     }
 
+    private static boolean isValidDate(String formattedDate) {
+        // The serialization could have occurred > 1 second ago, causing a 
rolling date/time mismatch, so use regex
+        // Format -- #Fri Aug 19 16:51:16 PDT 2016
+        // Alternate format -- #Fri Aug 19 16:51:16 GMT-05:00 2016
+        // \u0024 == '$' to avoid escaping
+        String datePattern = /^#\w{3} \w{3} \d{2} \d{2}:\d{2}:\d{2} 
\w{2,5}([\-+]\d{2}:\d{2})? \d{4}\u0024/
+
+        formattedDate =~ datePattern
+    }
+
     @Test
     void testShouldPrintHelpMessage() {
         // Arrange
@@ -967,15 +977,8 @@ class ConfigEncryptionToolTest extends GroovyTestCase {
 
         // Assert
 
-        // The serialization could have occurred > 1 second ago, causing a 
rolling date/time mismatch, so use regex
-        // Format -- #Fri Aug 19 16:51:16 PDT 2016
-        // Alternate format -- #Fri Aug 19 16:51:16 GMT-05:00 2016
-        // \u0024 == '$' to avoid escaping
-        String datePattern = /^#\w{3} \w{3} \d{2} \d{2}:\d{2}:\d{2} 
\w{3}([\-+]\d{2}:\d{2})? \d{4}\u0024/
-
         // One extra line for the date
         assert lines.size() == properties.size() + 1
-        assert lines.first() =~ datePattern
 
         rawProperties.keySet().every { String key ->
             assert 
lines.contains("${key}=${properties.getProperty(key)}".toString())
@@ -983,6 +986,37 @@ class ConfigEncryptionToolTest extends GroovyTestCase {
     }
 
     @Test
+    void testFirstLineOfSerializedPropertiesShouldBeLocalizedDateTime() {
+        // Arrange
+        Assume.assumeTrue("Test only runs on *nix because Windows line endings 
are different", !SystemUtils.IS_OS_WINDOWS)
+
+        Properties rawProperties = [key: "value", key2: "value2"] as Properties
+        NiFiProperties properties = new StandardNiFiProperties(rawProperties)
+        logger.info("Loaded ${properties.size()} properties")
+
+        def currentTimeZone = TimeZone.default
+        logger.info("Current time zone: ${currentTimeZone.displayName} 
(${currentTimeZone.ID})")
+
+        // Configure different time zones
+        def timeZones = TimeZone.availableIDs as List<String>
+
+        // Act
+        timeZones.each { String tz ->
+            TimeZone.setDefault(TimeZone.getTimeZone(tz))
+
+            String formattedDate = 
ConfigEncryptionTool.serializeNiFiProperties(properties).first()
+            logger.info("First line date: ${formattedDate}")
+
+            // Assert
+            assert isValidDate(formattedDate)
+        }
+
+        // Restore current time zone
+        TimeZone.setDefault(currentTimeZone)
+        logger.info("Reset current time zone to ${currentTimeZone.displayName} 
(${currentTimeZone.ID})")
+    }
+
+    @Test
     void testShouldSerializeNiFiPropertiesAndPreserveFormat() {
         // Arrange
         String originalNiFiPropertiesPath = 
"src/test/resources/nifi_with_few_sensitive_properties_unprotected.properties"

Reply via email to