Package dk.netarkivet.testutils
Class TestMessageListener
- java.lang.Object
-
- dk.netarkivet.testutils.TestMessageListener
-
- All Implemented Interfaces:
javax.jms.MessageListener
public class TestMessageListener extends java.lang.Object implements javax.jms.MessageListener
A simple message listener that collects the messages given to it and lets you query them
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<NetarkivetMessage>
received
-
Constructor Summary
Constructors Constructor Description TestMessageListener()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.List<NetarkivetMessage>
getAllReceived()
get a list of all messages received.NetarkivetMessage
getLastInstance(java.lang.Class msgClass)
Looks up the messages that are instances of the given class.int
getNumNotOk()
Returns the number of received messages that were not ok.int
getNumOk()
Returns the number of received messages that were ok.int
getNumReceived()
Return the number of messages received so far.NetarkivetMessage
getReceived()
Get the last message received.void
onMessage(javax.jms.Message msg)
void
reset()
Reset the list of messages returned.
-
-
-
Field Detail
-
received
protected java.util.List<NetarkivetMessage> received
-
-
Constructor Detail
-
TestMessageListener
public TestMessageListener()
-
-
Method Detail
-
onMessage
public void onMessage(javax.jms.Message msg)
- Specified by:
onMessage
in interfacejavax.jms.MessageListener
-
getReceived
public NetarkivetMessage getReceived()
Get the last message received.- Returns:
- The last message received by the listener.
- Throws:
java.lang.IndexOutOfBoundsException
- if no messages have been received.
-
getNumReceived
public int getNumReceived()
Return the number of messages received so far.- Returns:
- the number of messages received so far
-
getAllReceived
public java.util.List<NetarkivetMessage> getAllReceived()
get a list of all messages received.- Returns:
- a list of all messages received
-
reset
public void reset()
Reset the list of messages returned.
-
getNumOk
public int getNumOk()
Returns the number of received messages that were ok.- Returns:
- the number of received messages that were ok
-
getNumNotOk
public int getNumNotOk()
Returns the number of received messages that were not ok.- Returns:
- the number of received messages that were not ok
-
getLastInstance
public NetarkivetMessage getLastInstance(java.lang.Class msgClass)
Looks up the messages that are instances of the given class.- Parameters:
msgClass
- A subclass of NetarkivetMessage, e.g. BatchMessage.class;- Returns:
- The instance that was most recently received, or null if no messages of the specified type has been received.
-
-