FileDocCategorySizeDatePackage
PolicyLoggerTest.javaAPI DocExample11959Tue May 29 16:57:40 BST 2007com.sun.xml.ws.policy.privateutil

PolicyLoggerTest

public class PolicyLoggerTest extends TestCase
author
Marek Potociar (marek.potociar at sun.com)

Fields Summary
private PolicyLogger
instance
Constructors Summary
public PolicyLoggerTest(String testName)

        super(testName);
    
Methods Summary
protected voidsetUp()

        instance = PolicyLogger.getLogger(PolicyLoggerTest.class);
    
protected voidtearDown()

    
public voidtestCommonsCreateAndLogException()
Test of createAndLogException method, of class com.sun.xml.ws.policy.privateutil.PolicyUtils.Commons.

        PolicyLogger logger = PolicyLogger.getLogger(PolicyLoggerTest.class);
        Throwable cause, result;
        String message;
        
        cause = new Exception();
        message = "Test message.";
        result = logger.logSevereException(new IllegalArgumentException(message), cause);
        assertEquals(message, result.getMessage());
        assertEquals(cause, result.getCause());
        assertEquals("testCommonsCreateAndLogException", result.getStackTrace()[0].getMethodName());
        
        message = "Test message.";
        result = logger.logSevereException(new NullPointerException(message), cause);
        assertEquals(message, result.getMessage());
        assertEquals(cause, result.getCause());
        assertEquals("testCommonsCreateAndLogException", result.getStackTrace()[0].getMethodName());
        
        message = null;
        result = logger.logSevereException(new PolicyException(message), true);
        assertEquals(message, result.getMessage());
        assertEquals(null, result.getCause());
        assertEquals("testCommonsCreateAndLogException", result.getStackTrace()[0].getMethodName());
        
        message = "Test message.";
        result = logger.logSevereException(new PolicyException(message), false);
        assertEquals(message, result.getMessage());
        assertEquals(null, result.getCause());
        assertEquals("testCommonsCreateAndLogException", result.getStackTrace()[0].getMethodName());
        
        cause = new NullPointerException("test");
        message = null;
        result = logger.logSevereException(new PolicyException(message, cause), true);
        assertEquals(message, result.getMessage());
        assertEquals(cause, result.getCause());
        assertEquals("testCommonsCreateAndLogException", result.getStackTrace()[0].getMethodName());
        
        cause = new NullPointerException("test");
        message = "Test message.";
        result = logger.logSevereException(new PolicyException(message, cause), false);
        assertEquals(message, result.getMessage());
        assertEquals(cause, result.getCause());
        assertEquals("testCommonsCreateAndLogException", result.getStackTrace()[0].getMethodName());
        
        message = null;
        result = logger.logSevereException(new PolicyException(message));
        assertEquals(message, result.getMessage());
        assertEquals(null, result.getCause());
        assertEquals("testCommonsCreateAndLogException", result.getStackTrace()[0].getMethodName());
        
        message = "Test message.";
        result = logger.logSevereException(new PolicyException(message));
        assertEquals(message, result.getMessage());
        assertEquals(null, result.getCause());
        assertEquals("testCommonsCreateAndLogException", result.getStackTrace()[0].getMethodName());
        
        cause = new NullPointerException("test");
        message = null;
        result = logger.logSevereException(new PolicyException(message, cause));
        assertEquals(message, result.getMessage());
        assertEquals(cause, result.getCause());
        assertEquals("testCommonsCreateAndLogException", result.getStackTrace()[0].getMethodName());
        
        cause = new NullPointerException("test");
        message = "Test message.";
        result = logger.logSevereException(new PolicyException(message, cause));
        assertEquals(message, result.getMessage());
        assertEquals(cause, result.getCause());
        assertEquals("testCommonsCreateAndLogException", result.getStackTrace()[0].getMethodName());
    
public voidtestConfig()
Test of config method, of class com.sun.xml.ws.policy.privateutil.PolicyLogger.

        String message = "Test";
        
        instance.config(message);
    
public voidtestEntering()
Test of entering method, of class com.sun.xml.ws.policy.privateutil.PolicyLogger.

        instance.entering();
    
