sk.seges.test.jms.activemq.SimpleActiveMQQueueReceiveFailTest.java Source code

Java tutorial

Introduction

Here is the source code for sk.seges.test.jms.activemq.SimpleActiveMQQueueReceiveFailTest.java

Source

/*
 * Copyright 2009 Seges Ltd. 
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 *  
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 */
package sk.seges.test.jms.activemq;

import static org.junit.Assert.assertNull;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.Queue;
import javax.jms.Session;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * @author ladislav.gazo
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:/sk/seges/test/jms/activemq/test-activemq-context.xml" })
public class SimpleActiveMQQueueReceiveFailTest {
    @Autowired
    private ConnectionFactory activeMQConnectionFactory;
    @Autowired
    private Queue activeMQTestQueueA;

    @Before
    public void setUp() {
    }

    @Test
    public void testReceive() throws Exception {
        Connection connection = activeMQConnectionFactory.createConnection();
        connection.start();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageConsumer consumer = session.createConsumer(activeMQTestQueueA);

        Message rawMessage = consumer.receive(1000);
        assertNull(rawMessage);
        connection.close();
    }
}