KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.HashMap JavaDoc;
20 import java.util.Map JavaDoc;
21
22 import javax.servlet.ServletException JavaDoc;
23
24 import junit.framework.TestCase;
25
26 import org.springframework.transaction.TransactionDefinition;
27
28 /**
29  * Tests for various TransactionAttributeSource implementations.
30  *
31  * @author Colin Sampaleanu
32  * @author Juergen Hoeller
33  * @since 15.10.2003
34  * @see org.springframework.transaction.interceptor.TransactionProxyFactoryBean
35  */

36 public class TransactionAttributeSourceTests extends TestCase {
37   
38     public void testMatchAlwaysTransactionAttributeSource() throws Exception JavaDoc {
39         MatchAlwaysTransactionAttributeSource tas = new MatchAlwaysTransactionAttributeSource();
40         TransactionAttribute ta = tas.getTransactionAttribute(
41                 Object JavaDoc.class.getMethod("hashCode", (Class JavaDoc[]) null), null);
42         assertNotNull(ta);
43         assertTrue(TransactionDefinition.PROPAGATION_REQUIRED == ta.getPropagationBehavior());
44
45         tas.setTransactionAttribute(new DefaultTransactionAttribute(TransactionDefinition.PROPAGATION_SUPPORTS));
46         ta = tas.getTransactionAttribute(
47                 ServletException JavaDoc.class.getMethod("getMessage", (Class JavaDoc[]) null), ServletException JavaDoc.class);
48         assertNotNull(ta);
49         assertTrue(TransactionDefinition.PROPAGATION_SUPPORTS == ta.getPropagationBehavior());
50     }
51
52     public void testMethodMapTransactionAttributeSource() throws NoSuchMethodException JavaDoc {
53         MethodMapTransactionAttributeSource tas = new MethodMapTransactionAttributeSource();
54         Map JavaDoc methodMap = new HashMap JavaDoc();
55         methodMap.put(Object JavaDoc.class.getName() + ".hashCode", "PROPAGATION_REQUIRED");
56         methodMap.put(Object JavaDoc.class.getName() + ".toString",
57                 new DefaultTransactionAttribute(TransactionDefinition.PROPAGATION_SUPPORTS));
58         tas.setMethodMap(methodMap);
59         TransactionAttribute ta = tas.getTransactionAttribute(
60                 Object JavaDoc.class.getMethod("hashCode", (Class JavaDoc[]) null), null);
61         assertNotNull(ta);
62         assertEquals(TransactionDefinition.PROPAGATION_REQUIRED, ta.getPropagationBehavior());
63         ta = tas.getTransactionAttribute(Object JavaDoc.class.getMethod("toString", (Class JavaDoc[]) null), null);
64         assertNotNull(ta);
65         assertEquals(TransactionDefinition.PROPAGATION_SUPPORTS, ta.getPropagationBehavior());
66     }
67
68     public void testNameMatchTransactionAttributeSource() throws NoSuchMethodException JavaDoc {
69         NameMatchTransactionAttributeSource tas = new NameMatchTransactionAttributeSource();
70         Map JavaDoc methodMap = new HashMap JavaDoc();
71         methodMap.put("hashCode", "PROPAGATION_REQUIRED");
72         methodMap.put("toString", new DefaultTransactionAttribute(TransactionDefinition.PROPAGATION_SUPPORTS));
73         tas.setNameMap(methodMap);
74         TransactionAttribute ta = tas.getTransactionAttribute(
75                 Object JavaDoc.class.getMethod("hashCode", (Class JavaDoc[]) null), null);
76         assertNotNull(ta);
77         assertEquals(TransactionDefinition.PROPAGATION_REQUIRED, ta.getPropagationBehavior());
78         ta = tas.getTransactionAttribute(Object JavaDoc.class.getMethod("toString", (Class JavaDoc[]) null), null);
79         assertNotNull(ta);
80         assertEquals(TransactionDefinition.PROPAGATION_SUPPORTS, ta.getPropagationBehavior());
81     }
82
83 }
84
Popular Tags