You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ek...@apache.org on 2004/07/22 02:28:25 UTC

svn commit: rev 23129 - in incubator/beehive/trunk/netui/test/src/testRecorder: jsp org/apache/beehive/netui/tools/testrecorder/server/state org/apache/beehive/netui/tools/testrecorder/shared org/apache/beehive/netui/tools/testrecorder/shared/util

Author: ekoneil
Date: Wed Jul 21 17:28:24 2004
New Revision: 23129

Added:
   incubator/beehive/trunk/netui/test/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/util/DateHelper.java   (contents, props changed)
Modified:
   incubator/beehive/trunk/netui/test/src/testRecorder/jsp/sessionInfo.jsp
   incubator/beehive/trunk/netui/test/src/testRecorder/jsp/status.inc
   incubator/beehive/trunk/netui/test/src/testRecorder/jsp/testInfo.jsp
   incubator/beehive/trunk/netui/test/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/server/state/PlaybackSessionImpl.java
   incubator/beehive/trunk/netui/test/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/server/state/RecordSessionImpl.java
   incubator/beehive/trunk/netui/test/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/server/state/Session.java
   incubator/beehive/trunk/netui/test/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/server/state/SessionImpl.java
   incubator/beehive/trunk/netui/test/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/SessionBean.java
Log:
Update the test recorder to standardize on US dates.  This specifies the Locale used when creating and parsing dates for display in JSP pages and when reading / writing record and playback XML files.

Hopefully this starts to address the issues we've been having when running the DRTs on machines with non-US locales.  

If you encounter additional problems, let me know.

BB: self
DRT: NetUI pass
CR: Daryl



Modified: incubator/beehive/trunk/netui/test/src/testRecorder/jsp/sessionInfo.jsp
==============================================================================
--- incubator/beehive/trunk/netui/test/src/testRecorder/jsp/sessionInfo.jsp	(original)
+++ incubator/beehive/trunk/netui/test/src/testRecorder/jsp/sessionInfo.jsp	Wed Jul 21 17:28:24 2004
@@ -3,15 +3,17 @@
                  org.apache.beehive.netui.tools.testrecorder.shared.config.WebappConfig,
                  org.apache.beehive.netui.tools.testrecorder.shared.config.Category,
                  org.apache.beehive.netui.tools.testrecorder.shared.config.Categories,
-                 java.util.List,
                  org.apache.beehive.netui.tools.testrecorder.shared.Constants,
+                 org.apache.beehive.netui.tools.testrecorder.server.state.Session,
                  java.io.File,
                  java.text.SimpleDateFormat,
-                 org.apache.beehive.netui.tools.testrecorder.server.state.Session,
                  java.util.Calendar,
-                 java.util.Date"%>
+                 java.util.Date,
+                 java.util.List,
+                 java.util.Locale"%>
 <%!
-    private static final SimpleDateFormat dateFormat = new SimpleDateFormat( "dd MMM, hh:mm:ss aa" );
+    // todo: need to clean this up to handle date formats correctly in one place
+    private static final SimpleDateFormat dateFormat = new SimpleDateFormat( "dd MMM, hh:mm:ss aa", Locale.US );
 %>
 <%
     Calendar calendar = Calendar.getInstance();
