com.mockrunner.jms.MessageManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mockrunner-jdk1.3-j2ee1.3 Show documentation
Show all versions of mockrunner-jdk1.3-j2ee1.3 Show documentation
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.jms;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.mockrunner.mock.jms.MockBytesMessage;
import com.mockrunner.mock.jms.MockMapMessage;
import com.mockrunner.mock.jms.MockMessage;
import com.mockrunner.mock.jms.MockObjectMessage;
import com.mockrunner.mock.jms.MockStreamMessage;
import com.mockrunner.mock.jms.MockTextMessage;
/**
* Can be used to create and access all type of messages.
* The create methods are usually called by
* {@link com.mockrunner.mock.jms.MockSession}.
*/
public class MessageManager
{
private List messages;
private List byteMessages;
private List mapMessages;
private List textMessages;
private List streamMessages;
private List objectMessages;
public MessageManager()
{
messages = new ArrayList();
byteMessages = new ArrayList();
mapMessages = new ArrayList();
textMessages = new ArrayList();
streamMessages = new ArrayList();
objectMessages = new ArrayList();
}
/**
* Creates a new Message
. Usually this method is called
* by {@link com.mockrunner.mock.jms.MockSession#createMessage}.
* @return the created Message
*/
public MockMessage createMessage()
{
MockMessage message = new MockMessage();
messages.add(message);
return message;
}
/**
* Returns a Message
by its index or
* null
, if no such Message
is
* present.
* @param index the index of the Message
* @return the Message
*/
public MockMessage getMessage(int index)
{
if(messages.size() <= index || index < 0) return null;
return (MockMessage)messages.get(index);
}
/**
* Returns the list of Message
objects.
* @return the Message
list
*/
public List getMessageList()
{
return Collections.unmodifiableList(messages);
}
/**
* Creates a new BytesMessage
. Usually this method is called
* by {@link com.mockrunner.mock.jms.MockSession#createBytesMessage}.
* @return the created BytesMessage
*/
public MockBytesMessage createBytesMessage()
{
MockBytesMessage message = new MockBytesMessage();
byteMessages.add(message);
return message;
}
/**
* Returns a BytesMessage
by its index or
* null
, if no such BytesMessage
is
* present.
* @param index the index of the BytesMessage
* @return the BytesMessage
*/
public MockBytesMessage getBytesMessage(int index)
{
if(byteMessages.size() <= index || index < 0) return null;
return (MockBytesMessage)byteMessages.get(index);
}
/**
* Returns the list of BytesMessage
objects.
* @return the BytesMessage
list
*/
public List getBytesMessageList()
{
return Collections.unmodifiableList(byteMessages);
}
/**
* Creates a new MapMessage
. Usually this method is called
* by {@link com.mockrunner.mock.jms.MockSession#createMapMessage}.
* @return the created MapMessage
*/
public MockMapMessage createMapMessage()
{
MockMapMessage message = new MockMapMessage();
mapMessages.add(message);
return message;
}
/**
* Returns a MapMessage
by its index or
* null
, if no such MapMessage
is
* present.
* @param index the index of the MapMessage
* @return the MapMessage
*/
public MockMapMessage getMapMessage(int index)
{
if(mapMessages.size() <= index || index < 0) return null;
return (MockMapMessage)mapMessages.get(index);
}
/**
* Returns the list of MapMessage
objects.
* @return the MapMessage
list
*/
public List getMapMessageList()
{
return Collections.unmodifiableList(mapMessages);
}
/**
* Creates a new TextMessage
. Usually this method is called
* by {@link com.mockrunner.mock.jms.MockSession#createTextMessage}.
* @return the created TextMessage
*/
public MockTextMessage createTextMessage(String text)
{
MockTextMessage message = new MockTextMessage(text);
textMessages.add(message);
return message;
}
/**
* Returns a TextMessage
by its index or
* null
, if no such TextMessage
is
* present.
* @param index the index of the TextMessage
* @return the TextMessage
*/
public MockTextMessage getTextMessage(int index)
{
if(textMessages.size() <= index || index < 0) return null;
return (MockTextMessage)textMessages.get(index);
}
/**
* Returns the list of TextMessage
objects.
* @return the TextMessage
list
*/
public List getTextMessageList()
{
return Collections.unmodifiableList(textMessages);
}
/**
* Creates a new StreamMessage
. Usually this method is called
* by {@link com.mockrunner.mock.jms.MockSession#createStreamMessage}.
* @return the created StreamMessage
*/
public MockStreamMessage createStreamMessage()
{
MockStreamMessage message = new MockStreamMessage();
streamMessages.add(message);
return message;
}
/**
* Returns a StreamMessage
by its index or
* null
, if no such StreamMessage
is
* present.
* @param index the index of the StreamMessage
* @return the StreamMessage
*/
public MockStreamMessage getStreamMessage(int index)
{
if(streamMessages.size() <= index || index < 0) return null;
return (MockStreamMessage)streamMessages.get(index);
}
/**
* Returns the list of StreamMessage
objects.
* @return the StreamMessage
list
*/
public List getStreamMessageList()
{
return Collections.unmodifiableList(streamMessages);
}
/**
* Creates a new ObjectMessage
. Usually this method is called
* by {@link com.mockrunner.mock.jms.MockSession#createObjectMessage}.
* @return the created ObjectMessage
*/
public MockObjectMessage createObjectMessage(java.io.Serializable object)
{
MockObjectMessage message = new MockObjectMessage(object);
objectMessages.add(message);
return message;
}
/**
* Returns a ObjectMessage
by its index or
* null
, if no such ObjectMessage
is
* present.
* @param index the index of the ObjectMessage
* @return the ObjectMessage
*/
public MockObjectMessage getObjectMessage(int index)
{
if(objectMessages.size() <= index || index < 0) return null;
return (MockObjectMessage)objectMessages.get(index);
}
/**
* Returns the list of ObjectMessage
objects.
* @return the ObjectMessage
list
*/
public List getObjectMessageList()
{
return Collections.unmodifiableList(objectMessages);
}
}