Hi  

You can use replace the jms component with seda component just like this

camelContext.addComponent("jms", sedaComponent );

The you don't need to create a new jms connection per test.  

--  
Willem Jiang

Red Hat, Inc.
FuseSource is now part of Red Hat
Web: http://www.fusesource.com | http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) 
(English)
          http://jnn.iteye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem





On Tuesday, July 30, 2013 at 6:17 PM, Costash wrote:

> Hello,
>  
> Thanks a lot. I did it. (see below) Now i have another question :)  
> My Endpoints are connecting to the real queue, and send the message there.
> What if i don't want a real connection to a queue,* can the endpoint be
> somehow virtualize for unit tests*?
> Ofcourse i can use active MQ instead of real MQ, but we will have same stuff
> = connection itself.
>  
>  
> I mean, to take the endoints from context, somehow vritualize not to have a
> real conection(just spmething called Endpoint), and send a message to that
> endpoint.
>  
> i think you got the idea: to use Endpoints in general instead of real one
> (with connection)
>  
>  
> Thanks,
> Vlad
>  
>  
> package main;
>  
> import org.apache.camel.CamelContext;
> import org.apache.camel.Produce;
> import org.apache.camel.ProducerTemplate;
> import org.apache.camel.builder.AdviceWithRouteBuilder;
> import org.apache.camel.builder.RouteBuilder;
> import org.apache.camel.component.jms.JmsComponent;
> import org.apache.camel.component.mock.MockEndpoint;
> import org.apache.camel.impl.DefaultCamelContext;
> import org.apache.camel.test.junit4.CamelTestSupport;
> import org.apache.log4j.PropertyConfigurator;
> import org.junit.BeforeClass;
> import org.junit.Test;
>  
> import com.ibm.mq.jms.MQQueueConnectionFactory;
> import com.ibm.msg.client.wmq.WMQConstants;
>  
>  
>  
>  
>  
>  
> /**
> * @author vlad.costache
> *
> *  
> */
> public class TestWithMokk extends CamelTestSupport {  
>  
>  
> @Produce(uri = "jms:queue:msb.2761100008.mpos")
> protected ProducerTemplate template;
>  
> @BeforeClass
> public static void setConn(){
> PropertyConfigurator.configure("./log4j.properties");
>  
>  
>  
>  
> }
>  
> /* (non-Javadoc)
> * @see org.apache.camel.test.junit4.CamelTestSupport#createCamelContext()
> */
> @Override
> protected CamelContext createCamelContext() throws Exception {
> MQQueueConnectionFactory factory = new MQQueueConnectionFactory();  
> factory.setQueueManager("MQSD.ESSWS008");
> factory.setChannel("MSB.S0.SVRCONN");
> factory.setHostName("10.23.8.218");
> factory.setPort(1414);
> factory.setTransportType(WMQConstants. WMQ_CM_CLIENT);
>  
>  
> JmsComponent jmsComponent =
> JmsComponent.jmsComponentAutoAcknowledge(factory);
>  
> CamelContext camelContext = new DefaultCamelContext();
> camelContext.addComponent("jms", jmsComponent );
> return camelContext;
>  
> }
>  
> @Test
> public void testSendMatchingMessage() throws Exception {
>  
>  
>  
>  
> context.getRouteDefinitions().get(0).adviceWith(context, new
> AdviceWithRouteBuilder() {
> @Override
> public void configure() throws Exception {
> // mock all endpoints
> mockEndpoints();
> }
> });
>  
>  
> String sendbody = "<send/>";
> String expectedBody = "<matched/>";
>  
> MockEndpoint mockEndpoint =
> getMockEndpoint("mock:jms:queue:msb.2761100008.invoice");
> mockEndpoint.expectedBodiesReceived(expectedBody);
>  
> template.sendBodyAndHeader(expectedBody, "foo", "bar");
> mockEndpoint.assertIsSatisfied();
> }
>  
>  
>  
>  
> @Override  
> protected RouteBuilder createRouteBuilder() throws Exception {  
> return new MyRouteBuilder();  
>  
> }  
>  
> }
>  
>  
>  
>  
>  
>  
> --
> View this message in context: 
> http://camel.465427.n5.nabble.com/Camel-testing-tp5736444p5736480.html
> Sent from the Camel - Users mailing list archive at Nabble.com 
> (http://Nabble.com).



Reply via email to