1 23 24 27 28 package com.sun.enterprise.admin.mbeans; 29 30 import junit.framework.*; 32 import junit.textui.TestRunner; 33 34 import javax.management.MBeanException ; 36 37 public class MBeanExceptionFormatterTest extends TestCase 38 { 39 public void testMBeanException() 40 { 41 Exception targetEx = new Exception (); 42 MBeanException mbe = new MBeanException (targetEx); 43 Assert.assertEquals(targetEx, mbe.getTargetException()); 44 Assert.assertEquals(null, mbe.getCause()); 45 Assert.assertEquals(null, mbe.getMessage()); 46 Assert.assertEquals(null, mbe.getTargetException().getMessage()); 47 48 targetEx = new Exception ("actual message"); 49 mbe = new MBeanException (targetEx); 50 mbe.initCause(targetEx); 51 Assert.assertEquals(targetEx, mbe.getCause()); 52 Assert.assertEquals(null, mbe.getMessage()); 53 54 mbe = toMBeanException(null, null); 55 Assert.assertEquals(null, mbe.getMessage()); 56 Assert.assertTrue(null != mbe.getCause()); 57 Assert.assertTrue(null != mbe.getTargetException()); 58 59 mbe = toMBeanException(null, "a"); 60 Assert.assertEquals("a", mbe.getMessage()); 61 62 Exception e = new Exception ("b", new Exception ("c", new Exception ("d"))); 63 mbe = toMBeanException(e, "a"); 64 Assert.assertEquals("a(b(c(d)))", mbe.getMessage()); 65 Assert.assertEquals(e, mbe.getCause()); 66 Assert.assertEquals(e, mbe.getTargetException()); 67 68 mbe = toMBeanException(e, null); 69 Assert.assertEquals("b(c(d))", mbe.getMessage()); 70 71 e = new Exception (); 72 mbe = toMBeanException(e, "a"); 73 Assert.assertEquals("a", mbe.getMessage()); 74 75 e = new Exception ("b", null); 76 mbe = toMBeanException(e, "a"); 77 Assert.assertEquals("a(b)", mbe.getMessage()); 78 79 e = new Exception ("b", new Exception (null, new Exception ("c"))); 80 mbe = toMBeanException(e, "a"); 81 Assert.assertEquals("a(b(c))", mbe.getMessage()); 82 } 83 84 MBeanException toMBeanException(final Exception e, final String msg) 85 { 86 return MBeanExceptionFormatter.toMBeanException(e, msg); 87 } 88 89 public MBeanExceptionFormatterTest(String name) throws Exception 90 { 91 super(name); 92 } 93 94 protected void setUp() 95 { 96 } 97 98 protected void tearDown() 99 { 100 } 101 102 public static junit.framework.Test suite() 103 { 104 TestSuite suite = new TestSuite(MBeanExceptionFormatterTest.class); 105 return suite; 106 } 107 108 public static void main(String args[]) throws Exception 109 { 110 final TestRunner runner= new TestRunner(); 111 final TestResult result = runner.doRun( 112 MBeanExceptionFormatterTest.suite(), false); 113 System.exit(result.errorCount() + result.failureCount()); 114 } 115 } | Popular Tags |