From 3c3ca54bfde39ba7df13bd7409b47580cfa0bd39 Mon Sep 17 00:00:00 2001
From: Chris Ridd <chris.ridd@forgerock.com>
Date: Tue, 07 Aug 2012 15:09:24 +0000
Subject: [PATCH] Fix OPENDJ-559 UTCTimeSyntax parses 32... as 1932

---
 opends/tests/unit-tests-testng/src/server/org/opends/server/schema/UTCTimeSyntaxTest.java |  107 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 107 insertions(+), 0 deletions(-)

diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/schema/UTCTimeSyntaxTest.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/schema/UTCTimeSyntaxTest.java
index aaf1f62..49532b8 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/schema/UTCTimeSyntaxTest.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/schema/UTCTimeSyntaxTest.java
@@ -23,12 +23,18 @@
  *
  *
  *      Copyright 2006-2008 Sun Microsystems, Inc.
+ *      Portions copyright 2012 ForgeRock AS
+ *
  */
 package org.opends.server.schema;
 
+import java.util.Calendar;
 import java.util.Date;
+import java.util.TimeZone;
+
 import org.opends.server.api.AttributeSyntax;
 import org.opends.server.types.AttributeValue;
+import org.opends.server.types.ByteString;
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
 
@@ -129,4 +135,105 @@
     // sure that the decoded value is within 1000 milliseconds.
     assertTrue(Math.abs(d.getTime() - decodedDate.getTime()) < 1000);
   }
+
+
+
+  /**
+   * Tests the {@code decodeUTCTimeValue} method decodes
+   * 50-99 into 1950-1999. See RFC 3280 4.1.2.5.1.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test()
+  public void testDecode50to99()
+         throws Exception
+  {
+    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
+
+    // values from 50 through 99 inclusive shall have 1900 added to it
+    for (int yy = 50; yy <= 99; yy++) {
+      String utcString = String.format("%02d0819120000Z", new Integer(yy));
+      Date decodedDate = UTCTimeSyntax.decodeUTCTimeValue(ByteString.valueOf(utcString));
+      cal.clear();
+      cal.setTime(decodedDate);
+      int year = cal.get(Calendar.YEAR);
+      assertEquals(year, yy + 1900);
+    }
+  }
+
+
+
+  /**
+   * Tests the {@code decodeUTCTimeValue} method decodes
+   * 00-49 into 2000-2049. See RFC 3280 4.1.2.5.1.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test()
+  public void testDecode00to49()
+         throws Exception
+  {
+    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
+
+    // values from 00 through 49 inclusive shall have 2000 added to it
+    for (int yy = 0; yy <= 49; yy++) {
+      String utcString = String.format("%02d0819120000Z", new Integer(yy));
+      Date decodedDate = UTCTimeSyntax.decodeUTCTimeValue(ByteString.valueOf(utcString));
+      cal.clear();
+      cal.setTime(decodedDate);
+      int year = cal.get(Calendar.YEAR);
+      assertEquals(year, yy + 2000);
+    }
+  }
+
+
+
+  /**
+   * Tests the {@code createUTCTimeValue} method converts
+   * 1950-1999 into 50-99. See RFC 3280 4.1.2.5.1.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test()
+  public void testCreate50to99()
+         throws Exception
+  {
+    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
+
+    // values from 50 through 99 inclusive shall have 1900 added to it
+    for (int yy = 50; yy <= 99; yy++) {
+      cal.clear();
+      cal.set(1900 + yy, 7, 19, 12, 0, 0); // months are 0..11
+      Date date = cal.getTime();
+      String createdString = UTCTimeSyntax.createUTCTimeValue(date).toString();
+      String expectedString = String.format("%02d0819120000Z", new Integer(yy));
+      assertEquals(expectedString, createdString);
+    }
+  }
+
+
+
+  /**
+   * Tests the {@code createUTCTimeValue} method converts
+   * 2000-2049 to 00-49. See RFC 3280 4.1.2.5.1.
+   *
+   * @throws  Exception  If an unexpected problem occurs.
+   */
+  @Test()
+  public void testCreate00to49()
+         throws Exception
+  {
+    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
+
+    // values from 00 through 49 inclusive shall have 2000 added to it
+    for (int yy = 0; yy <= 49; yy++) {
+      cal.clear();
+      cal.set(2000 + yy, 7, 19, 12, 0, 0); // months are 0..11
+      Date date = cal.getTime();
+      String createdString = UTCTimeSyntax.createUTCTimeValue(date).toString();
+      String expectedString = String.format("%02d0819120000Z", new Integer(yy));
+      assertEquals(expectedString, createdString);
+	}
+  }
 }
+

--
Gitblit v1.10.0