@@ -36,7 +38,7 @@
         catHref = new String( "testInfo.jsp?category=" + category.getName() );
         reportFile = new File( category.getReportDirPath(), "/html/junit-noframes.html" );
         if ( reportFile.exists() ) {
-            calendar.setTimeInMillis(  reportFile.lastModified());
+            calendar.setTimeInMillis(reportFile.lastModified());
             date = calendar.getTime();
             resultsHref = new String( "<a href=" + webapp.getServletURI() + "?" + Constants.MODE + "=" + Constants.ADMIN +
                 "&" + Constants.CMD + "=" + Constants.DISPLAY_REPORT + "&category=" + category.getName() + ">results (" +

Modified: incubator/beehive/trunk/netui/test/src/testRecorder/jsp/status.inc
==============================================================================
--- incubator/beehive/trunk/netui/test/src/testRecorder/jsp/status.inc	(original)
+++ incubator/beehive/trunk/netui/test/src/testRecorder/jsp/status.inc	Wed Jul 21 17:28:24 2004
@@ -1,15 +1,13 @@
 
-<%@ page import="org.apache.beehive.netui.tools.testrecorder.server.state.Session" %>
+<%@ page import="org.apache.beehive.netui.tools.testrecorder.server.state.Session,
+                 org.apache.beehive.netui.tools.testrecorder.shared.util.DateHelper" %>
 <%@ page import="org.apache.beehive.netui.tools.testrecorder.server.TestRecorderFilter" %>
 <%@ page import="org.apache.beehive.netui.tools.testrecorder.server.state.RecordSession" %>
 <%@ page import="org.apache.beehive.netui.tools.testrecorder.server.state.RecordSession" %>
-<%@ page import="java.text.SimpleDateFormat" %>
 <%@ page import="java.text.MessageFormat" %>
 <%@ page import="java.util.*" %>
 
 <%!
-    private static final SimpleDateFormat dateFormat = new SimpleDateFormat( Session.DATE_FORMAT_STRING );
-
     private static final String property =
         "<strong style=\"color: blue\">{0}</strong>";
     private static final String value =
@@ -41,7 +39,7 @@
 
 <%
     TestRecorderFilter filter = TestRecorderFilter.instance();
-    String dateString = dateFormat.format( new Date() );
+    String dateString = DateHelper.formatToString(new Date());
     boolean testMode = false;
     RecordSession recordingSession = null;
     String recSessionInfo = null;

Modified: incubator/beehive/trunk/netui/test/src/testRecorder/jsp/testInfo.jsp
==============================================================================
--- incubator/beehive/trunk/netui/test/src/testRecorder/jsp/testInfo.jsp	(original)
+++ incubator/beehive/trunk/netui/test/src/testRecorder/jsp/testInfo.jsp	Wed Jul 21 17:28:24 2004
@@ -3,16 +3,13 @@
                  org.apache.beehive.netui.tools.testrecorder.shared.config.WebappConfig,
                  org.apache.beehive.netui.tools.testrecorder.shared.config.Category,
                  org.apache.beehive.netui.tools.testrecorder.shared.config.Categories,
-                 java.util.List,
                  org.apache.beehive.netui.tools.testrecorder.shared.config.TestDefinition,
                  org.apache.beehive.netui.tools.testrecorder.shared.Constants,
+                 org.apache.beehive.netui.tools.testrecorder.shared.util.DateHelper,
                  java.io.File,
-                 java.text.SimpleDateFormat,
                  java.util.Calendar,
-                 java.util.Date"%>
-<%!
-    private static final SimpleDateFormat dateFormat = new SimpleDateFormat( "dd MMM, hh:mm:ss aa" );
-%>
+                 java.util.Date,
+                 java.util.List"%>
 <%
     Calendar calendar = Calendar.getInstance();
     Date date = null;
@@ -75,7 +72,7 @@
             date = calendar.getTime();
             playbackHref = new String( "<a href=" + webapp.getServletURI() + "?" + Constants.MODE + "=" + Constants.ADMIN +
                 "&" + Constants.CMD + "=" + Constants.DISPLAY_PLAYBACK + "&test=" + test.getName() + ">" + test.getName() +
-                " Playback File (" + dateFormat.format( date ) + ")</a>");
+                " Playback File (" + DateHelper.formatToReadableString(date) + ")</a>");
         }
         else {
             playbackHref =  "&nbsp;";

Modified: incubator/beehive/trunk/netui/test/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/server/state/PlaybackSessionImpl.java
==============================================================================
--- incubator/beehive/trunk/netui/test/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/server/state/PlaybackSessionImpl.java	(original)
+++ incubator/beehive/trunk/netui/test/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/server/state/PlaybackSessionImpl.java	Wed Jul 21 17:28:24 2004
@@ -20,7 +20,6 @@
 package org.apache.beehive.netui.tools.testrecorder.server.state;
 
 import java.io.File;
-import java.util.Calendar;
 import java.rmi.server.UID;
 import java.lang.StringBuffer;
 
@@ -29,6 +28,7 @@
 import org.apache.beehive.netui.tools.testrecorder.shared.PlaybackSessionBean;
 import org.apache.beehive.netui.tools.testrecorder.shared.xmlbeans.XMLHelper;
 import org.apache.beehive.netui.tools.testrecorder.shared.TestResults;
+import org.apache.beehive.netui.tools.testrecorder.shared.util.DateHelper;
 import org.apache.beehive.netui.tools.testrecorder.server.DiffEngineFactory;
 import org.apache.beehive.netui.tools.testrecorder.server.FilterData;
 import org.apache.beehive.netui.tools.testrecorder.server.DiffEngine;
@@ -233,7 +233,7 @@
             rtnVal = false;
         }
         else {
-            setStartDate( Calendar.getInstance() );
+            setStartDate( DateHelper.getCalendarInstance() );
             setSessionState( PLAYBACK );
             rtnVal = true;
         }
