com.mockrunner.jms.DestinationManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mockrunner-jms Show documentation
Show all versions of mockrunner-jms Show documentation
Mock classes for Java Messaging System
package com.mockrunner.jms;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import com.mockrunner.mock.jms.MockQueue;
import com.mockrunner.mock.jms.MockTopic;
/**
* The DestinationManager
can be used
* to create queues and topics, which is normally an
* administrative act. Since queues and topics are ususally
* acquired using JNDI in a J2EE environment, you can bind
* the created objects to the mock context with the help
* of com.mockrunner.ejb.EJBTestModule#bindToContext.
*/
public class DestinationManager implements Serializable
{
private Map queues;
private Map topics;
public DestinationManager()
{
queues = new HashMap();
topics = new HashMap();
}
/**
* Creates a new Queue
that is available
* for {@link com.mockrunner.mock.jms.MockQueueSession#createQueue}
* calls. Creating queues is an administrative act.
* Before {@link com.mockrunner.mock.jms.MockQueueSession#createQueue}
* can be sucessfully called, you have to create a Queue
* with this method. You can also bind the created queue to the
* mock JNDI context using com.mockrunner.ejb.EJBTestModule#bindToContext.
* @param name the name of the Queue
* @return the created Queue
*/
public MockQueue createQueue(String name)
{
MockQueue queue = new MockQueue(name);
queues.put(name, queue);
return queue;
}
/**
* Removes a formerly created Queue
.
* @param name the name of the Queue
*/
public void removeQueue(String name)
{
queues.remove(name);
}
/**
* Returns a Queue
that was created with
* {@link #createQueue} or null
if no such
* Queue
is present.
* @param name the name of the Queue
* @return the Queue
*/
public MockQueue getQueue(String name)
{
return (MockQueue)queues.get(name);
}
/**
* Creates a new Topic
that is available
* for {@link com.mockrunner.mock.jms.MockTopicSession#createTopic}
* calls. Creating topics is an administrative act.
* Before {@link com.mockrunner.mock.jms.MockTopicSession#createTopic}
* can be sucessfully called, you have to create a Topic
* with this method. You can also bind the created topic to the
* mock JNDI context using com.mockrunner.ejb.EJBTestModule#bindToContext.
* @param name the name of the Topic
* @return the created Topic
*/
public MockTopic createTopic(String name)
{
MockTopic topic = new MockTopic(name);
topics.put(name, topic);
return topic;
}
/**
* Removes a formerly created Topic
.
* @param name the name of the Topic
*/
public void removeTopic(String name)
{
topics.remove(name);
}
/**
* Returns a Topic
that was created with
* {@link #createTopic} or null
if no such
* Topic
is present.
* @param name the name of the Topic
* @return the Topic
*/
public MockTopic getTopic(String name)
{
return (MockTopic)topics.get(name);
}
}