From 7e1ac76588d8a335e5ea64edbb127d53f1ef57be Mon Sep 17 00:00:00 2001 From: Rupert Smith Date: Thu, 27 Sep 2007 15:32:31 +0000 Subject: Added test cases 4 and 5, from the updated interop spec. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/branches/M2.1@580066 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/qpid/test/framework/TestUtils.java | 47 ++++++++++++++++++---- 1 file changed, 40 insertions(+), 7 deletions(-) (limited to 'java/systests/src') diff --git a/java/systests/src/main/java/org/apache/qpid/test/framework/TestUtils.java b/java/systests/src/main/java/org/apache/qpid/test/framework/TestUtils.java index 8b3e72ef08..569eac425c 100644 --- a/java/systests/src/main/java/org/apache/qpid/test/framework/TestUtils.java +++ b/java/systests/src/main/java/org/apache/qpid/test/framework/TestUtils.java @@ -26,16 +26,13 @@ import static org.apache.qpid.test.framework.MessagingTestConfigProperties.*; import uk.co.thebadgerset.junit.extensions.util.ParsedProperties; -import javax.jms.Connection; -import javax.jms.ConnectionFactory; -import javax.jms.JMSException; -import javax.jms.Message; +import javax.jms.*; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; -import java.util.Properties; import java.util.Map; +import java.util.Properties; /** * TestUtils provides static helper methods that are usefull for writing tests against QPid. @@ -51,6 +48,10 @@ public class TestUtils /** Used for debugging. */ private static Logger log = Logger.getLogger(TestUtils.class); + private static byte[] MESSAGE_DATA_BYTES = + "Test Message -- Test Message -- Test Message -- Test Message -- Test Message -- Test Message -- Test Message -- " + .getBytes(); + /** * 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 @@ -96,9 +97,8 @@ public class TestUtils Context ctx = new InitialContext(messagingProps); ConnectionFactory cf = (ConnectionFactory) ctx.lookup(CONNECTION_NAME); - Connection connection = cf.createConnection(); - return connection; + return cf.createConnection(); } catch (NamingException e) { @@ -110,6 +110,39 @@ public class TestUtils } } + /** + * Creates a test message of the specified size, on the given JMS session. + * + * @param session The JMS session. + * @param size The size of the message in bytes. + * + * @return A bytes message, of the specified size, filled with dummy data. + * + * + */ + public static Message createTestMessageOfSize(Session session, int size) throws JMSException + { + BytesMessage message = session.createBytesMessage(); + + if (size > 0) + { + int div = MESSAGE_DATA_BYTES.length / size; + int mod = MESSAGE_DATA_BYTES.length % size; + + for (int i = 0; i < div; i++) + { + message.writeBytes(MESSAGE_DATA_BYTES); + } + + if (mod != 0) + { + message.writeBytes(MESSAGE_DATA_BYTES, 0, mod); + } + } + + return message; + } + /** * 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 -- cgit v1.2.1