@@ -248,7 +248,7 @@
         }
         SessionFailedException caught = null;
         try {
-            setEndDate( Calendar.getInstance() );
+            setEndDate( DateHelper.getCalendarInstance() );
             XMLHelper.createPlaybackFile( getPlaybackFile(), playbackSessionBean );
         }
         catch ( Exception e ) {

Modified: incubator/beehive/trunk/netui/test/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/server/state/RecordSessionImpl.java
==============================================================================
--- incubator/beehive/trunk/netui/test/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/server/state/RecordSessionImpl.java	(original)
+++ incubator/beehive/trunk/netui/test/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/server/state/RecordSessionImpl.java	Wed Jul 21 17:28:24 2004
@@ -20,12 +20,12 @@
 package org.apache.beehive.netui.tools.testrecorder.server.state;
 
 import java.io.File;
-import java.util.Calendar;
 
 import org.apache.beehive.netui.tools.testrecorder.shared.RequestData;
 import org.apache.beehive.netui.tools.testrecorder.shared.ResponseData;
 import org.apache.beehive.netui.tools.testrecorder.shared.Logger;
 import org.apache.beehive.netui.tools.testrecorder.shared.RecordSessionBean;
+import org.apache.beehive.netui.tools.testrecorder.shared.util.DateHelper;
 import org.apache.beehive.netui.tools.testrecorder.shared.xmlbeans.XMLHelper;
 
 
@@ -97,7 +97,7 @@
             rtnVal = false;
         }
         else {
-            setStartDate( Calendar.getInstance() );
+            setStartDate( DateHelper.getCalendarInstance() );
             setSessionState( RECORD );
             rtnVal = true;
         }
