Package org.codehaus.activemq.service.impl

Source Code of org.codehaus.activemq.service.impl.XATransactionTest

/**
*
* 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.XidStub;
import org.codehaus.activemq.test.SerializationTestSupport;

import javax.jms.JMSException;

/**
* @version $Revision: 1.3 $
*/
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 {
        XidStub xidStub = new XidStub(new byte[]{1, 2, 3, 4, 5});
        ActiveMQXid xid = new ActiveMQXid(xidStub);

        byte[] data = serialize(xid);
        Object value = deserialize(data);

        assertEquals("deserialized object is not equal", xid, value);
    }

    public void testXidEquals() throws Exception {
        XidStub xidStub = new XidStub(new byte[]{1, 2, 3, 4, 5});
        ActiveMQXid xid1 = new ActiveMQXid(xidStub);
        ActiveMQXid xid2 = new ActiveMQXid(xidStub);

        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;
    }

}
TOP

Related Classes of org.codehaus.activemq.service.impl.XATransactionTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.