roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject svn commit: r417044 [2/3] - in /incubator/roller/branches/roller_3.0: ./ metadata/database/ src/org/apache/roller/business/ src/org/apache/roller/business/hibernate/ src/org/apache/roller/pojos/ src/org/apache/roller/ui/core/ src/org/apache/roller/ui/r...
Date Sun, 25 Jun 2006 19:33:53 GMT
Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/util/DateUtil.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/util/DateUtil.java?rev=417044&r1=417043&r2=417044&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/util/DateUtil.java (original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/util/DateUtil.java Sun Jun 25 12:33:50 2006
@@ -1 +1 @@
-/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  The ASF licenses this file to You
 * 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.  For additional information regarding
 * copyright in this work, please see the NOTICE file in the top level
 * directory of this distribution.
 */
package org.apache.roller.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
 import java.util.Locale;
import org.apache.commons.lang.StringUtils;

/**
 * General purpose date utilities.
 * @author Mark Saarinen
 * @author Lance Lavandowska
 */
public abstract class DateUtil extends Object {
    public static final long millisInDay = 86400000;
    
    // some static date formats
    private static SimpleDateFormat[] mDateFormats = loadDateFormats();
    
    private static final SimpleDateFormat mFormat8chars =
            new SimpleDateFormat("yyyyMMdd");
    
    private static final SimpleDateFormat mFormat6chars =
            new SimpleDateFormat("yyyyMM");
    
    private static final SimpleDateFormat mFormatIso8601Day =
            new SimpleDateFormat("yyyy-MM-dd");
    
    private static final SimpleDateFormat mFormatIso8601 =
            new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
    
    // http://www.w3.org/Protocols/rfc822/Overview.html#z28
    // Using Locale.US to fix ROL-725 and ROL-628
    private static final SimpleDateFormat 
 mFormatRfc822 =
            new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", Locale.US);
    
    
    private static SimpleDateFormat[] loadDateFormats() {
        SimpleDateFormat[] temp = {
            //new SimpleDateFormat("MM/dd/yyyy hh:mm:ss.SSS a"),
            new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy"), // standard Date.toString() results
            new SimpleDateFormat("M/d/yy hh:mm:ss"),
            new SimpleDateFormat("M/d/yyyy hh:mm:ss"),
            new SimpleDateFormat("M/d/yy hh:mm a"),
            new SimpleDateFormat("M/d/yyyy hh:mm a"),
            new SimpleDateFormat("M/d/yy HH:mm"),
            new SimpleDateFormat("M/d/yyyy HH:mm"),
            new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"),
            new SimpleDateFormat("yy-MM-dd HH:mm:ss.SSS"),
            new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"), // standard Timestamp.toString() results
            new SimpleDateFormat("M-d-yy HH:mm"),
            new SimpleDateFormat("M-d-yyyy HH:
 mm"),
            new SimpleDateFormat("MM/dd/yyyy HH:mm:ss.SSS"),
            new SimpleDateFormat("M/d/yy"),
            new SimpleDateFormat("M/d/yyyy"),
            new SimpleDateFormat("M-d-yy"),
            new SimpleDateFormat("M-d-yyyy"),
            new SimpleDateFormat("MMMM d, yyyyy"),
            new SimpleDateFormat("MMM d, yyyyy")
        };
        
        return temp;
    }
    //-----------------------------------------------------------------------
    /**
     * Gets the array of SimpleDateFormats that DateUtil knows about.
     **/
    private static SimpleDateFormat[] getFormats() {
        return mDateFormats;
    }
    
    //-----------------------------------------------------------------------
    /**
     * Returns a Date set to the last possible millisecond of the day, just
     * before midnight. If a null day is passed in, a new Date is created.
     * midnight (00m 00h 00s)
     */
    public static Date getEndOfDay(Date day) {
        return 
 getEndOfDay(day,Calendar.getInstance());
    }
    public static Date getEndOfDay(Date day,Calendar cal) {
        if (day == null) day = new Date();
        cal.setTime(day);
        cal.set(Calendar.HOUR_OF_DAY, cal.getMaximum(Calendar.HOUR_OF_DAY));
        cal.set(Calendar.MINUTE,      cal.getMaximum(Calendar.MINUTE));
        cal.set(Calendar.SECOND,      cal.getMaximum(Calendar.SECOND));
        cal.set(Calendar.MILLISECOND, cal.getMaximum(Calendar.MILLISECOND));
        return cal.getTime();
    }
    
    //-----------------------------------------------------------------------
    
    /**
     * Returns a Date set to the first possible millisecond of the month, just
     * after midnight. If a null day is passed in, a new Date is created.
     * midnight (00m 00h 00s)
     */
    public static Date getStartOfMonth(Date day) {
        return getStartOfMonth(day, Calendar.getInstance());
    }
    
    public static Date getStartOfMonth(Date day, Calendar cal) {
    
     if (day == null) day = new Date();
        cal.setTime(day);
        
        // set time to start of day
        cal.set(Calendar.HOUR_OF_DAY, cal.getMinimum(Calendar.HOUR_OF_DAY));
        cal.set(Calendar.MINUTE,      cal.getMinimum(Calendar.MINUTE));
        cal.set(Calendar.SECOND,      cal.getMinimum(Calendar.SECOND));
        cal.set(Calendar.MILLISECOND, cal.getMinimum(Calendar.MILLISECOND));
        
        // set time to first day of month
        cal.set(Calendar.DAY_OF_MONTH, 1);
                
        return cal.getTime();
    }
    
    /**
     * Returns a Date set to the last possible millisecond of the month, just
     * before midnight. If a null day is passed in, a new Date is created.
     * midnight (00m 00h 00s)
     */
    public static Date getEndOfMonth(Date day) {
        return getEndOfMonth(day, Calendar.getInstance());
    }
    
    public static Date getEndOfMonth(Date day,Calendar cal) {
        if (day == null) day = new Date();
      
   cal.setTime(day);
        
        // set time to end of day
        cal.set(Calendar.HOUR_OF_DAY, cal.getMaximum(Calendar.HOUR_OF_DAY));
        cal.set(Calendar.MINUTE,      cal.getMaximum(Calendar.MINUTE));
        cal.set(Calendar.SECOND,      cal.getMaximum(Calendar.SECOND));
        cal.set(Calendar.MILLISECOND, cal.getMaximum(Calendar.MILLISECOND));
        
        // set time to first day of month
        cal.set(Calendar.DAY_OF_MONTH, 1);
        
        // add one month
        cal.add(Calendar.MONTH, 1);
        
        // back up one day
        cal.add(Calendar.DAY_OF_MONTH, -1);
        
        return cal.getTime();
    }
    
    //-----------------------------------------------------------------------
    /**
     * Returns a Date set to the first possible millisecond of the day, just
     * after midnight. If a null day is passed in, a new Date is created.
     * midnight (00m 00h 00s)
     */
    public static Date getStartOfDay(Date day) {
        re
 turn getStartOfDay(day, Calendar.getInstance());
    }
    /**
     * Returns a Date set to the first possible millisecond of the day, just
     * after midnight. If a null day is passed in, a new Date is created.
     * midnight (00m 00h 00s)
     */
    public static Date getStartOfDay(Date day, Calendar cal) {
        if (day == null) day = new Date();
        cal.setTime(day);
        cal.set(Calendar.HOUR_OF_DAY, cal.getMinimum(Calendar.HOUR_OF_DAY));
        cal.set(Calendar.MINUTE,      cal.getMinimum(Calendar.MINUTE));
        cal.set(Calendar.SECOND,      cal.getMinimum(Calendar.SECOND));
        cal.set(Calendar.MILLISECOND, cal.getMinimum(Calendar.MILLISECOND));
        return cal.getTime();
    }
    
    /**
     * Returns a Date set just to Noon, to the closest possible millisecond
     * of the day. If a null day is passed in, a new Date is created.
     * nnoon (00m 12h 00s)
     */
    public static Date getNoonOfDay(Date day, Calendar cal) {
        if (day
  == null) day = new Date();
        cal.setTime(day);
        cal.set(Calendar.HOUR_OF_DAY, 12);
        cal.set(Calendar.MINUTE,      cal.getMinimum(Calendar.MINUTE));
        cal.set(Calendar.SECOND,      cal.getMinimum(Calendar.SECOND));
        cal.set(Calendar.MILLISECOND, cal.getMinimum(Calendar.MILLISECOND));
        return cal.getTime();
    }
    
    //-----------------------------------------------------------------------
    public static Date parseFromFormats(String aValue) {
        if (StringUtils.isEmpty(aValue)) return null;
        
        // get DateUtil's formats
        SimpleDateFormat formats[] = DateUtil.getFormats();
        if (formats == null) return null;
        
        // iterate over the array and parse
        Date myDate = null;
        for (int i = 0; i <formats.length; i++) {
            try {
                myDate = DateUtil.parse(aValue, formats[i]);
                //if (myDate instanceof Date)
                return myDate;
         
    } catch (Exception e) {
                // do nothing because we want to try the next
                // format if current one fails
            }
        }
        // haven't returned so couldn't parse
        return null;
    }
    
    //-----------------------------------------------------------------------
    public static java.sql.Timestamp parseTimestampFromFormats(String aValue) {
        if (StringUtils.isEmpty(aValue)) return null;
        
        // call the regular Date formatter
        Date myDate = DateUtil.parseFromFormats(aValue);
        if (myDate != null) return new java.sql.Timestamp(myDate.getTime());
        return null;
    }
    //-----------------------------------------------------------------------
    /**
     * Returns a java.sql.Timestamp equal to the current time
     **/
    public static java.sql.Timestamp now() {
        return new java.sql.Timestamp(new java.util.Date().getTime());
    }
    
    //------------------------------------
 -----------------------------------
    /**
     * Returns a string the represents the passed-in date parsed
     * according to the passed-in format.  Returns an empty string
     * if the date or the format is null.
     **/
    public static String format(Date aDate, SimpleDateFormat aFormat) {
        if (aDate == null || aFormat == null ) { return ""; }
        synchronized (aFormat) {
            return aFormat.format(aDate);
        }
    }
    
    //-----------------------------------------------------------------------
    /**
     * Tries to take the passed-in String and format it as a date string in the
     * the passed-in format.
     **/
    public static String formatDateString(String aString, SimpleDateFormat aFormat) {
        if (StringUtils.isEmpty(aString) || aFormat == null)  return "";
        try {
            java.sql.Timestamp aDate = parseTimestampFromFormats(aString);
            if (aDate != null) {
                return DateUtil.format(aDate, a
 Format);
            }
        } catch (Exception e) {
            // Could not parse aString.
        }
        return "";
    }
    
    //-----------------------------------------------------------------------
    /**
     * Returns a Date using the passed-in string and format.  Returns null if the string
     * is null or empty or if the format is null.  The string must match the format.
     **/
    public static Date parse(String aValue, SimpleDateFormat aFormat) throws ParseException {
        if (StringUtils.isEmpty(aValue) || aFormat == null) {
            return null;
        }
        
        return aFormat.parse(aValue);
    }
    
    //-----------------------------------------------------------------------
    /**
     * Returns true if endDate is after startDate or if startDate equals endDate
     * or if they are the same date.  Returns false if either value is null.
     **/
    public static boolean isValidDateRange(Date startDate, Date endDate) {
        
 return isValidDateRange(startDate, endDate, true);
    }
    
    //-----------------------------------------------------------------------
    /**
     * Returns true if endDate is after startDate or if startDate equals endDate.
     * Returns false if either value is null.  If equalOK, returns true if the
     * dates are equal.
     **/
    public static boolean isValidDateRange(Date startDate, Date endDate, boolean equalOK) {
        // false if either value is null
        if (startDate == null || endDate == null) { return false; }
        
        if (equalOK) {
            // true if they are equal
            if (startDate.equals(endDate)) { return true; }
        }
        
        // true if endDate after startDate
        if (endDate.after(startDate)) { return true; }
        
        return false;
    }
    
    //-----------------------------------------------------------------------
    // returns full timestamp format
    public static java.text.SimpleDateForm
 at defaultTimestampFormat() {
        return new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
    }
    
    //-----------------------------------------------------------------------
    // convenience method returns minimal date format
    public static java.text.SimpleDateFormat get8charDateFormat() {
        return DateUtil.mFormat8chars;
    }
    
    // convenience method returns minimal date format
    public static java.text.SimpleDateFormat get6charDateFormat() {
        return DateUtil.mFormat6chars;
    }
    
    //-----------------------------------------------------------------------
    // convenience method returns minimal date format
    public static java.text.SimpleDateFormat defaultDateFormat() {
        return DateUtil.friendlyDateFormat(true);
    }
    
    //-----------------------------------------------------------------------
    // convenience method
    public static String defaultTimestamp(Date date) {
        return DateUtil.format(da
 te, DateUtil.defaultTimestampFormat());
    }
    
    //-----------------------------------------------------------------------
    // convenience method
    public static String defaultDate(Date date) {
        return DateUtil.format(date, DateUtil.defaultDateFormat());
    }
    
    //-----------------------------------------------------------------------
    // convenience method returns long friendly timestamp format
    public static java.text.SimpleDateFormat friendlyTimestampFormat() {
        return new java.text.SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
    }
    
    //-----------------------------------------------------------------------
    // convenience method returns long friendly formatted timestamp
    public static String friendlyTimestamp(Date date) {
        return DateUtil.format(date, DateUtil.friendlyTimestampFormat());
    }
    
    //-----------------------------------------------------------------------
    // convenience method returns long frie
 ndly formatted timestamp
    public static String format8chars(Date date) {
        return DateUtil.format(date, mFormat8chars);
    }
    
    //-----------------------------------------------------------------------
    // convenience method returns long friendly formatted timestamp
    public static String formatIso8601Day(Date date) {
        return DateUtil.format(date, mFormatIso8601Day);
    }
    
    //-----------------------------------------------------------------------
    public static String formatRfc822(Date date) {
        return DateUtil.format(date,mFormatRfc822);
    }
    
    //-----------------------------------------------------------------------
    // This is a hack, but it seems to work
    public static String formatIso8601(Date date) {
        if (date == null) return "";
        
        // Add a colon 2 chars before the end of the string
        // to make it a valid ISO-8601 date.
        
        String str = DateUtil.format(date,mFormatIso86
 01);
        StringBuffer sb = new StringBuffer();
        sb.append( str.substring(0,str.length()-2) );
        sb.append( ":" );
        sb.append( str.substring(str.length()-2) );
        return sb.toString();
    }
    
    //-----------------------------------------------------------------------
    // convenience method returns minimal date format
    public static java.text.SimpleDateFormat minimalDateFormat() {
        return DateUtil.friendlyDateFormat(true);
    }
    
    //-----------------------------------------------------------------------
    // convenience method using minimal date format
    public static String minimalDate(Date date) {
        return DateUtil.format(date, DateUtil.minimalDateFormat());
    }
    
    //-----------------------------------------------------------------------
    // convenience method that returns friendly data format
    // using full month, day, year digits.
    public static java.text.SimpleDateFormat fullDateFormat() {
 
        return DateUtil.friendlyDateFormat(false);
    }
    
    //-----------------------------------------------------------------------
    public static String fullDate(Date date) {
        return DateUtil.format(date, DateUtil.fullDateFormat());
    }
    
    //-----------------------------------------------------------------------
    /** Returns a "friendly" date format.
     *  @param mimimalFormat Should the date format allow single digits.
     **/
    public static java.text.SimpleDateFormat friendlyDateFormat(boolean minimalFormat) {
        if (minimalFormat) {
            return new java.text.SimpleDateFormat("d.M.yy");
        }
        
        return new java.text.SimpleDateFormat("dd.MM.yyyy");
    }
    
    //-----------------------------------------------------------------------
    /**
     * Format the date using the "friendly" date format.
     */
    public static String friendlyDate(Date date, boolean minimalFormat) {
        return DateUtil.format
 (date, DateUtil.friendlyDateFormat(minimalFormat));
    }
    
    //-----------------------------------------------------------------------
    // convenience method
    public static String friendlyDate(Date date) {
        return DateUtil.format(date, DateUtil.friendlyDateFormat(true));
    }
    
    public static Date parseIso8601(String value) throws Exception {
        return ISO8601DateParser.parse(value);
    }
    
}
\ No newline at end of file
+/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  The ASF licenses this file to You
 * 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.  For additional information regarding
 * copyright in this work, please see the NOTICE file in the top level
 * directory of this distribution.
 */
package org.apache.roller.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
 import java.util.Locale;
import org.apache.commons.lang.StringUtils;

/**
 * General purpose date utilities.
 * @author Mark Saarinen
 * @author Lance Lavandowska
 */
public abstract class DateUtil extends Object {
    public static final long millisInDay = 86400000;
    
    // some static date formats
    private static SimpleDateFormat[] mDateFormats = loadDateFormats();
    
    private static final SimpleDateFormat mFormat8chars =
            new SimpleDateFormat("yyyyMMdd");
    
    private static final SimpleDateFormat mFormat6chars =
            new SimpleDateFormat("yyyyMM");
    
    private static final SimpleDateFormat mFormatIso8601Day =
            new SimpleDateFormat("yyyy-MM-dd");
    
    private static final SimpleDateFormat mFormatIso8601 =
            new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
    
    // http://www.w3.org/Protocols/rfc822/Overview.html#z28
    // Using Locale.US to fix ROL-725 and ROL-628
    private static final SimpleDateFormat 
 mFormatRfc822 =
            new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", Locale.US);
    
    
    private static SimpleDateFormat[] loadDateFormats() {
        SimpleDateFormat[] temp = {
            //new SimpleDateFormat("MM/dd/yyyy hh:mm:ss.SSS a"),
            new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy"), // standard Date.toString() results
            new SimpleDateFormat("M/d/yy hh:mm:ss"),
            new SimpleDateFormat("M/d/yyyy hh:mm:ss"),
            new SimpleDateFormat("M/d/yy hh:mm a"),
            new SimpleDateFormat("M/d/yyyy hh:mm a"),
            new SimpleDateFormat("M/d/yy HH:mm"),
            new SimpleDateFormat("M/d/yyyy HH:mm"),
            new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"),
            new SimpleDateFormat("yy-MM-dd HH:mm:ss.SSS"),
            new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"), // standard Timestamp.toString() results
            new SimpleDateFormat("M-d-yy HH:mm"),
            new SimpleDateFormat("M-d-yyyy HH:
 mm"),
            new SimpleDateFormat("MM/dd/yyyy HH:mm:ss.SSS"),
            new SimpleDateFormat("M/d/yy"),
            new SimpleDateFormat("M/d/yyyy"),
            new SimpleDateFormat("M-d-yy"),
            new SimpleDateFormat("M-d-yyyy"),
            new SimpleDateFormat("MMMM d, yyyyy"),
            new SimpleDateFormat("MMM d, yyyyy")
        };
        
        return temp;
    }
    //-----------------------------------------------------------------------
    /**
     * Gets the array of SimpleDateFormats that DateUtil knows about.
     **/
    private static SimpleDateFormat[] getFormats() {
        return mDateFormats;
    }
    
    //-----------------------------------------------------------------------
    /**
     * Returns a Date set to the last possible millisecond of the day, just
     * before midnight. If a null day is passed in, a new Date is created.
     * midnight (00m 00h 00s)
     */
    public static Date getEndOfDay(Date day) {
        return 
 getEndOfDay(day,Calendar.getInstance());
    }
    public static Date getEndOfDay(Date day,Calendar cal) {
        if (day == null) day = new Date();
        cal.setTime(day);
        cal.set(Calendar.HOUR_OF_DAY, cal.getMaximum(Calendar.HOUR_OF_DAY));
        cal.set(Calendar.MINUTE,      cal.getMaximum(Calendar.MINUTE));
        cal.set(Calendar.SECOND,      cal.getMaximum(Calendar.SECOND));
        cal.set(Calendar.MILLISECOND, cal.getMaximum(Calendar.MILLISECOND));
        return cal.getTime();
    }
    
    //-----------------------------------------------------------------------
    
    /**
     * Returns a Date set to the first possible millisecond of the month, just
     * after midnight. If a null day is passed in, a new Date is created.
     * midnight (00m 00h 00s)
     */
    public static Date getStartOfMonth(Date day) {
        return getStartOfMonth(day, Calendar.getInstance());
    }
    
    public static Date getStartOfMonth(Date day, Calendar cal) {
    
     if (day == null) day = new Date();
        cal.setTime(day);
        
        // set time to start of day
        cal.set(Calendar.HOUR_OF_DAY, cal.getMinimum(Calendar.HOUR_OF_DAY));
        cal.set(Calendar.MINUTE,      cal.getMinimum(Calendar.MINUTE));
        cal.set(Calendar.SECOND,      cal.getMinimum(Calendar.SECOND));
        cal.set(Calendar.MILLISECOND, cal.getMinimum(Calendar.MILLISECOND));
        
        // set time to first day of month
        cal.set(Calendar.DAY_OF_MONTH, 1);
                
        return cal.getTime();
    }
    
    /**
     * Returns a Date set to the last possible millisecond of the month, just
     * before midnight. If a null day is passed in, a new Date is created.
     * midnight (00m 00h 00s)
     */
    public static Date getEndOfMonth(Date day) {
        return getEndOfMonth(day, Calendar.getInstance());
    }
    
    public static Date getEndOfMonth(Date day,Calendar cal) {
        if (day == null) day = new Date();
      
   cal.setTime(day);
        
        // set time to end of day
        cal.set(Calendar.HOUR_OF_DAY, cal.getMaximum(Calendar.HOUR_OF_DAY));
        cal.set(Calendar.MINUTE,      cal.getMaximum(Calendar.MINUTE));
        cal.set(Calendar.SECOND,      cal.getMaximum(Calendar.SECOND));
        cal.set(Calendar.MILLISECOND, cal.getMaximum(Calendar.MILLISECOND));
        
        // set time to first day of month
        cal.set(Calendar.DAY_OF_MONTH, 1);
        
        // add one month
        cal.add(Calendar.MONTH, 1);
        
        // back up one day
        cal.add(Calendar.DAY_OF_MONTH, -1);
        
        return cal.getTime();
    }
    
    //-----------------------------------------------------------------------
    /**
     * Returns a Date set to the first possible millisecond of the day, just
     * after midnight. If a null day is passed in, a new Date is created.
     * midnight (00m 00h 00s)
     */
    public static Date getStartOfDay(Date day) {
        re
 turn getStartOfDay(day, Calendar.getInstance());
    }
    /**
     * Returns a Date set to the first possible millisecond of the day, just
     * after midnight. If a null day is passed in, a new Date is created.
     * midnight (00m 00h 00s)
     */
    public static Date getStartOfDay(Date day, Calendar cal) {
        if (day == null) day = new Date();
        cal.setTime(day);
        cal.set(Calendar.HOUR_OF_DAY, cal.getMinimum(Calendar.HOUR_OF_DAY));
        cal.set(Calendar.MINUTE,      cal.getMinimum(Calendar.MINUTE));
        cal.set(Calendar.SECOND,      cal.getMinimum(Calendar.SECOND));
        cal.set(Calendar.MILLISECOND, cal.getMinimum(Calendar.MILLISECOND));
        return cal.getTime();
    }
    
    /**
     * Returns a Date set just to Noon, to the closest possible millisecond
     * of the day. If a null day is passed in, a new Date is created.
     * nnoon (00m 12h 00s)
     */
    public static Date getNoonOfDay(Date day, Calendar cal) {
        if (day
  == null) day = new Date();
        cal.setTime(day);
        cal.set(Calendar.HOUR_OF_DAY, 12);
        cal.set(Calendar.MINUTE,      cal.getMinimum(Calendar.MINUTE));
        cal.set(Calendar.SECOND,      cal.getMinimum(Calendar.SECOND));
        cal.set(Calendar.MILLISECOND, cal.getMinimum(Calendar.MILLISECOND));
        return cal.getTime();
    }
    
    //-----------------------------------------------------------------------
    public static Date parseFromFormats(String aValue) {
        if (StringUtils.isEmpty(aValue)) return null;
        
        // get DateUtil's formats
        SimpleDateFormat formats[] = DateUtil.getFormats();
        if (formats == null) return null;
        
        // iterate over the array and parse
        Date myDate = null;
        for (int i = 0; i <formats.length; i++) {
            try {
                myDate = DateUtil.parse(aValue, formats[i]);
                //if (myDate instanceof Date)
                return myDate;
         
    } catch (Exception e) {
                // do nothing because we want to try the next
                // format if current one fails
            }
        }
        // haven't returned so couldn't parse
        return null;
    }
    
    //-----------------------------------------------------------------------
    public static java.sql.Timestamp parseTimestampFromFormats(String aValue) {
        if (StringUtils.isEmpty(aValue)) return null;
        
        // call the regular Date formatter
        Date myDate = DateUtil.parseFromFormats(aValue);
        if (myDate != null) return new java.sql.Timestamp(myDate.getTime());
        return null;
    }
    //-----------------------------------------------------------------------
    /**
     * Returns a java.sql.Timestamp equal to the current time
     **/
    public static java.sql.Timestamp now() {
        return new java.sql.Timestamp(new java.util.Date().getTime());
    }
    
    //------------------------------------
 -----------------------------------
    /**
     * Returns a string the represents the passed-in date parsed
     * according to the passed-in format.  Returns an empty string
     * if the date or the format is null.
     **/
    public static String format(Date aDate, SimpleDateFormat aFormat) {
        if (aDate == null || aFormat == null ) { return ""; }
        synchronized (aFormat) {
            return aFormat.format(aDate);
        }
    }
    
    //-----------------------------------------------------------------------
    /**
     * Tries to take the passed-in String and format it as a date string in the
     * the passed-in format.
     **/
    public static String formatDateString(String aString, SimpleDateFormat aFormat) {
        if (StringUtils.isEmpty(aString) || aFormat == null)  return "";
        try {
            java.sql.Timestamp aDate = parseTimestampFromFormats(aString);
            if (aDate != null) {
                return DateUtil.format(aDate, a
 Format);
            }
        } catch (Exception e) {
            // Could not parse aString.
        }
        return "";
    }
    
    //-----------------------------------------------------------------------
    /**
     * Returns a Date using the passed-in string and format.  Returns null if the string
     * is null or empty or if the format is null.  The string must match the format.
     **/
    public static Date parse(String aValue, SimpleDateFormat aFormat) throws ParseException {
        if (StringUtils.isEmpty(aValue) || aFormat == null) {
            return null;
        }
        
        return aFormat.parse(aValue);
    }
    
    //-----------------------------------------------------------------------
    /**
     * Returns true if endDate is after startDate or if startDate equals endDate
     * or if they are the same date.  Returns false if either value is null.
     **/
    public static boolean isValidDateRange(Date startDate, Date endDate) {
        
 return isValidDateRange(startDate, endDate, true);
    }
    
    //-----------------------------------------------------------------------
    /**
     * Returns true if endDate is after startDate or if startDate equals endDate.
     * Returns false if either value is null.  If equalOK, returns true if the
     * dates are equal.
     **/
    public static boolean isValidDateRange(Date startDate, Date endDate, boolean equalOK) {
        // false if either value is null
        if (startDate == null || endDate == null) { return false; }
        
        if (equalOK) {
            // true if they are equal
            if (startDate.equals(endDate)) { return true; }
        }
        
        // true if endDate after startDate
        if (endDate.after(startDate)) { return true; }
        
        return false;
    }
    
    //-----------------------------------------------------------------------
    // returns full timestamp format
    public static java.text.SimpleDateForm
 at defaultTimestampFormat() {
        return new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
    }
    
    //-----------------------------------------------------------------------
    // convenience method returns minimal date format
    public static java.text.SimpleDateFormat get8charDateFormat() {
        return DateUtil.mFormat8chars;
    }
    
    // convenience method returns minimal date format
    public static java.text.SimpleDateFormat get6charDateFormat() {
        return DateUtil.mFormat6chars;
    }
    
    //-----------------------------------------------------------------------
    // convenience method returns minimal date format
    public static java.text.SimpleDateFormat defaultDateFormat() {
        return DateUtil.friendlyDateFormat(true);
    }
    
    //-----------------------------------------------------------------------
    // convenience method
    public static String defaultTimestamp(Date date) {
        return DateUtil.format(da
 te, DateUtil.defaultTimestampFormat());
    }
    
    //-----------------------------------------------------------------------
    // convenience method
    public static String defaultDate(Date date) {
        return DateUtil.format(date, DateUtil.defaultDateFormat());
    }
    
    //-----------------------------------------------------------------------
    // convenience method returns long friendly timestamp format
    public static java.text.SimpleDateFormat friendlyTimestampFormat() {
        return new java.text.SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
    }
    
    //-----------------------------------------------------------------------
    // convenience method returns long friendly formatted timestamp
    public static String friendlyTimestamp(Date date) {
        return DateUtil.format(date, DateUtil.friendlyTimestampFormat());
    }
    
    //-----------------------------------------------------------------------
    // convenience method returns 8 char da
 y stamp YYYYMMDD
    public static String format8chars(Date date) {
        return DateUtil.format(date, mFormat8chars);
    }
    
    //-----------------------------------------------------------------------
    // convenience method returns 6 char month stamp YYYYMM
    public static String format6chars(Date date) {
        return DateUtil.format(date, mFormat6chars);
    }
    
    //-----------------------------------------------------------------------
    // convenience method returns long friendly formatted timestamp
    public static String formatIso8601Day(Date date) {
        return DateUtil.format(date, mFormatIso8601Day);
    }
    
    //-----------------------------------------------------------------------
    public static String formatRfc822(Date date) {
        return DateUtil.format(date,mFormatRfc822);
    }
    
    //-----------------------------------------------------------------------
    // This is a hack, but it seems to work
    public static Str
 ing formatIso8601(Date date) {
        if (date == null) return "";
        
        // Add a colon 2 chars before the end of the string
        // to make it a valid ISO-8601 date.
        
        String str = DateUtil.format(date,mFormatIso8601);
        StringBuffer sb = new StringBuffer();
        sb.append( str.substring(0,str.length()-2) );
        sb.append( ":" );
        sb.append( str.substring(str.length()-2) );
        return sb.toString();
    }
    
    //-----------------------------------------------------------------------
    // convenience method returns minimal date format
    public static java.text.SimpleDateFormat minimalDateFormat() {
        return DateUtil.friendlyDateFormat(true);
    }
    
    //-----------------------------------------------------------------------
    // convenience method using minimal date format
    public static String minimalDate(Date date) {
        return DateUtil.format(date, DateUtil.minimalDateFormat());
    }
    
 
    //-----------------------------------------------------------------------
    // convenience method that returns friendly data format
    // using full month, day, year digits.
    public static java.text.SimpleDateFormat fullDateFormat() {
        return DateUtil.friendlyDateFormat(false);
    }
    
    //-----------------------------------------------------------------------
    public static String fullDate(Date date) {
        return DateUtil.format(date, DateUtil.fullDateFormat());
    }
    
    //-----------------------------------------------------------------------
    /** Returns a "friendly" date format.
     *  @param mimimalFormat Should the date format allow single digits.
     **/
    public static java.text.SimpleDateFormat friendlyDateFormat(boolean minimalFormat) {
        if (minimalFormat) {
            return new java.text.SimpleDateFormat("d.M.yy");
        }
        
        return new java.text.SimpleDateFormat("dd.MM.yyyy");
    }
    
    //----
 -------------------------------------------------------------------
    /**
     * Format the date using the "friendly" date format.
     */
    public static String friendlyDate(Date date, boolean minimalFormat) {
        return DateUtil.format(date, DateUtil.friendlyDateFormat(minimalFormat));
    }
    
    //-----------------------------------------------------------------------
    // convenience method
    public static String friendlyDate(Date date) {
        return DateUtil.format(date, DateUtil.friendlyDateFormat(true));
    }
    
    public static Date parseIso8601(String value) throws Exception {
        return ISO8601DateParser.parse(value);
    }
    
}
\ No newline at end of file

Modified: incubator/roller/branches/roller_3.0/tests/org/apache/roller/business/IndexManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/tests/org/apache/roller/business/IndexManagerTest.java?rev=417044&r1=417043&r2=417044&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/tests/org/apache/roller/business/IndexManagerTest.java (original)
+++ incubator/roller/branches/roller_3.0/tests/org/apache/roller/business/IndexManagerTest.java Sun Jun 25 12:33:50 2006
@@ -45,66 +45,63 @@
     }
         
     public void testSearch() throws Exception {
-        try {
-            IndexManager imgr = RollerFactory.getRoller().getIndexManager();
-            
-            WebsiteData website = new WebsiteData();
-            website.setHandle("trekker");
-            
-            UserData user = new UserData();
-            user.setUserName("nimoy");
-            
-            WeblogEntryData wd1 = new WeblogEntryData();            
-            wd1.setId("dummy1");
-            wd1.setAnchor("dummy1");
-            wd1.setCreator(user);
-            wd1.setUpdateTime(new Timestamp(System.currentTimeMillis()));
-            wd1.setPubTime(new Timestamp(System.currentTimeMillis()));
-            wd1.setTitle("The Tholian Web");
-            wd1.setWebsite(website);
-            wd1.setText(
-             "When the Enterprise attempts to ascertain the fate of the  "
-            +"U.S.S. Defiant which vanished 3 weeks ago, the warp engines  "
-            +"begin to lose power, and Spock reports strange sensor readings.");
-            imgr.executeIndexOperationNow(
-                new AddEntryOperation((IndexManagerImpl) imgr, wd1));
-            
-            WeblogEntryData wd2 = new WeblogEntryData();
-            wd2.setId("dummy2");
-            wd2.setAnchor("dummy2");
-            wd2.setCreator(user);
-            wd2.setUpdateTime(new Timestamp(System.currentTimeMillis()));
-            wd2.setPubTime(new Timestamp(System.currentTimeMillis()));
-            wd2.setTitle("A Piece of the Action");
-            wd2.setWebsite(website);
-            wd2.setText(
-              "The crew of the Enterprise attempts to make contact with "
-              +"the inhabitants of planet Sigma Iotia II, and Uhura puts Kirk "
-              +"in communication with Boss Oxmyx.");
-             imgr.executeIndexOperationNow(
-                 new AddEntryOperation((IndexManagerImpl) imgr, wd2));
-            
-            SearchOperation search = new SearchOperation(imgr);
-            search.setTerm("Enterprise");
-            imgr.executeIndexOperationNow(search);
-            assertEquals(2, search.getResultsCount());
-            
-            SearchOperation search2 = new SearchOperation(imgr);
-            search2.setTerm("Tholian");
-            imgr.executeIndexOperationNow(search2);
-            assertEquals(1, search2.getResultsCount());
-            
-            // Clean up
-            imgr.removeEntryIndexOperation(wd1);
-            imgr.removeEntryIndexOperation(wd2);
-            
-            SearchOperation search3 = new SearchOperation(imgr);
-            search3.setTerm("Enterprise");
-            imgr.executeIndexOperationNow(search3);
-            assertEquals(0, search3.getResultsCount());
-
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
+        IndexManager imgr = RollerFactory.getRoller().getIndexManager();
+
+        WebsiteData website = new WebsiteData();
+        website.setHandle("trekker");
+
+        UserData user = new UserData();
+        user.setUserName("nimoy");
+
+        WeblogEntryData wd1 = new WeblogEntryData();            
+        wd1.setId("dummy1");
+        wd1.setAnchor("dummy1");
+        wd1.setCreator(user);
+        wd1.setUpdateTime(new Timestamp(System.currentTimeMillis()));
+        wd1.setPubTime(new Timestamp(System.currentTimeMillis()));
+        wd1.setTitle("The Tholian Web");
+        wd1.setWebsite(website);
+        wd1.setText(
+         "When the Enterprise attempts to ascertain the fate of the  "
+        +"U.S.S. Defiant which vanished 3 weeks ago, the warp engines  "
+        +"begin to lose power, and Spock reports strange sensor readings.");
+        imgr.executeIndexOperationNow(
+            new AddEntryOperation((IndexManagerImpl) imgr, wd1));
+
+        WeblogEntryData wd2 = new WeblogEntryData();
+        wd2.setId("dummy2");
+        wd2.setAnchor("dummy2");
+        wd2.setCreator(user);
+        wd2.setUpdateTime(new Timestamp(System.currentTimeMillis()));
+        wd2.setPubTime(new Timestamp(System.currentTimeMillis()));
+        wd2.setTitle("A Piece of the Action");
+        wd2.setWebsite(website);
+        wd2.setText(
+          "The crew of the Enterprise attempts to make contact with "
+          +"the inhabitants of planet Sigma Iotia II, and Uhura puts Kirk "
+          +"in communication with Boss Oxmyx.");
+         imgr.executeIndexOperationNow(
+             new AddEntryOperation((IndexManagerImpl) imgr, wd2));
+
+        Thread.sleep(1000);
+
+        SearchOperation search = new SearchOperation(imgr);
+        search.setTerm("Enterprise");
+        imgr.executeIndexOperationNow(search);
+        assertEquals(2, search.getResultsCount());
+
+        SearchOperation search2 = new SearchOperation(imgr);
+        search2.setTerm("Tholian");
+        imgr.executeIndexOperationNow(search2);
+        assertEquals(1, search2.getResultsCount());
+
+        // Clean up
+        imgr.removeEntryIndexOperation(wd1);
+        imgr.removeEntryIndexOperation(wd2);
+
+        SearchOperation search3 = new SearchOperation(imgr);
+        search3.setTerm("Enterprise");
+        imgr.executeIndexOperationNow(search3);
+        assertEquals(0, search3.getResultsCount());
     }    
 }

Modified: incubator/roller/branches/roller_3.0/tests/org/apache/roller/business/PermissionTest.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/tests/org/apache/roller/business/PermissionTest.java?rev=417044&r1=417043&r2=417044&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/tests/org/apache/roller/business/PermissionTest.java (original)
+++ incubator/roller/branches/roller_3.0/tests/org/apache/roller/business/PermissionTest.java Sun Jun 25 12:33:50 2006
@@ -225,12 +225,12 @@
         
         // assert that user is member of weblog
         assertFalse(mgr.getPermissions(testWeblog, user).isPending());
-        List weblogs = mgr.getWebsites(user, null, null, null, null, 0, Integer.MAX_VALUE);
+        List weblogs = mgr.getWebsites(user, null, null, null, null, 0, -1);
         assertEquals(1, weblogs.size());
         assertEquals(testWeblog.getId(), ((WebsiteData)weblogs.get(0)).getId());
         
         // assert that website has user
-        List users = mgr.getUsers(testWeblog, null, 0, Integer.MAX_VALUE); 
+        List users = mgr.getUsers(testWeblog, null, 0, -1); 
         assertEquals(2, users.size());
         
         // test user can be retired from website

Modified: incubator/roller/branches/roller_3.0/tests/org/apache/roller/business/PlanetManagerLocalTest.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/tests/org/apache/roller/business/PlanetManagerLocalTest.java?rev=417044&r1=417043&r2=417044&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/tests/org/apache/roller/business/PlanetManagerLocalTest.java (original)
+++ incubator/roller/branches/roller_3.0/tests/org/apache/roller/business/PlanetManagerLocalTest.java Sun Jun 25 12:33:50 2006
@@ -15,13 +15,24 @@
  */
 package org.apache.roller.business;
 
+import java.sql.Timestamp;
+import java.util.Date;
 import java.util.List;
 
 import junit.framework.Test;
+import junit.framework.TestCase;
 import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.TestUtils;
 
-import org.apache.roller.RollerTestBase;
 import org.apache.roller.model.PlanetManager;
+import org.apache.roller.model.RollerFactory;
+import org.apache.roller.pojos.UserData;
+import org.apache.roller.pojos.WeblogEntryData;
+import org.apache.roller.pojos.WebsiteData;
 import org.apache.roller.ui.core.tasks.RefreshEntriesTask;
 import org.apache.roller.ui.core.tasks.SyncWebsitesTask;
 
@@ -29,37 +40,96 @@
  * Test database implementation of PlanetManager for local feeds.
  * @author Dave Johnson
  */
-public class PlanetManagerLocalTest extends RollerTestBase {
+public class PlanetManagerLocalTest extends TestCase {
+    public static Log log = LogFactory.getLog(PlanetManagerLocalTest.class);
+    
+    UserData testUser = null;
+    WebsiteData testWeblog = null;
     
     public static void main(String[] args) {
-        junit.textui.TestRunner.run(PlanetManagerLocalTest.class);
+        TestRunner.run(PlanetManagerLocalTest.class);
     }
     
+    /**
+     * All tests in this suite require a user and a weblog.
+     */
     public void setUp() throws Exception {
-        super.setUp();
-        super.setUpTestWeblogs();
+        
+        try {
+            testUser = TestUtils.setupUser("entryTestUser");
+            testWeblog = TestUtils.setupWeblog("entryTestWeblog", testUser);
+            
+            WeblogEntryData testEntry1 = new WeblogEntryData();
+            testEntry1.setTitle("entryTestEntry1");
+            testEntry1.setLink("testEntryLink1");
+            testEntry1.setText("blah blah entry1");
+            testEntry1.setAnchor("testEntryAnchor1");
+            testEntry1.setPubTime(new Timestamp(new Date().getTime()));
+            testEntry1.setUpdateTime(new Timestamp(new Date().getTime()));
+            testEntry1.setWebsite(testWeblog);
+            testEntry1.setCreator(testUser);
+            testEntry1.setCategory(testWeblog.getDefaultCategory());
+            RollerFactory.getRoller().getWeblogManager().saveWeblogEntry(testEntry1);
+
+            WeblogEntryData testEntry2 = new WeblogEntryData();
+            testEntry2.setTitle("entryTestEntry2");
+            testEntry2.setLink("testEntryLink2");
+            testEntry2.setText("blah blah entry2");
+            testEntry2.setAnchor("testEntryAnchor2");
+            testEntry2.setPubTime(new Timestamp(new Date().getTime()));
+            testEntry2.setUpdateTime(new Timestamp(new Date().getTime()));
+            testEntry2.setWebsite(testWeblog);
+            testEntry2.setCreator(testUser);
+            testEntry2.setCategory(testWeblog.getDefaultCategory());
+            RollerFactory.getRoller().getWeblogManager().saveWeblogEntry(testEntry1);
+
+            WeblogEntryData testEntry3 = new WeblogEntryData();
+            testEntry3.setTitle("entryTestEntry3");
+            testEntry3.setLink("testEntryLink3");
+            testEntry3.setText("blah blah entry3");
+            testEntry3.setAnchor("testEntryAnchor3");
+            testEntry3.setPubTime(new Timestamp(new Date().getTime()));
+            testEntry3.setUpdateTime(new Timestamp(new Date().getTime()));
+            testEntry3.setWebsite(testWeblog);
+            testEntry3.setCreator(testUser);
+            testEntry3.setCategory(testWeblog.getDefaultCategory());           
+            RollerFactory.getRoller().getWeblogManager().saveWeblogEntry(testEntry1);
+
+            TestUtils.endSession(true);
+            
+        } catch (Exception ex) {
+            log.error(ex);
+            throw new Exception("Test setup failed", ex);
+        }
     }
     
     public void tearDown() throws Exception {
-        super.tearDown();
-        super.tearDownTestWeblogs();
+        
+        try {
+            TestUtils.teardownWeblog(testWeblog.getId());
+            TestUtils.teardownUser(testUser.getId());
+            TestUtils.endSession(true);
+        } catch (Exception ex) {
+            log.error(ex);
+            throw new Exception("Test teardown failed", ex);
+        }
     }
+    
     public void testRefreshEntries() {
         try {      
-            PlanetManager planet = getRoller().getPlanetManager();
+            PlanetManager planet = RollerFactory.getRoller().getPlanetManager();
             
             // run sync task to fill aggregator with websites created by super
             SyncWebsitesTask syncTask = new SyncWebsitesTask();
-            syncTask.init(getRoller(), "dummy");
+            syncTask.init(RollerFactory.getRoller(), "dummy");
             syncTask.run();           
             
             RefreshEntriesTask refreshTask = new RefreshEntriesTask();
-            refreshTask.init(getRoller(), "dummy");
+            refreshTask.init(RollerFactory.getRoller(), "dummy");
             refreshTask.run();
             
             List agg = planet.getAggregation(null, null, 0, -1);
-            int size = agg.size();
-            assertEquals(mBlogCount * mExpectedPublishedEntryCount, size);
+            assertEquals(3, agg.size());
         }
         catch (Exception e) {
             e.printStackTrace();

Modified: incubator/roller/branches/roller_3.0/tests/org/apache/roller/business/PlanetManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/tests/org/apache/roller/business/PlanetManagerTest.java?rev=417044&r1=417043&r2=417044&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/tests/org/apache/roller/business/PlanetManagerTest.java (original)
+++ incubator/roller/branches/roller_3.0/tests/org/apache/roller/business/PlanetManagerTest.java Sun Jun 25 12:33:50 2006
@@ -134,7 +134,7 @@
         
         {   // save subscription
             PlanetSubscriptionData sub = new PlanetSubscriptionData();
-            sub.setFeedUrl("test_url");
+            sub.setFeedURL("test_url");
             planet.saveSubscription(sub);
             TestUtils.endSession(true);
         }
@@ -150,7 +150,7 @@
             group.addSubscription(sub);
             
             PlanetSubscriptionData sub1 = new PlanetSubscriptionData();
-            sub1.setFeedUrl("test_url1");
+            sub1.setFeedURL("test_url1");
             planet.saveSubscription(sub1);
             
             List subs = new ArrayList();
@@ -193,7 +193,7 @@
         
         {   // save subscription
             PlanetSubscriptionData sub = new PlanetSubscriptionData();
-            sub.setFeedUrl("test_url");
+            sub.setFeedURL("test_url");
             planet.saveSubscription(sub);
             TestUtils.endSession(true);
         }
@@ -278,7 +278,7 @@
             planet.saveGroup(group);
             
             PlanetSubscriptionData sub = new PlanetSubscriptionData();
-            sub.setFeedUrl(feed_url1);
+            sub.setFeedURL(feed_url1);
             planet.saveSubscription(sub);
             
             group.addSubscription(sub);
@@ -323,11 +323,11 @@
                 planet.saveGroup(group);
                 
                 PlanetSubscriptionData sub1 = new PlanetSubscriptionData();
-                sub1.setFeedUrl(feed_url1);
+                sub1.setFeedURL(feed_url1);
                 planet.saveSubscription(sub1);
                 
                 PlanetSubscriptionData sub2 = new PlanetSubscriptionData();
-                sub2.setFeedUrl(feed_url2);
+                sub2.setFeedURL(feed_url2);
                 planet.saveSubscription(sub2);
                 
                 group.addSubscription(sub1);
@@ -382,10 +382,10 @@
             
             {
                 PlanetSubscriptionData sub1 = new PlanetSubscriptionData();
-                sub1.setFeedUrl(feed_url1);
+                sub1.setFeedURL(feed_url1);
                 planet.saveSubscription(sub1);
                 PlanetSubscriptionData sub2 = new PlanetSubscriptionData();
-                sub2.setFeedUrl(feed_url2);
+                sub2.setFeedURL(feed_url2);
                 planet.saveSubscription(sub2);
                 TestUtils.endSession(true);
                 

Modified: incubator/roller/branches/roller_3.0/tests/org/apache/roller/business/WeblogEntryTest.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/tests/org/apache/roller/business/WeblogEntryTest.java?rev=417044&r1=417043&r2=417044&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/tests/org/apache/roller/business/WeblogEntryTest.java (original)
+++ incubator/roller/branches/roller_3.0/tests/org/apache/roller/business/WeblogEntryTest.java Sun Jun 25 12:33:50 2006
@@ -183,7 +183,7 @@
         
         // get all entries for weblog
         entries = null;
-        entries = mgr.getWeblogEntries(testWeblog, null, null, null, null, null, null, 0, Integer.MAX_VALUE);
+        entries = mgr.getWeblogEntries(testWeblog, null, null, null, null, null, null, 0, -1);
         assertNotNull(entries);
         assertEquals(3, entries.size());
         assertEquals(entry3, entries.get(0));
@@ -196,13 +196,13 @@
         
         // get all published entries only 
         entries = null;
-        entries = mgr.getWeblogEntries(testWeblog, null, null, null, null, WeblogEntryData.PUBLISHED, null, 0, Integer.MAX_VALUE);
+        entries = mgr.getWeblogEntries(testWeblog, null, null, null, null, WeblogEntryData.PUBLISHED, null, 0, -1);
         assertNotNull(entries);
         assertEquals(2, entries.size());
         
         // get all entries in date range
         entries = null;
-        entries = mgr.getWeblogEntries(testWeblog, null, entry2.getPubTime(), entry2.getPubTime(), null, null, null, 0, Integer.MAX_VALUE);
+        entries = mgr.getWeblogEntries(testWeblog, null, entry2.getPubTime(), entry2.getPubTime(), null, null, null, 0, -1);
         assertNotNull(entries);
         assertEquals(1, entries.size());
         assertEquals(entry2, entries.get(0));
@@ -215,15 +215,15 @@
         
         // get all entries in category
         entries = null;
-        entries = mgr.getWeblogEntries(testWeblog, null, null, null, testWeblog.getDefaultCategory().getName(), null, null, 0, Integer.MAX_VALUE);
+        entries = mgr.getWeblogEntries(testWeblog, null, null, null, testWeblog.getDefaultCategory().getName(), null, null, 0, -1);
         assertNotNull(entries);
         assertEquals(3, entries.size());
         
         // get all entries, limited by offset/range
         entries = null;
-        entries = mgr.getWeblogEntries(testWeblog, null, null, null, null, null, null, 0, Integer.MAX_VALUE);
+        entries = mgr.getWeblogEntries(testWeblog, null, null, null, null, null, null, 1, 1);
         assertNotNull(entries);
-        assertEquals(2, entries.size());
+        assertEquals(1, entries.size());
         assertEquals(entry2, entries.get(0));
         
         // get pinned entries only

Modified: incubator/roller/branches/roller_3.0/tests/org/apache/roller/business/WeblogStatsTest.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/tests/org/apache/roller/business/WeblogStatsTest.java?rev=417044&r1=417043&r2=417044&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/tests/org/apache/roller/business/WeblogStatsTest.java (original)
+++ incubator/roller/branches/roller_3.0/tests/org/apache/roller/business/WeblogStatsTest.java Sun Jun 25 12:33:50 2006
@@ -55,7 +55,7 @@
     }
     public void testGetMostCommentedWeblogs() throws Exception {        
         UserManager mgr = RollerFactory.getRoller().getUserManager();      
-        List list = mgr.getMostCommentedWebsites(null, null, 0, Integer.MAX_VALUE);  
+        List list = mgr.getMostCommentedWebsites(null, null, 0, -1);  
         
         assertNotNull(list);
         assertEquals(2, list.size());
@@ -70,7 +70,7 @@
     }
     public void testGetMostCommentedWeblogEntries() throws Exception {        
         WeblogManager mgr = RollerFactory.getRoller().getWeblogManager();      
-        List list = mgr.getMostCommentedWeblogEntries(null, null, null, 0, Integer.MAX_VALUE);
+        List list = mgr.getMostCommentedWeblogEntries(null, null, null, 0, -1);
         
         assertNotNull(list);
         assertEquals(3, list.size());

Modified: incubator/roller/branches/roller_3.0/tests/org/apache/roller/business/WeblogTest.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/tests/org/apache/roller/business/WeblogTest.java?rev=417044&r1=417043&r2=417044&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/tests/org/apache/roller/business/WeblogTest.java (original)
+++ incubator/roller/branches/roller_3.0/tests/org/apache/roller/business/WeblogTest.java Sun Jun 25 12:33:50 2006
@@ -180,7 +180,7 @@
         
         // get all weblogs for user
         weblog = null;
-        List weblogs1 = mgr.getWebsites(testUser, Boolean.TRUE, Boolean.TRUE, null, null, 0, Integer.MAX_VALUE);
+        List weblogs1 = mgr.getWebsites(testUser, Boolean.TRUE, Boolean.TRUE, null, null, 0, -1);
         assertEquals(2, weblogs1.size());
         weblog = (WebsiteData) weblogs1.get(0);
         assertNotNull(weblog);
@@ -195,7 +195,7 @@
         weblog.setEnabled(Boolean.FALSE);
         mgr.saveWebsite(weblog);
         TestUtils.endSession(true);
-        List weblogs2 = mgr.getWebsites(testUser, Boolean.TRUE, Boolean.TRUE, null, null, 0, Integer.MAX_VALUE);
+        List weblogs2 = mgr.getWebsites(testUser, Boolean.TRUE, Boolean.TRUE, null, null, 0, -1);
         assertEquals(1, weblogs2.size());
         weblog = (WebsiteData) weblogs2.get(0);
         assertNotNull(weblog);
@@ -204,7 +204,7 @@
         weblog.setActive(Boolean.FALSE);
         mgr.saveWebsite(weblog);
         TestUtils.endSession(true);
-        List weblogs3 = mgr.getWebsites(testUser, Boolean.TRUE, Boolean.TRUE, null, null, 0, Integer.MAX_VALUE);
+        List weblogs3 = mgr.getWebsites(testUser, Boolean.TRUE, Boolean.TRUE, null, null, 0, -1);
         assertEquals(0, weblogs3.size());
         
         // remove test weblogs

Copied: incubator/roller/branches/roller_3.0/tests/org/apache/roller/ui/MockPrincipal.java (from r416919, incubator/roller/branches/roller_3.0/tests/org/apache/roller/ui/core/MockPrincipal.java)
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/tests/org/apache/roller/ui/MockPrincipal.java?p2=incubator/roller/branches/roller_3.0/tests/org/apache/roller/ui/MockPrincipal.java&p1=incubator/roller/branches/roller_3.0/tests/org/apache/roller/ui/core/MockPrincipal.java&r1=416919&r2=417044&rev=417044&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/tests/org/apache/roller/ui/core/MockPrincipal.java (original)
+++ incubator/roller/branches/roller_3.0/tests/org/apache/roller/ui/MockPrincipal.java Sun Jun 25 12:33:50 2006
@@ -1,34 +1,33 @@
 /*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-*  contributor license agreements.  The ASF licenses this file to You
-* 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.  For additional information regarding
-* copyright in this work, please see the NOTICE file in the top level
-* directory of this distribution.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * 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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
 /*
  * Created on Mar 8, 2004
  */
-package org.apache.roller.ui.core;
+package org.apache.roller.ui;
+
+import java.security.Principal;
 
-public class MockPrincipal implements java.security.Principal
-{
+public class MockPrincipal implements Principal {
     String mName;
-    public MockPrincipal(String name)
-    {
+    public MockPrincipal(String name) {
         mName = name;
     }
-    public String getName()
-    {
+    public String getName() {
         return mName;
     }
 }

Copied: incubator/roller/branches/roller_3.0/tests/org/apache/roller/ui/MockRollerContext.java (from r416919, incubator/roller/branches/roller_3.0/tests/org/apache/roller/ui/core/MockRollerContext.java)
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/tests/org/apache/roller/ui/MockRollerContext.java?p2=incubator/roller/branches/roller_3.0/tests/org/apache/roller/ui/MockRollerContext.java&p1=incubator/roller/branches/roller_3.0/tests/org/apache/roller/ui/core/MockRollerContext.java&r1=416919&r2=417044&rev=417044&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/tests/org/apache/roller/ui/core/MockRollerContext.java (original)
+++ incubator/roller/branches/roller_3.0/tests/org/apache/roller/ui/MockRollerContext.java Sun Jun 25 12:33:50 2006
@@ -1 +1 @@
-/*
* Licensed to the Apache Software Foundation (ASF) under one or more
*  contributor license agreements.  The ASF licenses this file to You
* 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.  For additional information regarding
* copyright in this work, please see the NOTICE file in the top level
* directory of this distribution.
*/
/*
 * Created on Mar 4, 2004
 */
package org.apache.roller.ui.core;
import java.io.File;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
 
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.roller.RollerException;

/**
 * @author lance.lavandowska
 */
public class MockRollerContext extends RollerContext
{
    private static Log mLogger =
        LogFactory.getFactory().getInstance(MockRollerContext.class);
    private static ServletContext mContext = null;
    public void init(ServletContext sc)
    {
        mLogger.debug("MockRollerContext initializing");
        
        // initialize super 
        super.contextInitialized(new ServletContextEvent(sc));
        
        // Save context in self and self in context
        mContext = sc;
        mContext.setAttribute(ROLLER_CONTEXT, this);
        mContext.setAttribute("org.apache.roller.absoluteContextURL", "/");
    }
    //-----------------------------------------------------------------------
    /** Because I cannot set the super's values, I have to
     * o
 veride the methods as well */  
    public static RollerContext getRollerContext()
    {
        // get roller from servlet context
        return (RollerContext) mContext.getAttribute(ROLLER_CONTEXT);
    }
    //-----------------------------------------------------------------------
    /** Because I cannot set the super's values, I have to
     * overide the methods as well */  
    public static ServletContext getServletContext()
    {
        return mContext;
    }

    //-----------------------------------------------------------------------
    /** Because I cannot set the super's values, I have to
     * overide the methods as well */
    public String getRollerVersion()
    {
        return super.getRollerVersion();
    }
    //-----------------------------------------------------------------------
    /** Because I cannot set the super's values, I have to
     * overide the methods as well */
    public String getRollerBuildTime()
    {
        return super.getRoll
 erBuildTime();
    }
    //-----------------------------------------------------------------------
    /** Because I cannot set the super's values, I have to
     * overide the methods as well */
    public String getRollerBuildUser()
    {
        return super.getRollerBuildUser();
    }

    //-----------------------------------------------------------------------
    /** Because I cannot set the super's values, I have to
     * overide the methods as well */
    public String getAbsoluteContextUrl()
    {
        return "";
    }
    //-----------------------------------------------------------------------
    /** Because I cannot set the super's values, I have to
     * overide the methods as well */
    public String getAbsoluteContextUrl(HttpServletRequest request)
    {
        return request.getScheme() +"://" + request.getServerName() + "";
    }
    //-----------------------------------------------------------------------
    /** Because I cannot set the super's va
 lues, I have to
     * overide the methods as well */
    /* not available anymore ... use the new config classes instead -- Allen G
    public RollerConfigData getRollerConfig()
    {
        return super.getRollerConfig();
    }
    */
    //------------------------------------------------------------------------
    public String getConfigPath() 
    {
        String root = System.getProperty("ro.build");
        String configPath =
            root
                + File.separator
                + "roller"
                + File.separator
                + "WEB-INF"
                + File.separator
                + "roller-config.xml";
        return configPath;
    }
    protected void upgradeDatabaseIfNeeded() throws RollerException
    {
        // for now, this is a no-op
    }

}
\ No newline at end of file
+/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  The ASF licenses this file to You
 * 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.  For additional information regarding
 * copyright in this work, please see the NOTICE file in the top level
 * directory of this distribution.
 */
/*
 * Created on Mar 4, 2004
 */
package org.apache.roller.ui;
import java.io.File;

import javax.servlet.ServletContext;
import javax.servlet.ServletC
 ontextEvent;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.roller.RollerException;
import org.apache.roller.ui.core.*;

/**
 * @author lance.lavandowska
 */
public class MockRollerContext extends RollerContext {
    private static Log mLogger =
            LogFactory.getFactory().getInstance(MockRollerContext.class);
    
    private static ServletContext mContext = null;
    
    public void init(ServletContext sc) {
        mLogger.debug("MockRollerContext initializing");
        
        // initialize super
        super.contextInitialized(new ServletContextEvent(sc));
        
        // Save context in self and self in context
        mContext = sc;
        mContext.setAttribute(ROLLER_CONTEXT, this);
        mContext.setAttribute("org.apache.roller.absoluteContextURL", "/");
    }
    //-----------------------------------------------------------------------
    /** B
 ecause I cannot set the super's values, I have to
     * overide the methods as well */
    public static RollerContext getRollerContext() {
        // get roller from servlet context
        return (RollerContext) mContext.getAttribute(ROLLER_CONTEXT);
    }
    //-----------------------------------------------------------------------
    /** Because I cannot set the super's values, I have to
     * overide the methods as well */
    public static ServletContext getServletContext() {
        return mContext;
    }
    
    //-----------------------------------------------------------------------
    /** Because I cannot set the super's values, I have to
     * overide the methods as well */
    public String getRollerVersion() {
        return super.getRollerVersion();
    }
    //-----------------------------------------------------------------------
    /** Because I cannot set the super's values, I have to
     * overide the methods as well */
    public String getRoller
 BuildTime() {
        return super.getRollerBuildTime();
    }
    //-----------------------------------------------------------------------
    /** Because I cannot set the super's values, I have to
     * overide the methods as well */
    public String getRollerBuildUser() {
        return super.getRollerBuildUser();
    }
    
    //-----------------------------------------------------------------------
    /** Because I cannot set the super's values, I have to
     * overide the methods as well */
    public String getAbsoluteContextUrl() {
        return "";
    }
    //-----------------------------------------------------------------------
    /** Because I cannot set the super's values, I have to
     * overide the methods as well */
    public String getAbsoluteContextUrl(HttpServletRequest request) {
        return "http://localhost:8080/roller";
    }
    //-----------------------------------------------------------------------
    /** Because I cannot set the sup
 er's values, I have to
     * overide the methods as well */
    /* not available anymore ... use the new config classes instead -- Allen G
    public RollerConfigData getRollerConfig()
    {
        return super.getRollerConfig();
    }
     */
    //------------------------------------------------------------------------
    public String getConfigPath() {
        String root = System.getProperty("ro.build");
        String configPath =
                root
                + File.separator
                + "roller"
                + File.separator
                + "WEB-INF"
                + File.separator
                + "roller-config.xml";
        return configPath;
    }
    protected void upgradeDatabaseIfNeeded() throws RollerException {
        // for now, this is a no-op
    }
    
}
\ No newline at end of file

Added: incubator/roller/branches/roller_3.0/tests/org/apache/roller/ui/ServletTestBase.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/tests/org/apache/roller/ui/ServletTestBase.java?rev=417044&view=auto
==============================================================================
--- incubator/roller/branches/roller_3.0/tests/org/apache/roller/ui/ServletTestBase.java (added)
+++ incubator/roller/branches/roller_3.0/tests/org/apache/roller/ui/ServletTestBase.java Sun Jun 25 12:33:50 2006
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * 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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.roller.ui;
+
+import com.mockrunner.mock.web.ActionMockObjectFactory;
+import com.mockrunner.mock.web.MockHttpServletRequest;
+import com.mockrunner.mock.web.MockServletConfig;
+import com.mockrunner.mock.web.MockServletContext;
+import com.mockrunner.mock.web.WebMockObjectFactory;
+import com.mockrunner.servlet.ServletTestModule;
+import com.mockrunner.struts.ActionTestModule;
+import com.mockrunner.struts.MapMessageResources;
+
+import java.io.FileInputStream;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+import javax.servlet.jsp.JspEngineInfo;
+import javax.servlet.jsp.JspFactory;
+import javax.servlet.jsp.PageContext;
+
+import junit.framework.TestCase;
+import org.apache.roller.ui.core.filters.PersistenceSessionFilter;
+import org.apache.roller.ui.core.filters.RequestFilter;
+
+
+/**
+ * Base class for Roller Servlet tests with setup method that creates required 
+ * MockRunner mocks for Servlet context, request and JSP factory objects.
+ */
+public abstract class ServletTestBase extends TestCase {
+    protected ServletTestModule servletModule;
+    private WebMockObjectFactory mockFactory;
+    protected MockRollerContext rollerContext;
+    protected ActionTestModule strutsModule; // need Struts for message resources
+    
+    public void setUp() throws Exception {
+        getMockFactory().refresh();
+        
+        servletModule = new ServletTestModule(getMockFactory());
+        strutsModule = new ActionTestModule(getStrutsMockFactory());
+        
+        MockServletContext ctx = getMockFactory().getMockServletContext();
+        ctx.setServletContextName("/roller"); 
+        ctx.setRealPath("/", "");        
+        rollerContext = new MockRollerContext();
+        rollerContext.init(ctx);
+        
+        MockHttpServletRequest request = getMockFactory().getMockRequest();
+        request.setContextPath("/roller");
+        
+        JspFactory.setDefaultFactory(new MockJspFactory(getMockFactory()));
+        
+        // setup resources needed for running Velocity
+        MockServletContext app = getMockFactory().getMockServletContext();
+        app.addResourcePath("/WEB-INF/toolbox.xml","/WEB-INF/toolbox.xml");
+        app.setResourceAsStream(
+                "/WEB-INF/toolbox.xml", 
+                new FileInputStream("./WEB-INF/toolbox.xml"));        
+        MockServletConfig config = getMockFactory().getMockServletConfig();
+        config.setInitParameter(
+                "org.apache.velocity.properties","WEB-INF/velocity.properties");        
+        MapMessageResources resources = new MapMessageResources();
+        resources.putMessages(
+                "WEB-INF/classes/ApplicationResources.properties");
+        strutsModule.setResources(resources);
+    }
+    
+    /** Convenience method for placing username in role via mockRequest. */
+    protected void authenticateUser(String username, String role) {
+        MockHttpServletRequest mockRequest = getMockFactory().getMockRequest();
+        mockRequest.setRemoteUser(username);
+        mockRequest.setUserPrincipal(new MockPrincipal(username));
+        mockRequest.setUserInRole(role, true);
+    }
+    
+    /** Run request through Roller filters (PersistenceSessionFilter and RequestFilter) */
+    protected void doFilters() {
+        servletModule.createFilter(PersistenceSessionFilter.class);
+        servletModule.createFilter(RequestFilter.class);
+        servletModule.setDoChain(false);
+        servletModule.doFilter();
+        getMockFactory().addRequestWrapper(new HttpServletRequestWrapper(
+                (HttpServletRequest)servletModule.getFilteredRequest()));
+    }
+
+    protected ActionMockObjectFactory getStrutsMockFactory() {
+        return (ActionMockObjectFactory)getMockFactory();
+    }
+    
+    protected WebMockObjectFactory getMockFactory() {
+        if (mockFactory == null) {
+            mockFactory = new ActionMockObjectFactory();
+        }
+        return mockFactory;
+    }
+
+    /** MockRunner doesn't have one of these, but Roller rendering process needs one. */
+    public class MockJspFactory extends JspFactory {
+        
+        public WebMockObjectFactory factory;
+        
+        public MockJspFactory(WebMockObjectFactory factory) {
+            this.factory = factory;
+        }
+        
+        public PageContext getPageContext(
+                Servlet arg0, 
+                ServletRequest arg1, 
+                ServletResponse arg2,
+                String arg3, 
+                boolean arg4, 
+                int arg5, 
+                boolean arg6) {
+            return factory.getMockPageContext();
+        }
+        
+        public void releasePageContext(PageContext arg0) {}
+        
+        public JspEngineInfo getEngineInfo() {return null;}
+    }
+}

Modified: incubator/roller/branches/roller_3.0/tests/org/apache/roller/ui/StrutsActionTestBase.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/tests/org/apache/roller/ui/StrutsActionTestBase.java?rev=417044&r1=417043&r2=417044&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/tests/org/apache/roller/ui/StrutsActionTestBase.java (original)
+++ incubator/roller/branches/roller_3.0/tests/org/apache/roller/ui/StrutsActionTestBase.java Sun Jun 25 12:33:50 2006
@@ -1,30 +1,22 @@
 /*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-*  contributor license agreements.  The ASF licenses this file to You
-* 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.  For additional information regarding
-* copyright in this work, please see the NOTICE file in the top level
-* directory of this distribution.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * 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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
 package org.apache.roller.ui;
 
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletRequestWrapper;
-import javax.servlet.http.HttpSession;
-
-import org.apache.roller.RollerException;
-import org.apache.roller.RollerTestBase;
-import org.apache.roller.model.UserManager;
-import org.apache.roller.pojos.UserData;
 
 import com.mockrunner.mock.web.ActionMockObjectFactory;
 import com.mockrunner.mock.web.MockHttpServletRequest;
@@ -33,30 +25,40 @@
 import com.mockrunner.servlet.ServletTestModule;
 import com.mockrunner.struts.ActionTestModule;
 import com.mockrunner.struts.MapMessageResources;
-import org.apache.roller.ui.core.MockPrincipal;
-import org.apache.roller.ui.core.MockRollerContext;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+import javax.servlet.http.HttpSession;
+
+import junit.framework.TestCase;
+
+import org.apache.roller.RollerException;
+import org.apache.roller.model.RollerFactory;
+import org.apache.roller.model.UserManager;
+import org.apache.roller.pojos.UserData;
+import org.apache.roller.ui.MockPrincipal;
+import org.apache.roller.ui.MockRollerContext;
 import org.apache.roller.ui.core.RollerSession;
 import org.apache.roller.ui.core.filters.PersistenceSessionFilter;
 import org.apache.roller.ui.core.filters.RequestFilter;
 
-/** 
- * Base for Struts Action testing. 
- * @author Dave Johnson
+/**
+ * Base class for Roller action tests with setup method that creates required 
+ * MockRunner mocks for Servlet context and request objects.
  */
-public class StrutsActionTestBase extends RollerTestBase
-{     
+public class StrutsActionTestBase extends TestCase {
     private ActionMockObjectFactory mockFactory;
     protected MockRollerContext rollerContext;
     protected ActionTestModule strutsModule;
     protected ServletTestModule servletModule;
-
-    public void setUp() throws Exception
-    {
-        super.setUp();       
+    
+    public void setUp() throws Exception {
         getMockFactory().refresh();
-        strutsModule = new ActionTestModule(getStrutsMockFactory()); 
+        
+        strutsModule = new ActionTestModule(getStrutsMockFactory());
         servletModule = new ServletTestModule(getStrutsMockFactory());
         
+        // Setup mocks needed to run a Struts action 
         MapMessageResources resources = new MapMessageResources();
         resources.putMessages("WEB-INF/classes/ApplicationResources.properties");
         strutsModule.setResources(resources);
@@ -66,40 +68,39 @@
         rollerContext = new MockRollerContext();
         rollerContext.init(ctx);
     }
-    protected void authenticateUser(String username, String role) 
-        throws RollerException
-    {
+    
+    protected void authenticateUser(String username, String role)
+        throws RollerException {
+        
         MockHttpServletRequest mockRequest = getMockFactory().getMockRequest();
         mockRequest.setRemoteUser(username);
         mockRequest.setUserPrincipal(new MockPrincipal(username));
         mockRequest.setUserInRole(role, true);
         
-        HttpSession session = mockRequest.getSession(true);        
-        UserManager umgr = getRoller().getUserManager();
+        HttpSession session = mockRequest.getSession(true);
+        UserManager umgr = RollerFactory.getRoller().getUserManager();
         UserData user = umgr.getUserByUserName(username);
-
+        
         RollerSession rollerSession = new RollerSession();
         rollerSession.setAuthenticatedUser(user);
         session.setAttribute(RollerSession.ROLLER_SESSION, rollerSession);
     }
     
-    protected void doFilters()
-    {
+    protected void doFilters() {
         servletModule.createFilter(PersistenceSessionFilter.class);
         servletModule.createFilter(RequestFilter.class);
         servletModule.setDoChain(true);
-        servletModule.doFilter();        
+        servletModule.doFilter();
         getMockFactory().addRequestWrapper(new HttpServletRequestWrapper(
-            (HttpServletRequest)servletModule.getFilteredRequest()));
+                (HttpServletRequest)servletModule.getFilteredRequest()));
     }
-    protected ActionMockObjectFactory getStrutsMockFactory()
-    {
+    
+    protected ActionMockObjectFactory getStrutsMockFactory() {
         return (ActionMockObjectFactory)getMockFactory();
     }
-    protected WebMockObjectFactory getMockFactory()
-    {
-        if (mockFactory == null) 
-        {
+    
+    protected WebMockObjectFactory getMockFactory() {
+        if (mockFactory == null) {
             mockFactory = new ActionMockObjectFactory();
         }
         return mockFactory;



Mime
View raw message