You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2015/06/09 18:36:38 UTC
[07/52] [abbrv] [partial] activemq-artemis git commit: ARTEMIS-127
Adding activemq unit test module to Artemis
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/command/ActiveMQStreamMessageTest.java
----------------------------------------------------------------------
diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/command/ActiveMQStreamMessageTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/command/ActiveMQStreamMessageTest.java
new file mode 100644
index 0000000..9e0f468
--- /dev/null
+++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/command/ActiveMQStreamMessageTest.java
@@ -0,0 +1,1000 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.command;
+
+import java.io.Serializable;
+
+import javax.jms.JMSException;
+import javax.jms.MessageFormatException;
+import javax.jms.MessageNotReadableException;
+import javax.jms.MessageNotWriteableException;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ */
+public class ActiveMQStreamMessageTest extends TestCase {
+
+ /**
+ * Constructor for ActiveMQStreamMessageTest.
+ *
+ * @param name
+ */
+ public ActiveMQStreamMessageTest(String name) {
+ super(name);
+ }
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(ActiveMQStreamMessageTest.class);
+ }
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ /*
+ * @see TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testGetDataStructureType() {
+ ActiveMQStreamMessage msg = new ActiveMQStreamMessage();
+ assertEquals(msg.getDataStructureType(), CommandTypes.ACTIVEMQ_STREAM_MESSAGE);
+ }
+
+ public void testReadBoolean() {
+ ActiveMQStreamMessage msg = new ActiveMQStreamMessage();
+ try {
+ msg.writeBoolean(true);
+ msg.reset();
+ assertTrue(msg.readBoolean());
+ msg.reset();
+ assertTrue(msg.readString().equals("true"));
+ msg.reset();
+ try {
+ msg.readByte();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readShort();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readInt();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readLong();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readFloat();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readDouble();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readChar();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readBytes(new byte[1]);
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ } catch (JMSException jmsEx) {
+ jmsEx.printStackTrace();
+ assertTrue(false);
+ }
+ }
+
+ public void testreadByte() {
+ ActiveMQStreamMessage msg = new ActiveMQStreamMessage();
+ try {
+ byte test = (byte)4;
+ msg.writeByte(test);
+ msg.reset();
+ assertTrue(msg.readByte() == test);
+ msg.reset();
+ assertTrue(msg.readShort() == test);
+ msg.reset();
+ assertTrue(msg.readInt() == test);
+ msg.reset();
+ assertTrue(msg.readLong() == test);
+ msg.reset();
+ assertTrue(msg.readString().equals(new Byte(test).toString()));
+ msg.reset();
+ try {
+ msg.readBoolean();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readFloat();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readDouble();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readChar();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readBytes(new byte[1]);
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ } catch (JMSException jmsEx) {
+ jmsEx.printStackTrace();
+ assertTrue(false);
+ }
+ }
+
+ public void testReadShort() {
+ ActiveMQStreamMessage msg = new ActiveMQStreamMessage();
+ try {
+ short test = (short)4;
+ msg.writeShort(test);
+ msg.reset();
+ assertTrue(msg.readShort() == test);
+ msg.reset();
+ assertTrue(msg.readInt() == test);
+ msg.reset();
+ assertTrue(msg.readLong() == test);
+ msg.reset();
+ assertTrue(msg.readString().equals(new Short(test).toString()));
+ msg.reset();
+ try {
+ msg.readBoolean();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readByte();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readFloat();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readDouble();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readChar();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readBytes(new byte[1]);
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ } catch (JMSException jmsEx) {
+ jmsEx.printStackTrace();
+ assertTrue(false);
+ }
+ }
+
+ public void testReadChar() {
+ ActiveMQStreamMessage msg = new ActiveMQStreamMessage();
+ try {
+ char test = 'z';
+ msg.writeChar(test);
+ msg.reset();
+ assertTrue(msg.readChar() == test);
+ msg.reset();
+ assertTrue(msg.readString().equals(new Character(test).toString()));
+ msg.reset();
+ try {
+ msg.readBoolean();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readByte();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readShort();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readInt();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readLong();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readFloat();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readDouble();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readBytes(new byte[1]);
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ } catch (JMSException jmsEx) {
+ jmsEx.printStackTrace();
+ assertTrue(false);
+ }
+ }
+
+ public void testReadInt() {
+ ActiveMQStreamMessage msg = new ActiveMQStreamMessage();
+ try {
+ int test = 4;
+ msg.writeInt(test);
+ msg.reset();
+ assertTrue(msg.readInt() == test);
+ msg.reset();
+ assertTrue(msg.readLong() == test);
+ msg.reset();
+ assertTrue(msg.readString().equals(new Integer(test).toString()));
+ msg.reset();
+ try {
+ msg.readBoolean();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readByte();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readShort();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readFloat();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readDouble();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readChar();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readBytes(new byte[1]);
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ } catch (JMSException jmsEx) {
+ jmsEx.printStackTrace();
+ assertTrue(false);
+ }
+ }
+
+ public void testReadLong() {
+ ActiveMQStreamMessage msg = new ActiveMQStreamMessage();
+ try {
+ long test = 4L;
+ msg.writeLong(test);
+ msg.reset();
+ assertTrue(msg.readLong() == test);
+ msg.reset();
+ assertTrue(msg.readString().equals(Long.valueOf(test).toString()));
+ msg.reset();
+ try {
+ msg.readBoolean();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readByte();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readShort();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readInt();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readFloat();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readDouble();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readChar();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readBytes(new byte[1]);
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg = new ActiveMQStreamMessage();
+ msg.writeObject(new Long("1"));
+ // reset so it's readable now
+ msg.reset();
+ assertEquals(new Long("1"), msg.readObject());
+ } catch (JMSException jmsEx) {
+ jmsEx.printStackTrace();
+ assertTrue(false);
+ }
+ }
+
+ public void testReadFloat() {
+ ActiveMQStreamMessage msg = new ActiveMQStreamMessage();
+ try {
+ float test = 4.4f;
+ msg.writeFloat(test);
+ msg.reset();
+ assertTrue(msg.readFloat() == test);
+ msg.reset();
+ assertTrue(msg.readDouble() == test);
+ msg.reset();
+ assertTrue(msg.readString().equals(new Float(test).toString()));
+ msg.reset();
+ try {
+ msg.readBoolean();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readByte();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readShort();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readInt();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readLong();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readChar();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readBytes(new byte[1]);
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ } catch (JMSException jmsEx) {
+ jmsEx.printStackTrace();
+ assertTrue(false);
+ }
+ }
+
+ public void testReadDouble() {
+ ActiveMQStreamMessage msg = new ActiveMQStreamMessage();
+ try {
+ double test = 4.4d;
+ msg.writeDouble(test);
+ msg.reset();
+ assertTrue(msg.readDouble() == test);
+ msg.reset();
+ assertTrue(msg.readString().equals(new Double(test).toString()));
+ msg.reset();
+ try {
+ msg.readBoolean();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readByte();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readShort();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readInt();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readLong();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readFloat();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readChar();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readBytes(new byte[1]);
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ } catch (JMSException jmsEx) {
+ jmsEx.printStackTrace();
+ assertTrue(false);
+ }
+
+ }
+
+ public void testReadString() {
+ ActiveMQStreamMessage msg = new ActiveMQStreamMessage();
+ try {
+ byte testByte = (byte)2;
+ msg.writeString(new Byte(testByte).toString());
+ msg.reset();
+ assertTrue(msg.readByte() == testByte);
+ msg.clearBody();
+ short testShort = 3;
+ msg.writeString(new Short(testShort).toString());
+ msg.reset();
+ assertTrue(msg.readShort() == testShort);
+ msg.clearBody();
+ int testInt = 4;
+ msg.writeString(new Integer(testInt).toString());
+ msg.reset();
+ assertTrue(msg.readInt() == testInt);
+ msg.clearBody();
+ long testLong = 6L;
+ msg.writeString(new Long(testLong).toString());
+ msg.reset();
+ assertTrue(msg.readLong() == testLong);
+ msg.clearBody();
+ float testFloat = 6.6f;
+ msg.writeString(new Float(testFloat).toString());
+ msg.reset();
+ assertTrue(msg.readFloat() == testFloat);
+ msg.clearBody();
+ double testDouble = 7.7d;
+ msg.writeString(new Double(testDouble).toString());
+ msg.reset();
+ assertTrue(msg.readDouble() == testDouble);
+ msg.clearBody();
+ msg.writeString("true");
+ msg.reset();
+ assertTrue(msg.readBoolean());
+ msg.clearBody();
+ msg.writeString("a");
+ msg.reset();
+ try {
+ msg.readChar();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException e) {
+ }
+ msg.clearBody();
+ msg.writeString("777");
+ msg.reset();
+ try {
+ msg.readBytes(new byte[3]);
+ fail("Should have thrown exception");
+ } catch (MessageFormatException e) {
+ }
+
+ } catch (JMSException jmsEx) {
+ jmsEx.printStackTrace();
+ assertTrue(false);
+ }
+ }
+
+ public void testReadBigString() {
+ ActiveMQStreamMessage msg = new ActiveMQStreamMessage();
+ try {
+ // Test with a 1Meg String
+ StringBuffer bigSB = new StringBuffer(1024 * 1024);
+ for (int i = 0; i < 1024 * 1024; i++) {
+ bigSB.append((char)'a' + i % 26);
+ }
+ String bigString = bigSB.toString();
+
+ msg.writeString(bigString);
+ msg.reset();
+ assertEquals(bigString, msg.readString());
+
+ } catch (JMSException jmsEx) {
+ jmsEx.printStackTrace();
+ assertTrue(false);
+ }
+ }
+
+ public void testReadBytes() {
+ ActiveMQStreamMessage msg = new ActiveMQStreamMessage();
+ try {
+ byte[] test = new byte[50];
+ for (int i = 0; i < test.length; i++) {
+ test[i] = (byte)i;
+ }
+ msg.writeBytes(test);
+ msg.reset();
+ byte[] valid = new byte[test.length];
+ msg.readBytes(valid);
+ for (int i = 0; i < valid.length; i++) {
+ assertTrue(valid[i] == test[i]);
+ }
+ msg.reset();
+ try {
+ msg.readByte();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readShort();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readInt();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readLong();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readFloat();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readChar();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ msg.reset();
+ try {
+ msg.readString();
+ fail("Should have thrown exception");
+ } catch (MessageFormatException mfe) {
+ }
+ } catch (JMSException jmsEx) {
+ jmsEx.printStackTrace();
+ assertTrue(false);
+ }
+ }
+
+ public void testReadObject() {
+ ActiveMQStreamMessage msg = new ActiveMQStreamMessage();
+ try {
+ byte testByte = (byte)2;
+ msg.writeByte(testByte);
+ msg.reset();
+ assertTrue(((Byte)msg.readObject()).byteValue() == testByte);
+ msg.clearBody();
+
+ short testShort = 3;
+ msg.writeShort(testShort);
+ msg.reset();
+ assertTrue(((Short)msg.readObject()).shortValue() == testShort);
+ msg.clearBody();
+
+ int testInt = 4;
+ msg.writeInt(testInt);
+ msg.reset();
+ assertTrue(((Integer)msg.readObject()).intValue() == testInt);
+ msg.clearBody();
+
+ long testLong = 6L;
+ msg.writeLong(testLong);
+ msg.reset();
+ assertTrue(((Long)msg.readObject()).longValue() == testLong);
+ msg.clearBody();
+
+ float testFloat = 6.6f;
+ msg.writeFloat(testFloat);
+ msg.reset();
+ assertTrue(((Float)msg.readObject()).floatValue() == testFloat);
+ msg.clearBody();
+
+ double testDouble = 7.7d;
+ msg.writeDouble(testDouble);
+ msg.reset();
+ assertTrue(((Double)msg.readObject()).doubleValue() == testDouble);
+ msg.clearBody();
+
+ char testChar = 'z';
+ msg.writeChar(testChar);
+ msg.reset();
+ assertTrue(((Character)msg.readObject()).charValue() == testChar);
+ msg.clearBody();
+
+ byte[] data = new byte[50];
+ for (int i = 0; i < data.length; i++) {
+ data[i] = (byte)i;
+ }
+ msg.writeBytes(data);
+ msg.reset();
+ byte[] valid = (byte[])msg.readObject();
+ assertTrue(valid.length == data.length);
+ for (int i = 0; i < valid.length; i++) {
+ assertTrue(valid[i] == data[i]);
+ }
+ msg.clearBody();
+ msg.writeBoolean(true);
+ msg.reset();
+ assertTrue(((Boolean)msg.readObject()).booleanValue());
+
+ } catch (JMSException jmsEx) {
+ jmsEx.printStackTrace();
+ assertTrue(false);
+ }
+ }
+
+ public void testClearBody() throws JMSException {
+ ActiveMQStreamMessage streamMessage = new ActiveMQStreamMessage();
+ try {
+ streamMessage.writeObject(new Long(2));
+ streamMessage.clearBody();
+ assertFalse(streamMessage.isReadOnlyBody());
+ streamMessage.writeObject(new Long(2));
+ streamMessage.readObject();
+ fail("should throw exception");
+ } catch (MessageNotReadableException mnwe) {
+ } catch (MessageNotWriteableException mnwe) {
+ fail("should be writeable");
+ }
+ }
+
+ public void testReset() throws JMSException {
+ ActiveMQStreamMessage streamMessage = new ActiveMQStreamMessage();
+ try {
+ streamMessage.writeDouble(24.5);
+ streamMessage.writeLong(311);
+ } catch (MessageNotWriteableException mnwe) {
+ fail("should be writeable");
+ }
+ streamMessage.reset();
+ try {
+ assertTrue(streamMessage.isReadOnlyBody());
+ assertEquals(streamMessage.readDouble(), 24.5, 0);
+ assertEquals(streamMessage.readLong(), 311);
+ } catch (MessageNotReadableException mnre) {
+ fail("should be readable");
+ }
+ try {
+ streamMessage.writeInt(33);
+ fail("should throw exception");
+ } catch (MessageNotWriteableException mnwe) {
+ }
+ }
+
+ public void testReadOnlyBody() throws JMSException {
+ ActiveMQStreamMessage message = new ActiveMQStreamMessage();
+ try {
+ message.writeBoolean(true);
+ message.writeByte((byte)1);
+ message.writeBytes(new byte[1]);
+ message.writeBytes(new byte[3], 0, 2);
+ message.writeChar('a');
+ message.writeDouble(1.5);
+ message.writeFloat((float)1.5);
+ message.writeInt(1);
+ message.writeLong(1);
+ message.writeObject("stringobj");
+ message.writeShort((short)1);
+ message.writeString("string");
+ } catch (MessageNotWriteableException mnwe) {
+ fail("Should be writeable");
+ }
+ message.reset();
+ try {
+ message.readBoolean();
+ message.readByte();
+ assertEquals(1, message.readBytes(new byte[10]));
+ assertEquals(-1, message.readBytes(new byte[10]));
+ assertEquals(2, message.readBytes(new byte[10]));
+ assertEquals(-1, message.readBytes(new byte[10]));
+ message.readChar();
+ message.readDouble();
+ message.readFloat();
+ message.readInt();
+ message.readLong();
+ message.readString();
+ message.readShort();
+ message.readString();
+ } catch (MessageNotReadableException mnwe) {
+ fail("Should be readable");
+ }
+ try {
+ message.writeBoolean(true);
+ fail("Should have thrown exception");
+ } catch (MessageNotWriteableException mnwe) {
+ }
+ try {
+ message.writeByte((byte)1);
+ fail("Should have thrown exception");
+ } catch (MessageNotWriteableException mnwe) {
+ }
+ try {
+ message.writeBytes(new byte[1]);
+ fail("Should have thrown exception");
+ } catch (MessageNotWriteableException mnwe) {
+ }
+ try {
+ message.writeBytes(new byte[3], 0, 2);
+ fail("Should have thrown exception");
+ } catch (MessageNotWriteableException mnwe) {
+ }
+ try {
+ message.writeChar('a');
+ fail("Should have thrown exception");
+ } catch (MessageNotWriteableException mnwe) {
+ }
+ try {
+ message.writeDouble(1.5);
+ fail("Should have thrown exception");
+ } catch (MessageNotWriteableException mnwe) {
+ }
+ try {
+ message.writeFloat((float)1.5);
+ fail("Should have thrown exception");
+ } catch (MessageNotWriteableException mnwe) {
+ }
+ try {
+ message.writeInt(1);
+ fail("Should have thrown exception");
+ } catch (MessageNotWriteableException mnwe) {
+ }
+ try {
+ message.writeLong(1);
+ fail("Should have thrown exception");
+ } catch (MessageNotWriteableException mnwe) {
+ }
+ try {
+ message.writeObject("stringobj");
+ fail("Should have thrown exception");
+ } catch (MessageNotWriteableException mnwe) {
+ }
+ try {
+ message.writeShort((short)1);
+ fail("Should have thrown exception");
+ } catch (MessageNotWriteableException mnwe) {
+ }
+ try {
+ message.writeString("string");
+ fail("Should have thrown exception");
+ } catch (MessageNotWriteableException mnwe) {
+ }
+ }
+
+ public void testWriteOnlyBody() throws JMSException {
+ ActiveMQStreamMessage message = new ActiveMQStreamMessage();
+ message.clearBody();
+ try {
+ message.writeBoolean(true);
+ message.writeByte((byte)1);
+ message.writeBytes(new byte[1]);
+ message.writeBytes(new byte[3], 0, 2);
+ message.writeChar('a');
+ message.writeDouble(1.5);
+ message.writeFloat((float)1.5);
+ message.writeInt(1);
+ message.writeLong(1);
+ message.writeObject("stringobj");
+ message.writeShort((short)1);
+ message.writeString("string");
+ } catch (MessageNotWriteableException mnwe) {
+ fail("Should be writeable");
+ }
+ try {
+ message.readBoolean();
+ fail("Should have thrown exception");
+ } catch (MessageNotReadableException mnwe) {
+ }
+ try {
+ message.readByte();
+ fail("Should have thrown exception");
+ } catch (MessageNotReadableException e) {
+ }
+ try {
+ message.readBytes(new byte[1]);
+ fail("Should have thrown exception");
+ } catch (MessageNotReadableException e) {
+ }
+ try {
+ message.readBytes(new byte[2]);
+ fail("Should have thrown exception");
+ } catch (MessageNotReadableException e) {
+ }
+ try {
+ message.readChar();
+ fail("Should have thrown exception");
+ } catch (MessageNotReadableException e) {
+ }
+ try {
+ message.readDouble();
+ fail("Should have thrown exception");
+ } catch (MessageNotReadableException e) {
+ }
+ try {
+ message.readFloat();
+ fail("Should have thrown exception");
+ } catch (MessageNotReadableException e) {
+ }
+ try {
+ message.readInt();
+ fail("Should have thrown exception");
+ } catch (MessageNotReadableException e) {
+ }
+ try {
+ message.readLong();
+ fail("Should have thrown exception");
+ } catch (MessageNotReadableException e) {
+ }
+ try {
+ message.readString();
+ fail("Should have thrown exception");
+ } catch (MessageNotReadableException e) {
+ }
+ try {
+ message.readShort();
+ fail("Should have thrown exception");
+ } catch (MessageNotReadableException e) {
+ }
+ try {
+ message.readString();
+ fail("Should have thrown exception");
+ } catch (MessageNotReadableException e) {
+ }
+ }
+
+ public void testWriteObject() {
+ try {
+ ActiveMQStreamMessage message = new ActiveMQStreamMessage();
+ message.clearBody();
+ message.writeObject("test");
+ message.writeObject(new Character('a'));
+ message.writeObject(new Boolean(false));
+ message.writeObject(new Byte((byte) 2));
+ message.writeObject(new Short((short) 2));
+ message.writeObject(new Integer(2));
+ message.writeObject(new Long(2l));
+ message.writeObject(new Float(2.0f));
+ message.writeObject(new Double(2.0d));
+ }catch(Exception e) {
+ fail(e.getMessage());
+ }
+ try {
+ ActiveMQStreamMessage message = new ActiveMQStreamMessage();
+ message.clearBody();
+ message.writeObject(new Object());
+ fail("should throw an exception");
+ }catch(MessageFormatException e) {
+
+ }catch(Exception e) {
+ fail(e.getMessage());
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/command/ActiveMQTextMessageTest.java
----------------------------------------------------------------------
diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/command/ActiveMQTextMessageTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/command/ActiveMQTextMessageTest.java
new file mode 100644
index 0000000..28fc307
--- /dev/null
+++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/command/ActiveMQTextMessageTest.java
@@ -0,0 +1,159 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.command;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import javax.jms.JMSException;
+import javax.jms.MessageNotReadableException;
+import javax.jms.MessageNotWriteableException;
+
+import junit.framework.TestCase;
+import junit.textui.TestRunner;
+
+import org.apache.activemq.util.ByteArrayOutputStream;
+import org.apache.activemq.util.ByteSequence;
+import org.apache.activemq.util.MarshallingSupport;
+
+/**
+ *
+ */
+public class ActiveMQTextMessageTest extends TestCase {
+
+ public static void main(String[] args) {
+ TestRunner.run(ActiveMQTextMessageTest.class);
+ }
+
+ public void testGetDataStructureType() {
+ ActiveMQTextMessage msg = new ActiveMQTextMessage();
+ assertEquals(msg.getDataStructureType(), CommandTypes.ACTIVEMQ_TEXT_MESSAGE);
+ }
+
+ public void testShallowCopy() throws JMSException {
+ ActiveMQTextMessage msg = new ActiveMQTextMessage();
+ String string = "str";
+ msg.setText(string);
+ Message copy = msg.copy();
+ assertTrue(msg.getText() == ((ActiveMQTextMessage) copy).getText());
+ }
+
+ public void testSetText() {
+ ActiveMQTextMessage msg = new ActiveMQTextMessage();
+ String str = "testText";
+ try {
+ msg.setText(str);
+ assertEquals(msg.getText(), str);
+ } catch (JMSException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void testGetBytes() throws JMSException, IOException {
+ ActiveMQTextMessage msg = new ActiveMQTextMessage();
+ String str = "testText";
+ msg.setText(str);
+ msg.beforeMarshall(null);
+
+ ByteSequence bytes = msg.getContent();
+ msg = new ActiveMQTextMessage();
+ msg.setContent(bytes);
+
+ assertEquals(msg.getText(), str);
+ }
+
+ public void testClearBody() throws JMSException, IOException {
+ ActiveMQTextMessage textMessage = new ActiveMQTextMessage();
+ textMessage.setText("string");
+ textMessage.clearBody();
+ assertFalse(textMessage.isReadOnlyBody());
+ assertNull(textMessage.getText());
+ try {
+ textMessage.setText("String");
+ textMessage.getText();
+ } catch (MessageNotWriteableException mnwe) {
+ fail("should be writeable");
+ } catch (MessageNotReadableException mnre) {
+ fail("should be readable");
+ }
+ }
+
+ public void testReadOnlyBody() throws JMSException {
+ ActiveMQTextMessage textMessage = new ActiveMQTextMessage();
+ textMessage.setText("test");
+ textMessage.setReadOnlyBody(true);
+ try {
+ textMessage.getText();
+ } catch (MessageNotReadableException e) {
+ fail("should be readable");
+ }
+ try {
+ textMessage.setText("test");
+ fail("should throw exception");
+ } catch (MessageNotWriteableException mnwe) {
+ }
+ }
+
+ public void testWriteOnlyBody() throws JMSException { // should always be readable
+ ActiveMQTextMessage textMessage = new ActiveMQTextMessage();
+ textMessage.setReadOnlyBody(false);
+ try {
+ textMessage.setText("test");
+ textMessage.getText();
+ } catch (MessageNotReadableException e) {
+ fail("should be readable");
+ }
+ textMessage.setReadOnlyBody(true);
+ try {
+ textMessage.getText();
+ textMessage.setText("test");
+ fail("should throw exception");
+ } catch (MessageNotReadableException e) {
+ fail("should be readable");
+ } catch (MessageNotWriteableException mnwe) {
+ }
+ }
+
+ public void testShortText() throws Exception {
+ String shortText = "Content";
+ ActiveMQTextMessage shortMessage = new ActiveMQTextMessage();
+ setContent(shortMessage, shortText);
+ assertTrue(shortMessage.toString().contains("text = " + shortText));
+ assertTrue(shortMessage.getText().equals(shortText));
+
+ String longText = "Very very very very veeeeeeery loooooooooooooooooooooooooooooooooong text";
+ String longExpectedText = "Very very very very veeeeeeery looooooooooooo...ooooong text";
+ ActiveMQTextMessage longMessage = new ActiveMQTextMessage();
+ setContent(longMessage, longText);
+ assertTrue(longMessage.toString().contains("text = " + longExpectedText));
+ assertTrue(longMessage.getText().equals(longText));
+ }
+
+ public void testNullText() throws Exception {
+ ActiveMQTextMessage nullMessage = new ActiveMQTextMessage();
+ setContent(nullMessage, null);
+ assertTrue(nullMessage.toString().contains("text = null"));
+ }
+
+ protected void setContent(Message message, String text) throws Exception {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ DataOutputStream dataOut = new DataOutputStream(baos);
+ MarshallingSupport.writeUTF8(dataOut, text);
+ dataOut.close();
+ message.setContent(baos.toByteSequence());
+ }
+}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/command/DataStructureTestSupport.java
----------------------------------------------------------------------
diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/command/DataStructureTestSupport.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/command/DataStructureTestSupport.java
new file mode 100644
index 0000000..fa977af
--- /dev/null
+++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/command/DataStructureTestSupport.java
@@ -0,0 +1,158 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.command;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+
+import junit.framework.AssertionFailedError;
+import junit.framework.TestCase;
+import org.apache.activemq.CombinationTestSupport;
+import org.apache.activemq.openwire.OpenWireFormat;
+import org.apache.activemq.util.ByteSequence;
+import org.apache.activemq.wireformat.WireFormat;
+
+public abstract class DataStructureTestSupport extends CombinationTestSupport {
+ public boolean cacheEnabled;
+ public WireFormat wireFormat;
+
+ public void assertBeanMarshalls(Object original) throws IOException {
+ Object o = marshalAndUnmarshall(original, wireFormat);
+ assertNotNull(o);
+ assertEquals(original, o);
+ // assertEquals(original.getClass(), o.getClass());
+ //
+ // Method[] methods = original.getClass().getMethods();
+ // for (int i = 0; i < methods.length; i++) {
+ // Method method = methods[i];
+ // if( ( method.getName().startsWith("get")
+ // || method.getName().startsWith("is")
+ // )
+ // && method.getParameterTypes().length==0
+ // && method.getReturnType()!=null
+ // ) {
+ // try {
+ // Object expect = method.invoke(original, null);
+ // Object was = method.invoke(o, null);
+ // assertEquals(expect, was);
+ // } catch (IllegalArgumentException e) {
+ // } catch (IllegalAccessException e) {
+ // } catch (InvocationTargetException e) {
+ // }
+ // }
+ // }
+ }
+
+ public static void assertEquals(Object expect, Object was) {
+ if (expect == null ^ was == null) {
+ throw new AssertionFailedError("Not equals, expected: " + expect + ", was: " + was);
+ }
+ if (expect == null) {
+ return;
+ }
+ if (expect.getClass() != was.getClass()) {
+ throw new AssertionFailedError("Not equals, classes don't match. expected: " + expect.getClass() + ", was: " + was.getClass());
+ }
+ if (expect.getClass().isArray()) {
+ Class componentType = expect.getClass().getComponentType();
+ if (componentType.isPrimitive()) {
+ boolean ok = false;
+ if (componentType == byte.class) {
+ ok = Arrays.equals((byte[])expect, (byte[])was);
+ }
+ if (componentType == char.class) {
+ ok = Arrays.equals((char[])expect, (char[])was);
+ }
+ if (componentType == short.class) {
+ ok = Arrays.equals((short[])expect, (short[])was);
+ }
+ if (componentType == int.class) {
+ ok = Arrays.equals((int[])expect, (int[])was);
+ }
+ if (componentType == long.class) {
+ ok = Arrays.equals((long[])expect, (long[])was);
+ }
+ if (componentType == double.class) {
+ ok = Arrays.equals((double[])expect, (double[])was);
+ }
+ if (componentType == float.class) {
+ ok = Arrays.equals((float[])expect, (float[])was);
+ }
+ if (!ok) {
+ throw new AssertionFailedError("Arrays not equal");
+ }
+ } else {
+ Object expectArray[] = (Object[])expect;
+ Object wasArray[] = (Object[])was;
+ if (expectArray.length != wasArray.length) {
+ throw new AssertionFailedError("Not equals, array lengths don't match. expected: " + expectArray.length + ", was: " + wasArray.length);
+ }
+ for (int i = 0; i < wasArray.length; i++) {
+ assertEquals(expectArray[i], wasArray[i]);
+ }
+
+ }
+ } else if (expect instanceof Command) {
+ assertEquals(expect.getClass(), was.getClass());
+ Method[] methods = expect.getClass().getMethods();
+ for (int i = 0; i < methods.length; i++) {
+ Method method = methods[i];
+ if ((method.getName().startsWith("get") || method.getName().startsWith("is")) && method.getParameterTypes().length == 0 && method.getReturnType() != null) {
+
+ // Check to see if there is a setter for the method.
+ try {
+ if (method.getName().startsWith("get")) {
+ expect.getClass().getMethod(method.getName().replaceFirst("get", "set"), new Class[] {method.getReturnType()});
+ } else {
+ expect.getClass().getMethod(method.getName().replaceFirst("is", "set"), new Class[] {method.getReturnType()});
+ }
+ } catch (Throwable ignore) {
+ continue;
+ }
+
+ try {
+ assertEquals(method.invoke(expect, (Object)null), method.invoke(was, (Object)null));
+ } catch (IllegalArgumentException e) {
+ } catch (IllegalAccessException e) {
+ } catch (InvocationTargetException e) {
+ }
+ }
+ }
+ } else {
+ TestCase.assertEquals(expect, was);
+ }
+ }
+
+ protected void setUp() throws Exception {
+ wireFormat = createWireFormat();
+ super.setUp();
+ }
+
+ protected WireFormat createWireFormat() {
+ OpenWireFormat answer = new OpenWireFormat();
+ answer.setCacheEnabled(cacheEnabled);
+ return answer;
+ }
+
+ protected Object marshalAndUnmarshall(Object original, WireFormat wireFormat) throws IOException {
+ ByteSequence packet = wireFormat.marshal(original);
+ return wireFormat.unmarshal(packet);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/command/MessageCompressionTest.java
----------------------------------------------------------------------
diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/command/MessageCompressionTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/command/MessageCompressionTest.java
new file mode 100644
index 0000000..4c77bfc
--- /dev/null
+++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/command/MessageCompressionTest.java
@@ -0,0 +1,143 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.command;
+
+import java.io.UnsupportedEncodingException;
+
+import javax.jms.BytesMessage;
+import javax.jms.JMSException;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+
+import junit.framework.TestCase;
+
+import org.apache.activemq.ActiveMQConnection;
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.broker.BrokerService;
+
+public class MessageCompressionTest extends TestCase {
+
+ private static final String BROKER_URL = "tcp://localhost:0";
+ // The following text should compress well
+ private static final String TEXT = "The quick red fox jumped over the lazy brown dog. "
+ + "The quick red fox jumped over the lazy brown dog. " + "The quick red fox jumped over the lazy brown dog. "
+ + "The quick red fox jumped over the lazy brown dog. " + "The quick red fox jumped over the lazy brown dog. "
+ + "The quick red fox jumped over the lazy brown dog. " + "The quick red fox jumped over the lazy brown dog. "
+ + "The quick red fox jumped over the lazy brown dog. " + "The quick red fox jumped over the lazy brown dog. "
+ + "The quick red fox jumped over the lazy brown dog. " + "The quick red fox jumped over the lazy brown dog. "
+ + "The quick red fox jumped over the lazy brown dog. " + "The quick red fox jumped over the lazy brown dog. "
+ + "The quick red fox jumped over the lazy brown dog. " + "The quick red fox jumped over the lazy brown dog. "
+ + "The quick red fox jumped over the lazy brown dog. " + "The quick red fox jumped over the lazy brown dog. ";
+
+ private BrokerService broker;
+ private ActiveMQQueue queue;
+ private String connectionUri;
+
+ protected void setUp() throws Exception {
+ broker = new BrokerService();
+ connectionUri = broker.addConnector(BROKER_URL).getPublishableConnectString();
+ broker.start();
+ queue = new ActiveMQQueue("TEST." + System.currentTimeMillis());
+ }
+
+ protected void tearDown() throws Exception {
+ if (broker != null) {
+ broker.stop();
+ }
+ }
+
+ public void testTextMessageCompression() throws Exception {
+
+ ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(connectionUri);
+ factory.setUseCompression(true);
+ sendTestMessage(factory, TEXT);
+ ActiveMQTextMessage message = receiveTestMessage(factory);
+ int compressedSize = message.getContent().getLength();
+
+ factory = new ActiveMQConnectionFactory(connectionUri);
+ factory.setUseCompression(false);
+ sendTestMessage(factory, TEXT);
+ message = receiveTestMessage(factory);
+ int unCompressedSize = message.getContent().getLength();
+
+ assertTrue("expected: compressed Size '" + compressedSize + "' < unCompressedSize '" + unCompressedSize + "'",
+ compressedSize < unCompressedSize);
+ }
+
+ public void testBytesMessageCompression() throws Exception {
+
+ ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(connectionUri);
+ factory.setUseCompression(true);
+ sendTestBytesMessage(factory, TEXT);
+ ActiveMQBytesMessage message = receiveTestBytesMessage(factory);
+ int compressedSize = message.getContent().getLength();
+ byte[] bytes = new byte[TEXT.getBytes("UTF8").length];
+ message.readBytes(bytes);
+ assertTrue(message.readBytes(new byte[255]) == -1);
+ String rcvString = new String(bytes, "UTF8");
+ assertEquals(TEXT, rcvString);
+ assertTrue(message.isCompressed());
+
+ factory = new ActiveMQConnectionFactory(connectionUri);
+ factory.setUseCompression(false);
+ sendTestBytesMessage(factory, TEXT);
+ message = receiveTestBytesMessage(factory);
+ int unCompressedSize = message.getContent().getLength();
+
+ assertTrue("expected: compressed Size '" + compressedSize + "' < unCompressedSize '" + unCompressedSize + "'",
+ compressedSize < unCompressedSize);
+ }
+
+ private void sendTestMessage(ActiveMQConnectionFactory factory, String message) throws JMSException {
+ ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection();
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer producer = session.createProducer(queue);
+ producer.send(session.createTextMessage(message));
+ connection.close();
+ }
+
+ private ActiveMQTextMessage receiveTestMessage(ActiveMQConnectionFactory factory) throws JMSException {
+ ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection();
+ connection.start();
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageConsumer consumer = session.createConsumer(queue);
+ ActiveMQTextMessage rc = (ActiveMQTextMessage) consumer.receive();
+ connection.close();
+ return rc;
+ }
+
+ private void sendTestBytesMessage(ActiveMQConnectionFactory factory, String message) throws JMSException, UnsupportedEncodingException {
+ ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection();
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer producer = session.createProducer(queue);
+ BytesMessage bytesMessage = session.createBytesMessage();
+ bytesMessage.writeBytes(message.getBytes("UTF8"));
+ producer.send(bytesMessage);
+ connection.close();
+ }
+
+ private ActiveMQBytesMessage receiveTestBytesMessage(ActiveMQConnectionFactory factory) throws JMSException, UnsupportedEncodingException {
+ ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection();
+ connection.start();
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageConsumer consumer = session.createConsumer(queue);
+ ActiveMQBytesMessage rc = (ActiveMQBytesMessage) consumer.receive();
+ connection.close();
+ return rc;
+ }
+}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/command/MessageSendTest.java
----------------------------------------------------------------------
diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/command/MessageSendTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/command/MessageSendTest.java
new file mode 100644
index 0000000..ec81800
--- /dev/null
+++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/command/MessageSendTest.java
@@ -0,0 +1,78 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.command;
+
+import java.io.IOException;
+
+import junit.framework.Test;
+
+import org.apache.activemq.util.ByteSequence;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MessageSendTest extends DataStructureTestSupport {
+ private static final Logger LOG = LoggerFactory.getLogger(MessageSendTest.class);
+
+ public static Test suite() {
+ return suite(MessageSendTest.class);
+ }
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(suite());
+ }
+
+ public void initCombosForTestMessageSendMarshaling() {
+ addCombinationValues("cacheEnabled", new Object[] {Boolean.TRUE, Boolean.FALSE});
+ }
+
+ public void testMessageSendMarshaling() throws IOException {
+ ActiveMQMessage message = new ActiveMQMessage();
+ message.setCommandId((short)1);
+ message.setDestination(new ActiveMQQueue("queue"));
+ message.setGroupID("group");
+ message.setGroupSequence(4);
+ message.setCorrelationId("correlation");
+ message.setMessageId(new MessageId("c1:1:1", 1));
+
+ assertBeanMarshalls(message);
+ assertBeanMarshalls(message);
+
+ }
+
+ public void xtestPerformance() throws IOException {
+ ActiveMQMessage message = new ActiveMQMessage();
+ message.setProducerId(new ProducerId(new SessionId(new ConnectionId(new ConnectionId("test")), 1), 1));
+ message.setMessageId(new MessageId(message.getProducerId(), 1));
+ message.setCommandId((short)1);
+ message.setGroupID("group");
+ message.setGroupSequence(4);
+ message.setCorrelationId("correlation");
+ message.setContent(new ByteSequence(new byte[1024], 0, 1024));
+ message.setTimestamp(System.currentTimeMillis());
+ message.setDestination(new ActiveMQQueue("TEST"));
+
+ int p = 1000000;
+
+ long start = System.currentTimeMillis();
+ for (int i = 0; i < p; i++) {
+ marshalAndUnmarshall(message, wireFormat);
+ }
+ long end = System.currentTimeMillis();
+
+ LOG.info("marshaled/unmarshaled: " + p + " msgs at " + (p * 1000f / (end - start)) + " msgs/sec");
+ }
+}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/command/MessageTest.java
----------------------------------------------------------------------
diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/command/MessageTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/command/MessageTest.java
new file mode 100644
index 0000000..f33c5b4
--- /dev/null
+++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/command/MessageTest.java
@@ -0,0 +1,100 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.command;
+
+import java.io.IOException;
+
+import junit.framework.Test;
+import junit.textui.TestRunner;
+
+public class MessageTest extends DataStructureTestSupport {
+
+ public boolean cacheEnabled;
+
+ public static Test suite() {
+ return suite(MessageTest.class);
+ }
+
+ public static void main(String[] args) {
+ TestRunner.run(suite());
+ }
+
+ public void initCombosForTestActiveMQMessageMarshaling() {
+ addCombinationValues("cacheEnabled", new Object[] {Boolean.TRUE, Boolean.FALSE});
+ }
+
+ public void testActiveMQMessageMarshaling() throws IOException {
+ ActiveMQMessage message = new ActiveMQMessage();
+ message.setCommandId((short)1);
+ message.setOriginalDestination(new ActiveMQQueue("queue"));
+ message.setGroupID("group");
+ message.setGroupSequence(4);
+ message.setCorrelationId("correlation");
+ message.setMessageId(new MessageId("c1:1:1", 1));
+ assertBeanMarshalls(message);
+ }
+
+ public void testActiveMQMessageMarshalingBigMessageId() throws IOException {
+ ActiveMQMessage message = new ActiveMQMessage();
+ message.setCommandId((short)1);
+ message.setOriginalDestination(new ActiveMQQueue("queue"));
+ message.setGroupID("group");
+ message.setGroupSequence(4);
+ message.setCorrelationId("correlation");
+ message.setMessageId(new MessageId("c1:1:1", Short.MAX_VALUE));
+ assertBeanMarshalls(message);
+ }
+
+ public void testActiveMQMessageMarshalingBiggerMessageId() throws IOException {
+ ActiveMQMessage message = new ActiveMQMessage();
+ message.setCommandId((short)1);
+ message.setOriginalDestination(new ActiveMQQueue("queue"));
+ message.setGroupID("group");
+ message.setGroupSequence(4);
+ message.setCorrelationId("correlation");
+ message.setMessageId(new MessageId("c1:1:1", Integer.MAX_VALUE));
+ assertBeanMarshalls(message);
+ }
+
+ public void testActiveMQMessageMarshalingBiggestMessageId() throws IOException {
+ ActiveMQMessage message = new ActiveMQMessage();
+ message.setCommandId((short)1);
+ message.setOriginalDestination(new ActiveMQQueue("queue"));
+ message.setGroupID("group");
+ message.setGroupSequence(4);
+ message.setCorrelationId("correlation");
+ message.setMessageId(new MessageId("c1:1:1", Long.MAX_VALUE));
+ assertBeanMarshalls(message);
+ }
+
+ public void testMessageIdMarshaling() throws IOException {
+ assertBeanMarshalls(new MessageId("c1:1:1", 1));
+ }
+
+ public void testPropRemove() throws Exception {
+ ActiveMQMessage message = new ActiveMQMessage();
+ message.setStringProperty("RM","RM");
+
+ ActiveMQMessage unMarshalled = (ActiveMQMessage) marshalAndUnmarshall(message, wireFormat);
+
+ unMarshalled.getBooleanProperty("NA");
+ unMarshalled.removeProperty("RM");
+
+ ActiveMQMessage unMarshalledAgain = (ActiveMQMessage) marshalAndUnmarshall(unMarshalled, wireFormat);
+ assertNull("Prop is gone", unMarshalledAgain.getProperty("RM"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/config/BrokerPropertiesTest.java
----------------------------------------------------------------------
diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/config/BrokerPropertiesTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/config/BrokerPropertiesTest.java
new file mode 100644
index 0000000..f8c3ec5
--- /dev/null
+++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/config/BrokerPropertiesTest.java
@@ -0,0 +1,60 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.config;
+
+import javax.jms.Connection;
+import junit.framework.TestCase;
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.broker.BrokerFactory;
+import org.apache.activemq.broker.BrokerRegistry;
+import org.apache.activemq.broker.BrokerService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ */
+public class BrokerPropertiesTest extends TestCase {
+ private static final transient Logger LOG = LoggerFactory.getLogger(BrokerPropertiesTest.class);
+
+ public void testPropertiesFile() throws Exception {
+ BrokerService broker = BrokerFactory.createBroker("properties:org/apache/activemq/config/broker.properties");
+
+ LOG.info("Created broker: " + broker);
+ assertNotNull(broker);
+
+ assertEquals("isUseJmx()", false, broker.isUseJmx());
+ assertEquals("isPersistent()", false, broker.isPersistent());
+ assertEquals("getBrokerName()", "Cheese", broker.getBrokerName());
+ broker.stop();
+ }
+
+
+ public void testVmBrokerPropertiesFile() throws Exception {
+ ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost?brokerConfig=properties:org/apache/activemq/config/broker.properties");
+ Connection connection = factory.createConnection();
+ BrokerService broker = BrokerRegistry.getInstance().lookup("Cheese");
+ LOG.info("Found broker : " + broker);
+ assertNotNull(broker);
+
+ assertEquals("isUseJmx()", false, broker.isUseJmx());
+ assertEquals("isPersistent()", false, broker.isPersistent());
+ assertEquals("getBrokerName()", "Cheese", broker.getBrokerName());
+ connection.close();
+ broker.stop();
+ }
+}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/config/BrokerXmlConfigFromJNDITest.java
----------------------------------------------------------------------
diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/config/BrokerXmlConfigFromJNDITest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/config/BrokerXmlConfigFromJNDITest.java
new file mode 100644
index 0000000..936603c
--- /dev/null
+++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/config/BrokerXmlConfigFromJNDITest.java
@@ -0,0 +1,53 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.config;
+
+import java.io.File;
+import java.util.Hashtable;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.test.JmsTopicSendReceiveWithTwoConnectionsTest;
+
+/**
+ *
+ */
+public class BrokerXmlConfigFromJNDITest extends JmsTopicSendReceiveWithTwoConnectionsTest {
+ @Override
+ protected ActiveMQConnectionFactory createConnectionFactory() throws Exception {
+ assertBaseDirectoryContainsSpaces();
+
+ // we could put these properties into a jndi.properties
+ // on the classpath instead
+ Hashtable<String, String> properties = new Hashtable<String, String>();
+ properties.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
+
+ // configure the embedded broker using an XML config file
+ // which is either a URL or a resource on the classpath
+ File f = new File(System.getProperty("basedir", "."), "/src/test/resources/activemq.xml");
+ properties.put(Context.PROVIDER_URL, "vm://localhost?brokerConfig=xbean:" + f.toURI());
+
+ InitialContext context = new InitialContext(properties);
+ ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) context.lookup("ConnectionFactory");
+
+ // END SNIPPET: example
+ return connectionFactory;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/60979268/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/config/BrokerXmlConfigTest.java
----------------------------------------------------------------------
diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/config/BrokerXmlConfigTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/config/BrokerXmlConfigTest.java
new file mode 100644
index 0000000..c392b12
--- /dev/null
+++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/config/BrokerXmlConfigTest.java
@@ -0,0 +1,48 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.config;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.test.JmsTopicSendReceiveWithTwoConnectionsTest;
+
+/**
+ *
+ */
+public class BrokerXmlConfigTest extends JmsTopicSendReceiveWithTwoConnectionsTest {
+ protected ActiveMQConnectionFactory createConnectionFactory() throws Exception {
+ // START SNIPPET: bean
+
+ // configure the connection factory using
+ // normal Java Bean property methods
+ ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
+
+ // configure the embedded broker using an XML config file
+ // which is either a URL or a resource on the classpath
+
+ // TODO ...
+
+ //connectionFactory.setBrokerXmlConfig("file:src/sample-conf/default.xml");
+
+ // you only need to configure the broker URL if you wish to change the
+ // default connection mechanism, which in this test case we do
+ connectionFactory.setBrokerURL("vm://localhost");
+
+ // END SNIPPET: bean
+ return connectionFactory;
+ }
+
+}