KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > transaction > support > JtaTransactionManagerSerializationTests


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.support;
18
19 import javax.transaction.TransactionManager JavaDoc;
20 import javax.transaction.UserTransaction JavaDoc;
21
22 import junit.framework.TestCase;
23 import org.easymock.MockControl;
24
25 import org.springframework.mock.jndi.SimpleNamingContextBuilder;
26 import org.springframework.transaction.jta.JtaTransactionManager;
27 import org.springframework.util.SerializationTestUtils;
28
29 /**
30  * @author Rod Johnson
31  */

32 public class JtaTransactionManagerSerializationTests extends TestCase {
33
34     public void testSerializable() throws Exception JavaDoc {
35         MockControl utMock = MockControl.createControl(UserTransaction JavaDoc.class);
36         UserTransaction JavaDoc ut = (UserTransaction JavaDoc) utMock.getMock();
37         MockControl ut2Mock = MockControl.createControl(UserTransaction JavaDoc.class);
38         UserTransaction JavaDoc ut2 = (UserTransaction JavaDoc) ut2Mock.getMock();
39         MockControl tmMock = MockControl.createControl(TransactionManager JavaDoc.class);
40         TransactionManager JavaDoc tm = (TransactionManager JavaDoc) tmMock.getMock();
41
42         JtaTransactionManager jtam = new JtaTransactionManager();
43         jtam.setUserTransaction(ut);
44         jtam.setTransactionManager(tm);
45         jtam.afterPropertiesSet();
46
47         SimpleNamingContextBuilder jndiEnv = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
48         jndiEnv.bind(JtaTransactionManager.DEFAULT_USER_TRANSACTION_NAME, ut2);
49         JtaTransactionManager jtam2 = (JtaTransactionManager) SerializationTestUtils.serializeAndDeserialize(jtam);
50         
51         // should do client-side lookup
52
assertNotNull("Logger must survive serialization", jtam2.logger);
53         assertTrue("UserTransaction looked up on client", jtam2.getUserTransaction() == ut2);
54         assertNull("TransactionManager didn't survive", jtam2.getTransactionManager());
55     }
56
57 }
58
Popular Tags