/**
*
* Copyright 2004 Protique Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
**/
package org.codehaus.activemq.service.impl;
import org.codehaus.activemq.message.ActiveMQMessage;
import org.codehaus.activemq.message.ActiveMQTextMessage;
import org.codehaus.activemq.message.ActiveMQXid;
import org.codehaus.activemq.message.MockXid;
import org.codehaus.activemq.test.SerializationTestSupport;
import javax.jms.JMSException;
/**
* @version $Revision: 1.2 $
*/
public class XATransactionTest extends SerializationTestSupport {
public void testXATransactionSerialization() throws Exception {
XATransactionCommand txn = createXATranasction();
byte[] data = serialize(txn);
Object value = deserialize(data);
assertTrue("Should have returned an XATransactionCommend: " + value, value instanceof XATransactionCommand);
}
public void testXidSerialization() throws Exception {
MockXid mockXid = new MockXid(new byte[]{1, 2, 3, 4, 5});
ActiveMQXid xid = new ActiveMQXid(mockXid);
byte[] data = serialize(xid);
Object value = deserialize(data);
assertEquals("deserialized object is not equal", xid, value);
}
public void testXidEquals() throws Exception {
MockXid mockXid = new MockXid(new byte[]{1, 2, 3, 4, 5});
ActiveMQXid xid1 = new ActiveMQXid(mockXid);
ActiveMQXid xid2 = new ActiveMQXid(mockXid);
assertEquals("object hashes are not equal", xid1.hashCode(), xid2.hashCode());
assertEquals("objects are not equal", xid1, xid2);
}
protected XATransactionCommand createXATranasction() throws JMSException {
ActiveMQXid xid = new ActiveMQXid("01:23:45");
XATransactionCommand answer = new XATransactionCommand(null, xid, null, null);
answer.addPostCommitTask(new SendMessageTransactionTask(null, createMessage()));
return answer;
}
protected ActiveMQMessage createMessage() throws JMSException {
ActiveMQTextMessage answer = new ActiveMQTextMessage();
answer.setJMSMessageID("abc:123");
answer.setText("I'm a test message!");
return answer;
}
}