KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > transaction > interceptor > RollbackRuleTests


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.transaction.interceptor;
18
19 import javax.servlet.ServletException JavaDoc;
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 /**
28  *
29  * @author Rod Johnson
30  * @since 09.04.2003
31  */

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 JavaDoc()) == 0);
37     }
38     
39     public void testFoundImmediatelyWithClass() {
40         RollbackRuleAttribute rr = new RollbackRuleAttribute(Exception JavaDoc.class);
41         assertTrue(rr.getDepth(new Exception JavaDoc()) == 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         // Exception -> Runtime -> NestedRuntime -> MailException -> MailSendException
52
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 JavaDoc()) > 0);
59         assertTrue(rr.getDepth(new FatalBeanException(null,null)) > 0);
60         assertTrue(rr.getDepth(new RuntimeException JavaDoc()) > 0);
61     }
62     
63     public void testConstructorArgMustBeAThrowableClass() {
64         try {
65             new RollbackRuleAttribute(StringBuffer JavaDoc.class);
66             fail("Can't construct a RollbackRuleAttribute without a throwable");
67         }
68         catch (AopConfigException ex) {
69             // OK
70
}
71     }
72
73 }
74
Popular Tags