/* ======================================================================
   Parts Copyright 2006 University of Leeds, Oxford University, University of the Highlands and Islands.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

====================================================================== */

package org.bodington.logging;

import junit.framework.TestCase;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.spi.LoggingEvent;

/**
 * @author buckett
 */
public class SimpleThrowableLayoutTest extends TestCase
{

    /*
     * Class under test for String format(LoggingEvent)
     */
    public void testFormatLoggingEvent()
    {
        SimpleThrowableLayout layout = new SimpleThrowableLayout();

        LoggingEvent event = new LoggingEvent(this.getName(), Logger.getRootLogger(), Level.INFO,"@@Log Message@@",null);
        String output = layout.format(event);
        
        assertTrue(output.indexOf("@@Test Message@@") == -1);
        assertTrue(output.indexOf("@@Log Message@@") > 0);

        Throwable throwable = new Throwable("@@Test Message@@");
        event = new LoggingEvent(this.getName(), Logger.getRootLogger(), Level.INFO,"@@Log Message@@",throwable);
        output = layout.format(event);
        
        assertTrue(output.indexOf("@@Test Message@@") > 0);
        assertTrue(output.indexOf("@@Log Message@@") > 0);
    }

    public void testThrowableFormat()
    {
        SimpleThrowableLayout layout = new SimpleThrowableLayout();
        Throwable throwable = new Throwable("@@Test Message@@");
        StringBuffer output = new StringBuffer();
        layout.throwableFormat(output, throwable);
        
        assertTrue(output.indexOf("@@Test Message@@") > 0);
        assertTrue(output.indexOf("testThrowableFormat") > 0);
    }

}
