1 /*** 2 * 3 * Copyright 2004 Protique Ltd 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 **/ 18 package org.codehaus.activemq.service.impl; 19 20 import org.codehaus.activemq.message.ActiveMQMessage; 21 import org.codehaus.activemq.message.ActiveMQTextMessage; 22 import org.codehaus.activemq.message.ActiveMQXid; 23 import org.codehaus.activemq.message.XidStub; 24 import org.codehaus.activemq.test.SerializationTestSupport; 25 26 import javax.jms.JMSException; 27 28 /*** 29 * @version $Revision: 1.3 $ 30 */ 31 public class XATransactionTest extends SerializationTestSupport { 32 public void testXATransactionSerialization() throws Exception { 33 XATransactionCommand txn = createXATranasction(); 34 35 byte[] data = serialize(txn); 36 Object value = deserialize(data); 37 38 assertTrue("Should have returned an XATransactionCommend: " + value, value instanceof XATransactionCommand); 39 } 40 41 public void testXidSerialization() throws Exception { 42 XidStub xidStub = new XidStub(new byte[]{1, 2, 3, 4, 5}); 43 ActiveMQXid xid = new ActiveMQXid(xidStub); 44 45 byte[] data = serialize(xid); 46 Object value = deserialize(data); 47 48 assertEquals("deserialized object is not equal", xid, value); 49 } 50 51 public void testXidEquals() throws Exception { 52 XidStub xidStub = new XidStub(new byte[]{1, 2, 3, 4, 5}); 53 ActiveMQXid xid1 = new ActiveMQXid(xidStub); 54 ActiveMQXid xid2 = new ActiveMQXid(xidStub); 55 56 assertEquals("object hashes are not equal", xid1.hashCode(), xid2.hashCode()); 57 assertEquals("objects are not equal", xid1, xid2); 58 } 59 60 protected XATransactionCommand createXATranasction() throws JMSException { 61 ActiveMQXid xid = new ActiveMQXid("01:23:45"); 62 XATransactionCommand answer = new XATransactionCommand(null, xid, null, null); 63 answer.addPostCommitTask(new SendMessageTransactionTask(null, createMessage())); 64 return answer; 65 } 66 67 protected ActiveMQMessage createMessage() throws JMSException { 68 ActiveMQTextMessage answer = new ActiveMQTextMessage(); 69 answer.setJMSMessageID("abc:123"); 70 answer.setText("I'm a test message!"); 71 return answer; 72 } 73 74 }