@@ -175,7 +175,7 @@
 
     protected synchronized void closeSessionInternal() throws SessionFailedException {
         try {
-            setEndDate( Calendar.getInstance() );
+            setEndDate( DateHelper.getCalendarInstance() );
             XMLHelper.createRecordFile( getRecordFile(), sessionBean );
         }
         catch ( Exception e ) {

Modified: incubator/beehive/trunk/netui/test/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/server/state/Session.java
==============================================================================
--- incubator/beehive/trunk/netui/test/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/server/state/Session.java	(original)
+++ incubator/beehive/trunk/netui/test/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/server/state/Session.java	Wed Jul 21 17:28:24 2004
@@ -27,8 +27,6 @@
  */
 public interface Session {
 
-    final String DATE_FORMAT_STRING = "dd MMM yyyy, hh:mm:ss.SSS aa zzz";
-
     /**
      * returns true if session started, false if the session is already started.  An excepion is thrown
      * if an error occurs

Modified: incubator/beehive/trunk/netui/test/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/server/state/SessionImpl.java
==============================================================================
--- incubator/beehive/trunk/netui/test/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/server/state/SessionImpl.java	(original)
+++ incubator/beehive/trunk/netui/test/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/server/state/SessionImpl.java	Wed Jul 21 17:28:24 2004
@@ -37,7 +37,7 @@
 
     // milliseconds
     public static final long LOOP_TIMEOUT = 250;
-    // milliseconds ... 1 minute to you and I
+    // milliseconds ... 1 minute to you and me
     public static final int HARD_TIMEOUT = 60 * 1 * 1000;
 
     public static final int BEGIN = 0;
@@ -232,12 +232,12 @@
         }
     }
 
-    protected Calendar setStartDate( Calendar startDate ) {
-        return sessionBean.setStartDate( startDate );
+    protected void setStartDate( Calendar startDate ) {
+        sessionBean.setStartDate( startDate );
     }
 
-    protected Calendar setEndDate( Calendar endDate ) {
-        return sessionBean.setEndDate( endDate );
+    protected void setEndDate( Calendar endDate ) {
+        sessionBean.setEndDate( endDate );
     }
 
     protected void setTestUser( String testUser ) {

Modified: incubator/beehive/trunk/netui/test/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/SessionBean.java
==============================================================================
--- incubator/beehive/trunk/netui/test/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/SessionBean.java	(original)
+++ incubator/beehive/trunk/netui/test/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/SessionBean.java	Wed Jul 21 17:28:24 2004
@@ -19,10 +19,9 @@
 
 package org.apache.beehive.netui.tools.testrecorder.shared;
 
-import org.apache.beehive.netui.tools.testrecorder.server.state.Session;
+import org.apache.beehive.netui.tools.testrecorder.shared.util.DateHelper;
 
 import java.util.Calendar;
-import java.text.SimpleDateFormat;
 import java.text.ParseException;
 
 /**
@@ -32,8 +31,6 @@
  */
 public class SessionBean {
 
-    private static final SimpleDateFormat xmlDateFormat = new SimpleDateFormat( Session.DATE_FORMAT_STRING );
-
     protected String sessionName;
     private String tester;
     private Calendar startDate;
@@ -56,44 +53,38 @@
         return startDate;
     }
 
-    public Calendar setStartDate( Calendar startDate ) {
-        return this.startDate = startDate;
+    public void setStartDate( Calendar startDate ) {
+        this.startDate = startDate;
     }
 
-    public Calendar setStartDate( String date ) throws ParseException {
-        Calendar calendar = Calendar.getInstance();
-        calendar.setTime( xmlDateFormat.parse( date ) );
-        startDate = calendar;
-        return startDate;
+    public void setStartDate( String date ) throws ParseException {
+        startDate = DateHelper.getCalendarInstance(date);
     }
 
     public String getStartDateString() {
         if ( getStartDate() == null ) {
             return null;
         }
-        return xmlDateFormat.format( getStartDate().getTime() );
+        return DateHelper.formatToString(getStartDate());
     }
 
     protected Calendar getEndDate() {
         return endDate;
     }
 
-    public Calendar setEndDate( Calendar endDate ) {
-        return this.endDate = endDate;
+    public void setEndDate( Calendar endDate ) {
+        this.endDate = endDate;
     }
 
-    public Calendar setEndDate( String date ) throws ParseException {
-        Calendar calendar = Calendar.getInstance();
-        calendar.setTime( xmlDateFormat.parse( date ) );
-        endDate = calendar;
-        return endDate;
+    public void setEndDate( String date ) throws ParseException {
+        endDate = DateHelper.getCalendarInstance(date);
     }
 
     public String getEndDateString() {
         if ( getEndDate() == null ) {
             return null;
         }
-        return xmlDateFormat.format( getEndDate().getTime() );
+        else return DateHelper.formatToString(getEndDate());
     }
 
     public String getDescription() {

Added: incubator/beehive/trunk/netui/test/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/util/DateHelper.java
==============================================================================
--- (empty file)
+++ incubator/beehive/trunk/netui/test/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/util/DateHelper.java	Wed Jul 21 17:28:24 2004
@@ -0,0 +1,134 @@
+/*
+ * B E A   S Y S T E M S
+ * Copyright 2002-2004  BEA Systems, Inc.
+ *
+ * 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.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.netui.tools.testrecorder.shared.util;
+
+import org.apache.beehive.netui.tools.testrecorder.server.state.Session;
+
+import java.text.SimpleDateFormat;
+import java.text.ParseException;
+
+import java.util.Calendar;
+import java.util.Locale;
+import java.util.Date;
+
+/**
+ * Utility to help handle Date/Calendar formatting in the test recorder.
+ */
+public class DateHelper
+{
+    /**
+     * Default {@link java.util.Locale} used to format dates that the test recorder uses.
+     * This defaults to the <code>US</code> Locale for the time being so that dates
+     * are handled in an internally consistent way.
+     */
+    private static final Locale DEFAULT_LOCALE = Locale.US;
+
+    /**
+     * Format for how dates are parsed and written.
+     */
+    private static final String DATE_FORMAT_STRING = "dd MMM yyyy, hh:mm:ss.SSS aa zzz";
+
+    /**
+     * Format for how dates are parsed and written in the JSP UI for the test recorder.
+     *
+     * These are just more readable than those that are used for the test record XML files.
+     */
+    private static final String READABLE_DATE_FORMAT_STRING = "dd MMM, hh:mm:ss aa";
+
+    /**
+     * {@link java.text.SimpleDateFormat} used to parse Strings to {@link java.util.Date} objects.
+     */
+    private static final SimpleDateFormat XML_DATE_FORMAT = new SimpleDateFormat(DATE_FORMAT_STRING, DEFAULT_LOCALE);
+
+    /**
+     * {@link java.text.SimpleDateFormat} used to parse Strings to {@link java.util.Date} objects.
+     */
+    private static final SimpleDateFormat READABLE_DATE_FORMAT = new SimpleDateFormat(READABLE_DATE_FORMAT_STRING, DEFAULT_LOCALE);
+
+
+    // Do not construct
+    private DateHelper() {}
+
+    /**
+     * Get a {@link java.util.Calendar} instance that represents <code>now</code>.
+     *
+     * @return said Calendar instance
+     */
+    public static final Calendar getCalendarInstance()
+    {
+        return Calendar.getInstance(DEFAULT_LOCALE);
+    }
+
+    /**
+     * Get a {@link java.util.Calendar} instance that represents the date parsed
+     * from the <code>dateString</code> parameter.
+     *
+     * @param dateString String date to parse
+     * @return the parsed Calendar instance
+     * @throws ParseException thrown when the dateString can't be parsed
+     */
+    public static final Calendar getCalendarInstance(String dateString)
+        throws ParseException
+    {
+        assert dateString != null;
+
+        Calendar calendar = Calendar.getInstance(DEFAULT_LOCALE);
+        calendar.setTime(XML_DATE_FORMAT.parse(dateString));
+
+        return calendar;
+    }
+
+    /**
+     * Format the given {@link java.util.Calendar} instance into a String
+     * for printing / display.
+     *
+     * @param calendar {@link java.util.Calendar} instance to format.
+     * @return the formatted String
+     */
+    public static final String formatToString(Calendar calendar)
+    {
+        assert calendar != null;
+        return XML_DATE_FORMAT.format(calendar.getTime());
+    }
+
+    /**
+     * Format the given {@link java.util.Date} instance into a String
+     * for use in a test's recorded XML file.
+     *
+     * @param date {@link java.util.Date} instance to format.
+     * @return the formatted String
+     */
+    public static final String formatToString(Date date)
+    {
+        assert date != null;
+        return XML_DATE_FORMAT.format(date);
+    }
+
+    /**
+     * Format the given {@link java.util.Date} into a String for display.
+     *
+     * @param date the {@link java.util.Date} to format
+     * @return the formatted String
+     */
+    public static final String formatToReadableString(Date date)
+    {
+        assert date != null;
+        return READABLE_DATE_FORMAT.format(date);
+    }
+}