FileDocCategorySizeDatePackage
CLILoggerTest.javaAPI DocGlassfish v2 API5891Fri May 04 22:25:28 BST 2007com.sun.enterprise.cli.framework

CLILoggerTest

public class CLILoggerTest extends TestCase
author
Toby H Ferguson
version
$Revision: 1.5 $

Fields Summary
private static final String
ls
private static final String
m
private static final CLILogger
log
ByteArrayOutputStream
err
ByteArrayOutputStream
out
InputsAndOutputs
io
Constructors Summary
public CLILoggerTest(String name)

        super(name);
    
Methods Summary
public static voidmain(java.lang.String[] args)

        if (args.length == 0){
            junit.textui.TestRunner.run(CLILoggerTest.class);
        } else {
            junit.textui.TestRunner.run(makeSuite(args));
        }
    
private static junit.framework.TestSuitemakeSuite(java.lang.String[] args)

        final TestSuite ts = new TestSuite();
        for (int i = 0; i < args.length; i++){
            ts.addTest(new CLILoggerTest(args[i]));
        }
        return ts;
    
private voidnyi()

        fail("Not Yet Implemented");
    
protected voidsetUp()

        log.setOutputLevel(Level.INFO);
        err = new ByteArrayOutputStream();
        out = new ByteArrayOutputStream();
        io = InputsAndOutputs.getInstance();
        io.setErrorOutput(err);
        io.setUserOutput(out);
    
protected voidtearDown()

    
public voidtestBasicLogging()

        log.printMessage(m);
        assertEquals(m + ls, out.toString());
        assertEquals("", err.toString());
    
public voidtestErrorLogging()

        log.printError(m);
        assertEquals(m + ls, err.toString());
        assertEquals("", out.toString());
    
public voidtestLevelGetSet()

        assertEquals(Level.INFO, log.getOutputLevel());
        log.setOutputLevel(Level.SEVERE);
        assertEquals(Level.SEVERE, log.getOutputLevel());
        
    
public voidtestLevelsBlockOutput()

        log.setOutputLevel(Level.SEVERE);
        log.printMessage(m);
        assertEquals("", out.toString());
        assertEquals("", err.toString());
        log.setOutputLevel(Level.INFO);
        log.printMessage(m);
        assertEquals(m + ls, out.toString());
        assertEquals("", err.toString());
    
public voidtestPrintDebugMessage()

        log.setOutputLevel(Level.FINEST);
        log.printDebugMessage(m);
        assertEquals("", err.toString());
        assertEquals(m + ls, out.toString());
    
public voidtestPrintDetailMessage()

        log.setOutputLevel(Level.FINEST);
        log.printDetailMessage(m);
        assertEquals(m + ls, out.toString());
        assertEquals("", err.toString());
    
public voidtestPrintExceptionStackTrace()


      
        log.setOutputLevel(Level.FINEST);
        final Throwable t = new Throwable(m);
        final StringWriter sw = new StringWriter();
        final PrintWriter pw = new PrintWriter(sw);
        t.printStackTrace(pw);
        log.printExceptionStackTrace(t);
        assertEquals(sw.toString() + ls, out.toString());
        assertEquals("", err.toString());
    
public voidtestPrintWarning()

        log.setOutputLevel(Level.FINEST);
        log.printWarning(m);
        assertEquals(m + ls, out.toString());
        assertEquals("", err.toString());
    
public voidtestSetLevelDoesntWorkUnderDebug()

        assertEquals(Level.INFO, log.getOutputLevel());
        System.setProperty("Debug", "on");
        log.setOutputLevel(Level.SEVERE);
        System.getProperties().remove("Debug");
        assertTrue(Level.SEVERE != log.getOutputLevel());
        assertEquals(Level.INFO, log.getOutputLevel());