public voidtestExiting()
Test of exiting method, of class com.sun.xml.ws.policy.privateutil.PolicyLogger.

        instance.exiting();
    
public voidtestFine()
Test of fine method, of class com.sun.xml.ws.policy.privateutil.PolicyLogger.

        String message = "Test";
        
        instance.fine(message);
    
public voidtestFiner()
Test of finer method, of class com.sun.xml.ws.policy.privateutil.PolicyLogger.

        String message = "Test";
        
        instance.finer(message);
    
public voidtestFinest()
Test of finest method, of class com.sun.xml.ws.policy.privateutil.PolicyLogger.

        String message = "Test";
        
        instance.finest(message);
    
public voidtestGetLogger()
Test of getLogger method, of class com.sun.xml.ws.policy.privateutil.PolicyLogger.

        PolicyLogger result = PolicyLogger.getLogger(PolicyLoggerTest.class);
        assertNotNull(result);
        
        try {
            PolicyLogger.getLogger(null);
            fail("NullPointerException expected");
        } catch (NullPointerException e) { /* ok */ }
    
public voidtestInfo()
Test of info method, of class com.sun.xml.ws.policy.privateutil.PolicyLogger.

        String message = "Test";
        
        instance.info(message);
    
public voidtestIsLoggable()
Test of isLoggable method, of class com.sun.xml.ws.policy.privateutil.PolicyLogger.

        boolean expResult, result;
        
        instance.setLevel(Level.ALL);
        expResult = true;
        result = instance.isLoggable(Level.FINEST);
        assertEquals(expResult, result);
        result = instance.isLoggable(Level.FINER);
        assertEquals(expResult, result);
        result = instance.isLoggable(Level.FINE);
        assertEquals(expResult, result);
        result = instance.isLoggable(Level.CONFIG);
        assertEquals(expResult, result);
        result = instance.isLoggable(Level.INFO);
        assertEquals(expResult, result);
        result = instance.isLoggable(Level.WARNING);
        assertEquals(expResult, result);
        result = instance.isLoggable(Level.SEVERE);
        assertEquals(expResult, result);
        result = instance.isLoggable(Level.ALL);
        assertEquals(expResult, result);

        instance.setLevel(Level.OFF);
        expResult = false;
        result = instance.isLoggable(Level.FINEST);
        assertEquals(expResult, result);
        result = instance.isLoggable(Level.FINER);
        assertEquals(expResult, result);
        result = instance.isLoggable(Level.FINE);
        assertEquals(expResult, result);
        result = instance.isLoggable(Level.CONFIG);
        assertEquals(expResult, result);
        result = instance.isLoggable(Level.INFO);
        assertEquals(expResult, result);
        result = instance.isLoggable(Level.WARNING);
        assertEquals(expResult, result);
        result = instance.isLoggable(Level.SEVERE);
        assertEquals(expResult, result);
        result = instance.isLoggable(Level.ALL);
        assertEquals(expResult, result);
    
public voidtestIsMethodCallLoggable()
Test of isMethodCallLoggable method, of class com.sun.xml.ws.policy.privateutil.PolicyLogger.

        boolean expResult = true;
        instance.setLevel(Level.FINEST);
        boolean result = instance.isMethodCallLoggable();
        assertEquals(expResult, result);

        expResult = false;
        instance.setLevel(Level.FINER);
        result = instance.isMethodCallLoggable();
        assertEquals(expResult, result);
    
public voidtestLog()
Test of log method, of class com.sun.xml.ws.policy.privateutil.PolicyLogger.

        Level level = Level.FINEST;
        String message = "Test";
        
        instance.log(level, message);
    
public voidtestSetLevel()
Test of setLevel method, of class com.sun.xml.ws.policy.privateutil.PolicyLogger.

        instance.setLevel(Level.FINE);        
        assertFalse(instance.isLoggable(Level.FINER));
        assertTrue(instance.isLoggable(Level.INFO));
    
public voidtestSevere()
Test of severe method, of class com.sun.xml.ws.policy.privateutil.PolicyLogger.

        String message = "Test";

        instance.severe(message);
    
public voidtestWarning()
Test of warning method, of class com.sun.xml.ws.policy.privateutil.PolicyLogger.

        String message = "Test";
        
        instance.warning(message);