org.apache.qpid.test.framework
Class TestUtils

java.lang.Object
  extended by org.apache.qpid.test.framework.TestUtils

public class TestUtils
extends Object

TestUtils provides static helper methods that are usefull for writing tests against QPid.

CRC Card
Responsibilities Collaborations
Create connections from test properties. MessagingTestConfigProperties
Create test messages.
Inject a short pause in a test.
Serialize properties into a message.


Constructor Summary
TestUtils()
           
 
Method Summary
static Connection createConnection(org.apache.qpid.junit.extensions.util.ParsedProperties messagingProps)
          Establishes a JMS connection using a set of properties and qpids built in JNDI implementation.
static Message createTestMessageOfSize(Session session, int size)
          Creates a test message of the specified size, on the given JMS session.
static void pause(long t)
          Pauses for the specified length of time.
static void setPropertiesOnMessage(Message message, Map<Object,Object> properties)
          Sets properties of different types on a JMS Message.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TestUtils

public TestUtils()
Method Detail

createConnection

public static Connection createConnection(org.apache.qpid.junit.extensions.util.ParsedProperties messagingProps)
Establishes a JMS connection using a set of properties and qpids built in JNDI implementation. This is a simple convenience method for code that does not anticipate handling connection failures. All exceptions that indicate that the connection has failed, are wrapped as rutime exceptions, presumably handled by a top level failure handler.

This utility makes use of the following test parameters from MessagingTestConfigProperties to control the connection creation:

MessagingTestConfigProperties.USERNAME_PROPNAME The username.
MessagingTestConfigProperties.PASSWORD_PROPNAME The password.
MessagingTestConfigProperties.VIRTUAL_HOST_PROPNAME The virtual host name.
MessagingTestConfigProperties.BROKER_PROPNAME The broker URL.
MessagingTestConfigProperties.CONNECTION_NAME The broker name in the initial context.

Parameters:
messagingProps - Connection properties as defined in MessagingTestConfigProperties.
Returns:
A JMS conneciton.

createTestMessageOfSize

public static Message createTestMessageOfSize(Session session,
                                              int size)
                                       throws JMSException
Creates a test message of the specified size, on the given JMS session.

Parameters:
session - The JMS session.
size - The size of the message in bytes.
Returns:
A bytes message, of the specified size, filled with dummy data.
Throws:
JMSException - Any underlying JMSExceptions are allowed to fall through.

pause

public static void pause(long t)
Pauses for the specified length of time. In the event of failing to pause for at least that length of time due to interuption of the thread, a RutimeException is raised to indicate the failure. The interupted status of the thread is restores in that case. This method should only be used when it is expected that the pause will be succesfull, for example in test code that relies on inejecting a pause.

Parameters:
t - The minimum time to pause for in milliseconds.

setPropertiesOnMessage

public static void setPropertiesOnMessage(Message message,
                                          Map<Object,Object> properties)
                                   throws JMSException
Sets properties of different types on a JMS Message.

Parameters:
message - The message to set properties on.
properties - The property name/value pairs to set.
Throws:
JMSException - All underlying JMSExceptions are allowed to fall through.
Todo:
Move this helper method somewhere else. For example, TestUtils.


Licensed to the Apache Software Foundation