Package com.muleinaction

Source Code of com.muleinaction.TransformingBridgeJmsClientTestCase

package com.muleinaction;

import static com.muleinaction.Constants.MESSAGE_XML_V1;
import static com.muleinaction.Constants.MESSAGE_XML_V2;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

import javax.jms.BytesMessage;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.junit.Test;
import org.mule.tck.junit4.FunctionalTestCase;
import org.mule.transport.jms.JmsConnector;

public class TransformingBridgeJmsClientTestCase extends FunctionalTestCase
{
    @Override
    protected String getConfigResources()
    {
        return "functional-test-connectors.xml,jms-transforming-bridge.xml";
    }

    // <start id="lis_12_fun_testing_jms"/>
    @Test
    public void testJmsXmlV1V2Bridge() throws Exception
    {
        JmsConnector jmsConnector = // <co id="lis_12_fun_testing_jms-1"/>
            (JmsConnector) muleContext
                            .getRegistry()
                              .lookupConnector("amqConnector");

        Session session =
            jmsConnector
              .getConnection()
                .createSession(false, Session.AUTO_ACKNOWLEDGE);

        Queue v1Queue = session.createQueue("messages.v1");
        MessageProducer producer = session.createProducer(v1Queue);
        TextMessage v1Message = session.createTextMessage(MESSAGE_XML_V1);
        producer.send(v1Message);// <co id="lis_12_fun_testing_jms-2"/>

        Queue v2Queue = session.createQueue("messages.v2");
        MessageConsumer consumer = session.createConsumer(v2Queue);
        BytesMessage v2Message =// <co id="lis_12_fun_testing_jms-3"/>
             (BytesMessage) consumer.receive(1000 * getTestTimeoutSecs());

        byte[] bytes = new byte[(int) v2Message.getBodyLength()];
        v2Message.readBytes(bytes);// <co id="lis_12_fun_testing_jms-4"/>

        assertThat(new String(bytes), is(MESSAGE_XML_V2));

        session.close();
    }
    // <end id="lis_12_fun_testing_jms"/>
}
TOP

Related Classes of com.muleinaction.TransformingBridgeJmsClientTestCase

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.