FileDocCategorySizeDatePackage
PatternLayoutTest.javaAPI DocApache log4j 1.2.153986Sat Aug 25 00:09:34 BST 2007org.apache.log4j

PatternLayoutTest

public class PatternLayoutTest extends LayoutTest
Test for PatternLayout.
author
Curt Arnold

Fields Summary
Constructors Summary
public PatternLayoutTest(String testName)
Construct new instance of PatternLayoutTest.

param
testName test name.

    super(testName, "text/plain", true, null, null);
  
Methods Summary
protected org.apache.log4j.LayoutcreateLayout()

{inheritDoc}

    return new PatternLayout("[%t] %p %c - %m%n");
  
public voidtestDefaultConversionPattern()
Tests DEFAULT_CONVERSION_PATTERN constant.

    assertEquals("%m%n", PatternLayout.DEFAULT_CONVERSION_PATTERN);
  
public voidtestFormat()
Tests format.

    Logger logger = Logger.getLogger("org.apache.log4j.LayoutTest");
    LoggingEvent event =
      new LoggingEvent(
        "org.apache.log4j.Logger", logger, Level.INFO, "Hello, World", null);
    PatternLayout layout = (PatternLayout) createLayout();
    String result = layout.format(event);
    StringBuffer buf = new StringBuffer(100);
    buf.append('[");
    buf.append(event.getThreadName());
    buf.append("] ");
    buf.append(event.getLevel().toString());
    buf.append(' ");
    buf.append(event.getLoggerName());
    buf.append(" - ");
    buf.append(event.getMessage());
    buf.append(System.getProperty("line.separator"));
    assertEquals(buf.toString(), result);
  
public voidtestFormatResize()
Tests buffer downsizing code path.

    Logger logger = Logger.getLogger("org.apache.log4j.xml.PatternLayoutTest");
    NDC.clear();

    char[] msg = new char[2000];

    for (int i = 0; i < msg.length; i++) {
      msg[i] = 'A";
    }

    LoggingEvent event1 =
      new LoggingEvent(
        "org.apache.log4j.Logger", logger, Level.DEBUG, new String(msg), null);
    PatternLayout layout = (PatternLayout) createLayout();
    String result = layout.format(event1);
    LoggingEvent event2 =
      new LoggingEvent(
        "org.apache.log4j.Logger", logger, Level.WARN, "Hello, World", null);
    result = layout.format(event2);
    assertEquals("[", result.substring(0, 1));
  
public voidtestGetPatternFormat()
Tests getPatternFormat().

    PatternLayout layout = (PatternLayout) createLayout();
    assertEquals("[%t] %p %c - %m%n", layout.getConversionPattern());
  
public voidtestTTCCConversionPattern()
Tests DEFAULT_CONVERSION_PATTERN constant.

    assertEquals(
      "%r [%t] %p %c %x - %m%n", PatternLayout.TTCC_CONVERSION_PATTERN);