FileDocCategorySizeDatePackage
DateLayoutTest.javaAPI DocApache log4j 1.2.157882Sat Aug 25 00:09:32 BST 2007org.apache.log4j.helpers

DateLayoutTest

public class DateLayoutTest extends org.apache.log4j.LayoutTest
Tests for DateLayout.

Fields Summary
Constructors Summary
public DateLayoutTest(String testName)
Construct a new instance of LayoutTest.

param
testName test name.

    super(testName);
  
protected DateLayoutTest(String testName, String expectedContentType, boolean expectedIgnoresThrowable, String expectedHeader, String expectedFooter)
Constructor for use by derived tests.

param
testName name of test.
param
expectedContentType expected value for getContentType().
param
expectedIgnoresThrowable expected value for ignoresThrowable().
param
expectedHeader expected value for getHeader().
param
expectedFooter expected value for getFooter().

    super(
      testName, expectedContentType, expectedIgnoresThrowable, expectedHeader,
      expectedFooter);
  
Methods Summary
protected org.apache.log4j.LayoutcreateLayout()

{inheritDoc}

    return new MockLayout();
  
public voidtestActivateOptions()
Tests activateOptions.

    DateLayout layout = (DateLayout) createLayout();
    layout.setDateFormat("HH:mm:ss");
    layout.setTimeZone("+05:00");
    layout.activateOptions();
  
public voidtestDateFormatOption()
Tests DateLayout.DATE_FORMAT_OPTION constant.

deprecated
since constant is deprecated

    assertEquals("DateFormat", DateLayout.DATE_FORMAT_OPTION);
  
public voidtestDateTimeFormat()
Tests DateTimeDateFormat class.

deprecated
since DateTimeDateFormat is deprecated

      DateFormat format = new DateTimeDateFormat();
      Calendar calendar = Calendar.getInstance();
      calendar.clear();
      calendar.set(1970, 0, 1, 0, 0, 0);
      String actual = format.format(calendar.getTime());
      SimpleDateFormat df = new SimpleDateFormat("dd MMM yyyy HH:mm:ss,SSS");
      String expected = df.format(calendar.getTime());
      assertEquals(expected, actual);
  
public voidtestGetOptionStrings()
Tests getOptionStrings().

deprecated
since getOptionStrings is deprecated.

    String[] options = ((DateLayout) createLayout()).getOptionStrings();
    assertEquals(2, options.length);
  
public voidtestISO8601Format()
Tests IS08601DateFormat class.

deprecated
since ISO8601DateFormat is deprecated

      DateFormat format = new ISO8601DateFormat();
      Calendar calendar = Calendar.getInstance();
      calendar.clear();
      calendar.set(1970, 0, 1, 0, 0, 0);
      String actual = format.format(calendar.getTime());
      assertEquals("1970-01-01 00:00:00,000", actual);
  
public voidtestNullDateFormat()
Tests DateLayout.NULL_DATE_FORMAT constant.

    assertEquals("NULL", DateLayout.NULL_DATE_FORMAT);
  
public voidtestRelativeTimeDateFormat()
Tests DateLayout.RELATIVE constant.

    assertEquals("RELATIVE", DateLayout.RELATIVE_TIME_DATE_FORMAT);
  
public voidtestSetDateFormat()
Tests setDateFormat.

    DateLayout layout = (DateLayout) createLayout();
    layout.setDateFormat("ABSOLUTE");
    assertEquals("ABSOLUTE", layout.getDateFormat());
  
public voidtestSetDateFormatAbsolute()
Tests 2 parameter setDateFormat with "ABSOLUTE".

    DateLayout layout = (DateLayout) createLayout();
    layout.setDateFormat("aBsolUte", TimeZone.getDefault());
  
public voidtestSetDateFormatDateTime()
Tests 2 parameter setDateFormat with "DATETIME".

    DateLayout layout = (DateLayout) createLayout();
    layout.setDateFormat("dAte", TimeZone.getDefault());
  
public voidtestSetDateFormatISO8601()
Tests 2 parameter setDateFormat with "ISO8601".

    DateLayout layout = (DateLayout) createLayout();
    layout.setDateFormat("iSo8601", TimeZone.getDefault());
  
public voidtestSetDateFormatNull()
Tests 2 parameter setDateFormat with null.

    DateLayout layout = (DateLayout) createLayout();
    layout.setDateFormat((String) null, null);
  
public voidtestSetDateFormatNullString()
Tests 2 parameter setDateFormat with "NULL".

    DateLayout layout = (DateLayout) createLayout();
    layout.setDateFormat("NuLL", null);
  
public voidtestSetDateFormatRelative()
Tests 2 parameter setDateFormat with "RELATIVE".

    DateLayout layout = (DateLayout) createLayout();
    layout.setDateFormat("rElatIve", TimeZone.getDefault());
  
public voidtestSetDateFormatSimple()
Tests 2 parameter setDateFormat with "HH:mm:ss".

    DateLayout layout = (DateLayout) createLayout();
    layout.setDateFormat("HH:mm:ss", TimeZone.getDefault());
  
public voidtestSetDateFormatWithFormat()
Tests setDateFormat(DateFormat, TimeZone).

    DateFormat format = new SimpleDateFormat("HH:mm");
    DateLayout layout = (DateLayout) createLayout();
    layout.setDateFormat(format, TimeZone.getDefault());
  
public voidtestSetOptionDateFormat()
Tests setting DateFormat through setOption method.

deprecated
since setOption is deprecated.

    DateLayout layout = (DateLayout) createLayout();
    layout.setOption("dAtefOrmat", "foobar");
    assertEquals("FOOBAR", layout.getDateFormat());
  
public voidtestSetOptionTimeZone()
Tests setting TimeZone through setOption method.

deprecated
since setOption is deprecated.

    DateLayout layout = (DateLayout) createLayout();
    layout.setOption("tImezOne", "+05:00");
    assertEquals("+05:00", layout.getTimeZone());
  
public voidtestSetTimeZone()
Tests setTimeZone.

    DateLayout layout = (DateLayout) createLayout();
    layout.setTimeZone("+05:00");
    assertEquals("+05:00", layout.getTimeZone());
  
public voidtestTimeZoneOption()
Tests DateLayout.TIMEZONE_OPTION constant.

deprecated
since constant is deprecated

    assertEquals("TimeZone", DateLayout.TIMEZONE_OPTION);