title: Test case for ActiveMQ
body: <p>I was wondering how to test JMS using ActiveMQ based on the answer suggesting using ActiveMQ to do the test <a href="https://stackoverflow.com/questions/5217315/simultating-jms-junit">Simulating JMS - jUnit</a></p>
  
  <p>However, I am not getting the message I was expecting from the MessageConsumer.  If I used receive it just hangs there.</p>
  
  <p>Here is my code</p>
  
  <pre><code>import javax.jms.Connection;
  import javax.jms.ConnectionFactory;
  import javax.jms.MessageConsumer;
  import javax.jms.MessageProducer;
  import javax.jms.Queue;
  import javax.jms.Session;
  import javax.jms.TextMessage;
  
  import org.apache.activemq.ActiveMQConnectionFactory;
  import org.junit.Assert;
  import org.junit.Test;
  
  public class JmsTest {
  @Test
  public void test() throws Exception {
      final ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
              "vm://localhost?broker.persistent=true");
      final Queue queue;
      final Connection connection = connectionFactory.createConnection();
      final Session session = connection.createSession(true,
              Session.AUTO_ACKNOWLEDGE);
      {
          queue = session.createQueue("test");
      }
      {
          final MessageProducer producer = session.createProducer(queue);
          final TextMessage message = session.createTextMessage("testing");
          producer.send(message);
      }
      {
          final MessageConsumer consumer = session.createConsumer(queue);
          final TextMessage message = (TextMessage) consumer.receiveNoWait();
          // "message" is null at this point
          Assert.assertEquals("testing", message.getText());
      }
  }
  }
  </code></pre>