I am using the JMS functionality in MockRunner. I'm running a simple test. Send a message on a queue, MDBean looks for getJMSReplyTo(), and then responds with a status on the destination in getJMSReplyTo(). However, even though I'm setting jmsReplyTo in the Message object before sending it to the queue, it is always null in the MDB's onMessage operation.
Not sure what I'm doing wrong? Here is my sample Message Driven Bean:
/*****************************************************************************TDAMERITRADECONFIDENTIALCONTROLLED.DONOTCOPYORDISTRIBUTEFURTHER.*(c)2006ThinkTech,Inc.Allrightsreserved.****************************************************************************/packagecom.ameritrade.jasom.clientnotification.service.mdb.mockSamples;importjavax.ejb.EJBException;importjavax.ejb.MessageDrivenBean;importjavax.ejb.MessageDrivenContext;importjavax.jms.Message;importjavax.jms.MessageListener;publicclassSimpleMDBeanimplementsMessageDrivenBean,MessageListener{//~Methods------------------------------------------------------------------------------------publicvoidonMessage(Messagemessage){try{System.out.println("I am a message driven bean, and message reply dest is "+message.getJMSReplyTo());}catch(Exceptionexception){exception.printStackTrace(System.err);}}publicvoidejbCreate(){//donothing}publicvoidejbRemove()throwsEJBException{//donothing}publicvoidsetMessageDrivenContext(MessageDrivenContextarg0)throwsEJBException{//donothing}}
And here is my sample Test Case:
publicclassTestSimpleMDBeanextendsTestCase{//~Staticfields/initializers-----------------------------------------------------------------privatestaticfinalStringRESPONSE_QUEUE_NAME="ResponseQueue";privatestaticfinalStringREQUEST_QUEUE_NAME="RequestQueue";privatestaticfinalStringQUEUE_CONNECTION_FACTORY="SampleConnectionFactory";//~Instancefields----------------------------------------------------------------------------//JNDIcontextandMockContainerinstanceusedbyalltestsinthisclassprivateMockContainermockContainer;//~Methods------------------------------------------------------------------------------------/***Setsupourmockcontainer,JNDIcontextanddeploythebeansthatweneed.*//***DeploysMDBandusessessionbeantosendamessagetoMDB.*/publicvoidtestMessageBeanWithWrongObjectType()throwsException{//MockContextFactorybecomestheprimaryJNDIproviderMockContextFactory.setAsInitial();Contextcontext=newInitialContext();//createtheresponsequeuecontext.rebind(RESPONSE_QUEUE_NAME,newMockQueue(RESPONSE_QUEUE_NAME));mockContainer=newMockContainer(context);//WecanbindtheMDBtothemockREQUESTqueuesothat//itwill'listen'onthequeuemockContainer.deploy(newMDBDescriptor(QUEUE_CONNECTION_FACTORY,REQUEST_QUEUE_NAME,newSimpleMDBean()));InitialContextctx=newInitialContext();//getreferencestorequestandresponsequeuesQueuerequestQueue=(Queue)ctx.lookup(REQUEST_QUEUE_NAME);QueueresponseQueue=null;responseQueue=(Queue)ctx.lookup(RESPONSE_QUEUE_NAME);System.out.println("response queue is "+responseQueue);//getmessageproducersowecansendthemessageQueueConnectionFactoryqueueConnectionFactory=(QueueConnectionFactory)ctx.lookup(QUEUE_CONNECTION_FACTORY);QueueConnectionqueueConnection=queueConnectionFactory.createQueueConnection();QueueSessionqueueSession=queueConnection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);MessageProducerproducer=queueSession.createProducer(requestQueue);//createthemessageObjectMessageobjectMessage=queueSession.createObjectMessage();objectMessage.setObject("Test Message!");objectMessage.setJMSReplyTo(responseQueue);System.out.println("Object message's JMSReplyTo before sending on the mock queue is "+objectMessage.getJMSReplyTo());//postthemessagetothequeueproducer.send(objectMessage);}}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It seems that you do not even use Mockrunner or one of Mockrunners JMS mock implementations. You do not show the imports of your test but do you even import a com.mockrunner.* class? This looks like pure MockEJB code (http://mockejb.sourceforge.net/). So you do not use the JMS functionality of Mockrunner but the JMS functionality of MockEJB. JMSReplyTo should work with Mockrunner. Please have a look at the Mockrunner examples.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you for taking the time to reply. I do import some com.mockrunner classes, but it is probably not the right ones.
I appreciate the pointer, and so far as I've been able to figure it out, LOVE this tool. =) Thank you for making the world of unit testing a better place.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I am using the JMS functionality in MockRunner. I'm running a simple test. Send a message on a queue, MDBean looks for getJMSReplyTo(), and then responds with a status on the destination in getJMSReplyTo(). However, even though I'm setting jmsReplyTo in the Message object before sending it to the queue, it is always null in the MDB's onMessage operation.
Not sure what I'm doing wrong? Here is my sample Message Driven Bean:
And here is my sample Test Case:
It seems that you do not even use Mockrunner or one of Mockrunners JMS mock implementations. You do not show the imports of your test but do you even import a com.mockrunner.* class? This looks like pure MockEJB code (http://mockejb.sourceforge.net/). So you do not use the JMS functionality of Mockrunner but the JMS functionality of MockEJB. JMSReplyTo should work with Mockrunner. Please have a look at the Mockrunner examples.
Thank you for taking the time to reply. I do import some com.mockrunner classes, but it is probably not the right ones.
I appreciate the pointer, and so far as I've been able to figure it out, LOVE this tool. =) Thank you for making the world of unit testing a better place.