All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mockrunner.mock.jms.MockQueueBrowser Maven / Gradle / Ivy

Go to download

Mockrunner is a lightweight framework for unit testing applications in the J2EE environment. It supports servlets, filters, tag classes and Struts actions. It includes a JDBC a JMS and a JCA test framework and can be used to test EJB based applications.

The newest version!
package com.mockrunner.mock.jms;

import java.util.Enumeration;
import java.util.Vector;

import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.QueueBrowser;

/**
 * Mock implementation of JMS QueueBrowser.
 */
public class MockQueueBrowser implements QueueBrowser
{
    private MockConnection connection;
    private MockQueue queue;
    private boolean closed;
    private String messageSelector;
    
    public MockQueueBrowser(MockConnection connection, MockQueue queue)
    {
        this(connection, queue, null);
    }

    public MockQueueBrowser(MockConnection connection, MockQueue queue, String messageSelector)
    {
        this.connection = connection;
        this.queue = queue;
        closed = false;
        this.messageSelector = messageSelector;
    }
    
    /**
     * Returns if this browser was closed.
     * @return true if this browser is closed
     */
    public boolean isClosed()
    {
        return closed;
    }

    public Queue getQueue() throws JMSException
    {
        connection.throwJMSException();
        return queue;
    }

    public String getMessageSelector() throws JMSException
    {
        connection.throwJMSException();
        return messageSelector;
    }

    public Enumeration getEnumeration() throws JMSException
    {
        connection.throwJMSException();
        if(isClosed())
        {
            throw new JMSException("Browser is closed");
        }
        return new Vector(queue.getCurrentMessageList()).elements();
    }

    public void close() throws JMSException
    {
        connection.throwJMSException();
        closed = true;
    }  
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy