7180362: RFE: Implement date cutover functionality for currency.properties file
Reviewed-by: naoto
diff --git a/test/java/util/Currency/PropertiesTest.java b/test/java/util/Currency/PropertiesTest.java
index e59ec7b..ab78ec0 100644
--- a/test/java/util/Currency/PropertiesTest.java
+++ b/test/java/util/Currency/PropertiesTest.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -22,11 +22,12 @@
  */
 
 import java.io.*;
+import java.text.*;
 import java.util.*;
 import java.util.regex.*;
 
 public class PropertiesTest {
-    public static void main(String[] s) {
+    public static void main(String[] s) throws Exception {
         for (int i = 0; i < s.length; i ++) {
             if ("-d".equals(s[i])) {
                 i++;
@@ -76,7 +77,7 @@
         pw.close();
     }
 
-    private static void compare(String beforeFile, String afterFile) {
+    private static void compare(String beforeFile, String afterFile) throws Exception {
         // load file contents
         Properties before = new Properties();
         Properties after = new Properties();
@@ -114,11 +115,23 @@
         // test each replacements
         keys = p.stringPropertyNames();
         Pattern propertiesPattern =
-            Pattern.compile("([A-Z]{3})\\s*,\\s*(\\d{3})\\s*,\\s*([0-3])");
+            Pattern.compile("([A-Z]{3})\\s*,\\s*(\\d{3})\\s*,\\s*" +
+                "([0-3])\\s*,?\\s*(\\d{4}-\\d{2}-\\d{2}T\\d{2}:" +
+                "\\d{2}:\\d{2})?");
         for (String key: keys) {
             String val = p.getProperty(key);
+            try {
+                if (countOccurrences(val, ',') == 3 && !isPastCutoverDate(val)) {
+                    System.out.println("Skipping since date is in future");
+                    continue; // skip since date in future (no effect)
+                }
+            } catch (ParseException pe) {
+                // swallow - currency class should not honour this value
+                continue;
+            }
             String afterVal = after.getProperty(key);
             System.out.printf("Testing key: %s, val: %s... ", key, val);
+            System.out.println("AfterVal is : " + afterVal);
 
             Matcher m = propertiesPattern.matcher(val.toUpperCase(Locale.ROOT));
             if (!m.find()) {
@@ -131,7 +144,6 @@
                 // ignore this
                 continue;
             }
-
             Matcher mAfter = propertiesPattern.matcher(afterVal);
             mAfter.find();
 
@@ -164,4 +176,29 @@
             throw new RuntimeException(sb.toString());
         }
     }
+
+    private static boolean isPastCutoverDate(String s)
+            throws IndexOutOfBoundsException, NullPointerException, ParseException {
+        String dateString = s.substring(s.lastIndexOf(',')+1, s.length()).trim();
+        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ROOT);
+        format.setTimeZone(TimeZone.getTimeZone("GMT"));
+        format.setLenient(false);
+
+        long time = format.parse(dateString).getTime();
+        if (System.currentTimeMillis() - time >= 0L) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    private static int countOccurrences(String value, char match) {
+        int count = 0;
+        for (char c : value.toCharArray()) {
+            if (c == match) {
+               ++count;
+            }
+        }
+        return count;
+    }
 }
diff --git a/test/java/util/Currency/PropertiesTest.sh b/test/java/util/Currency/PropertiesTest.sh
index 304d102..f016eed 100644
--- a/test/java/util/Currency/PropertiesTest.sh
+++ b/test/java/util/Currency/PropertiesTest.sh
@@ -1,7 +1,7 @@
 #!/bin/sh
 #
 # @test
-# @bug 6332666
+# @bug 6332666 7180362
 # @summary tests the capability of replacing the currency data with user
 #     specified currency properties file
 # @build PropertiesTest
diff --git a/test/java/util/Currency/currency.properties b/test/java/util/Currency/currency.properties
index f09e00f..ce3c7bb 100644
--- a/test/java/util/Currency/currency.properties
+++ b/test/java/util/Currency/currency.properties
@@ -2,9 +2,19 @@
 # Test data for replacing the currency data
 #
 JP=JPZ,123,2
-US=euR,978,2
+ES=ESD,877,2
+US=euR,978,2,2001-01-01T00:00:00
+CM=IED,111,2, 2004-01-01T00:70:00
+SB=EUR,111,2, 2099-01-01T00:00:00
 ZZ	=	ZZZ	,	999	,	3
+NO=EUR   ,978  ,2,  2099-01-01T00:00:00
 
 # invalid entries
 GB=123
 FR=zzzzz.123
+DE=2009-01-01T00:00:00,EUR,111,2
+IE=euR,111,2,#testcomment
+=euR,111,2, 2099-01-01-00-00-00
+FM=DED,194,2,eeee-01-01T00:00:00
+PE=EUR   ,978  ,2,  20399-01-01T00:00:00
+MX=SSS,493,2,2001-01-01-00-00-00