FileDocCategorySizeDatePackage
MBeanExceptionFormatterTest.javaAPI DocGlassfish v2 API4817Fri May 04 22:24:18 BST 2007com.sun.enterprise.admin.mbeans

MBeanExceptionFormatterTest

public class MBeanExceptionFormatterTest extends TestCase

Fields Summary
Constructors Summary
public MBeanExceptionFormatterTest(String name)

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

        final TestRunner runner= new TestRunner();
        final TestResult result = runner.doRun(
                MBeanExceptionFormatterTest.suite(), false);
        System.exit(result.errorCount() + result.failureCount());
    
protected voidsetUp()

    
public static junit.framework.Testsuite()

        TestSuite suite = new TestSuite(MBeanExceptionFormatterTest.class);
        return suite;
    
protected voidtearDown()

    
public voidtestMBeanException()

        Exception targetEx = new Exception();
        MBeanException mbe = new MBeanException(targetEx);
        Assert.assertEquals(targetEx, mbe.getTargetException());
        Assert.assertEquals(null, mbe.getCause());
        Assert.assertEquals(null, mbe.getMessage());
        Assert.assertEquals(null, mbe.getTargetException().getMessage());

        targetEx = new Exception("actual message");
        mbe = new MBeanException(targetEx);
        mbe.initCause(targetEx);
        Assert.assertEquals(targetEx, mbe.getCause());
        Assert.assertEquals(null, mbe.getMessage());

        mbe = toMBeanException(null, null);
        Assert.assertEquals(null, mbe.getMessage());
        Assert.assertTrue(null != mbe.getCause());
        Assert.assertTrue(null != mbe.getTargetException());

        mbe = toMBeanException(null, "a");
        Assert.assertEquals("a", mbe.getMessage());

        Exception e = new Exception("b", new Exception("c", new Exception("d")));
        mbe = toMBeanException(e, "a");
        Assert.assertEquals("a(b(c(d)))", mbe.getMessage());
        Assert.assertEquals(e, mbe.getCause());
        Assert.assertEquals(e, mbe.getTargetException());

        mbe = toMBeanException(e, null);
        Assert.assertEquals("b(c(d))", mbe.getMessage());

        e = new Exception();
        mbe = toMBeanException(e, "a");
        Assert.assertEquals("a", mbe.getMessage());

        e = new Exception("b", null);
        mbe = toMBeanException(e, "a");
        Assert.assertEquals("a(b)", mbe.getMessage());

        e = new Exception("b", new Exception(null, new Exception("c")));
        mbe = toMBeanException(e, "a");
        Assert.assertEquals("a(b(c))", mbe.getMessage());
    
javax.management.MBeanExceptiontoMBeanException(java.lang.Exception e, java.lang.String msg)

        return MBeanExceptionFormatter.toMBeanException(e, msg);