You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by David Siefert <si...@gmail.com> on 2008/02/11 10:51:45 UTC

Cannot get unit test to pass....

Hi,

I am trying to use ActiveMQ to do 'quick & easy' unit testing for JMS
message listeners.  So far, no luck.  I've tried to reduce my problem as
small as possible to pinpoint the problem.  Here is the code:
public class SimpleActiveMQTest {

private ConnectionFactory factory;

private Destination channel = new ActiveMQTopic("t.test.a");

@Before

public void setUp() throws Exception {

factory = new
ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");

}

@Test

public void testDestinationToDestination() throws Exception {

Connection connection = factory.createConnection();

Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

MessageProducer producer = session.createProducer(channel);

TextMessage message = session.createTextMessage("TEST");

producer.send(message);

MessageConsumer consumer = session.createConsumer(channel);

TextMessage message2 = (TextMessage) consumer.receive(30 * 1000);

Assert.assertNotNull(message2);

Assert.assertEquals("TEST", message2.getText());

}

}

I've tried quite a few variations including opening separate connections
(one to produce to the channel, the other to consume from the channel).
I've also tried creating the topic prior to producing/consuming--just to
verify whether or not ActiveMQ creates the channels on the fly.

Help?

Thanks,

David

Re: Cannot get unit test to pass....

Posted by James Strachan <ja...@gmail.com>.
I think you might have hit a real common gotcha...
http://activemq.apache.org/i-am-not-receiving-any-messages-what-is-wrong.html


On 11/02/2008, David Siefert <si...@gmail.com> wrote:
> Hi,
>
> I am trying to use ActiveMQ to do 'quick & easy' unit testing for JMS
> message listeners.  So far, no luck.  I've tried to reduce my problem as
> small as possible to pinpoint the problem.  Here is the code:
> public class SimpleActiveMQTest {
>
> private ConnectionFactory factory;
>
> private Destination channel = new ActiveMQTopic("t.test.a");
>
> @Before
>
> public void setUp() throws Exception {
>
> factory = new
> ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
>
> }
>
> @Test
>
> public void testDestinationToDestination() throws Exception {
>
> Connection connection = factory.createConnection();
>
> Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
>
> MessageProducer producer = session.createProducer(channel);
>
> TextMessage message = session.createTextMessage("TEST");
>
> producer.send(message);
>
> MessageConsumer consumer = session.createConsumer(channel);
>
> TextMessage message2 = (TextMessage) consumer.receive(30 * 1000);
>
> Assert.assertNotNull(message2);
>
> Assert.assertEquals("TEST", message2.getText());
>
> }
>
> }
>
> I've tried quite a few variations including opening separate connections
> (one to produce to the channel, the other to consume from the channel).
> I've also tried creating the topic prior to producing/consuming--just to
> verify whether or not ActiveMQ creates the channels on the fly.
>
> Help?
>
> Thanks,
>
> David
>


-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://open.iona.com