1 16 17 package org.springframework.transaction.interceptor; 18 19 import javax.servlet.ServletException ; 20 21 import junit.framework.TestCase; 22 23 import org.springframework.aop.framework.AopConfigException; 24 import org.springframework.beans.FatalBeanException; 25 import org.springframework.mail.MailSendException; 26 27 32 public class RollbackRuleTests extends TestCase { 33 34 public void testFoundImmediatelyWithString() { 35 RollbackRuleAttribute rr = new RollbackRuleAttribute("java.lang.Exception"); 36 assertTrue(rr.getDepth(new Exception ()) == 0); 37 } 38 39 public void testFoundImmediatelyWithClass() { 40 RollbackRuleAttribute rr = new RollbackRuleAttribute(Exception .class); 41 assertTrue(rr.getDepth(new Exception ()) == 0); 42 } 43 44 public void testNotFound() { 45 RollbackRuleAttribute rr = new RollbackRuleAttribute("javax.servlet.ServletException"); 46 assertTrue(rr.getDepth(new MailSendException("")) == -1); 47 } 48 49 public void testAncestry() { 50 RollbackRuleAttribute rr = new RollbackRuleAttribute("java.lang.Exception"); 51 assertTrue(rr.getDepth(new MailSendException("")) == 4); 53 } 54 55 public void testAlwaysTrue() { 56 RollbackRuleAttribute rr = new RollbackRuleAttribute("java.lang.Throwable"); 57 assertTrue(rr.getDepth(new MailSendException("")) > 0); 58 assertTrue(rr.getDepth(new ServletException ()) > 0); 59 assertTrue(rr.getDepth(new FatalBeanException(null,null)) > 0); 60 assertTrue(rr.getDepth(new RuntimeException ()) > 0); 61 } 62 63 public void testConstructorArgMustBeAThrowableClass() { 64 try { 65 new RollbackRuleAttribute(StringBuffer .class); 66 fail("Can't construct a RollbackRuleAttribute without a throwable"); 67 } 68 catch (AopConfigException ex) { 69 } 71 } 72 73 } 74 | Popular Tags |