You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2010/01/07 22:14:33 UTC
svn commit: r897016 - in /activemq/activemq-dotnet/Apache.NMS.Stomp/trunk:
./ src/test/csharp/ src/test/csharp/Commands/
Author: tabish
Date: Thu Jan 7 21:14:10 2010
New Revision: 897016
URL: http://svn.apache.org/viewvc?rev=897016&view=rev
Log:
Fix failures in DurableTest and ExclusiveConsumerTest, add tests for the Messages.
Added:
activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/Commands/
activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/Commands/BytesMessageTest.cs (with props)
activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/Commands/CommandTest.cs (with props)
activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/Commands/MessageTest.cs (with props)
activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/Commands/TextMessageTest.cs (with props)
Modified:
activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/DurableTest.cs
activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/ExclusiveConsumerTest.cs
activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/vs2008-stomp-test.csproj
Added: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/Commands/BytesMessageTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/Commands/BytesMessageTest.cs?rev=897016&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/Commands/BytesMessageTest.cs (added)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/Commands/BytesMessageTest.cs Thu Jan 7 21:14:10 2010
@@ -0,0 +1,541 @@
+/*
+ * 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.
+ */
+
+using NUnit.Framework;
+using System;
+using System.Text;
+using Apache.NMS.Stomp.Commands;
+
+namespace Apache.NMS.Stomp.Test.Commands
+{
+ [TestFixture]
+ public class BytesMessageTest
+ {
+ [Test]
+ public void TestCommand()
+ {
+ BytesMessage message = new BytesMessage();
+
+ // Test that a BytesMessage is created in WriteOnly mode.
+ try
+ {
+ byte[] content = message.Content;
+ content.SetValue(0, 0);
+ Assert.Fail("Should have thrown an exception");
+ }
+ catch
+ {
+ }
+
+ Assert.IsTrue( !message.ReadOnlyBody );
+ Assert.IsTrue( !message.ReadOnlyProperties );
+
+ message.Reset();
+
+ Assert.IsNull( message.Content );
+ Assert.IsTrue( message.ReadOnlyBody );
+ }
+
+ [Test]
+ public void TestGetBodyLength()
+ {
+ BytesMessage msg = new BytesMessage();
+ int len = 10;
+
+ for(int i = 0; i < len; i++)
+ {
+ msg.WriteInt64(5L);
+ }
+
+ msg.Reset();
+ Assert.IsTrue(msg.BodyLength == (len * 8));
+ }
+
+ [Test]
+ public void TestReadBoolean()
+ {
+ BytesMessage msg = new BytesMessage();
+ msg.WriteBoolean(true);
+ msg.Reset();
+ Assert.IsTrue(msg.ReadBoolean());
+ }
+
+ [Test]
+ public void TestReadByte()
+ {
+ BytesMessage msg = new BytesMessage();
+ msg.WriteByte( (byte)2 );
+ msg.Reset();
+ Assert.IsTrue( msg.ReadByte() == 2 );
+ }
+
+ [Test]
+ public void TestReadShort() {
+ BytesMessage msg = new BytesMessage();
+ msg.WriteInt16((short) 3000);
+ msg.Reset();
+ Assert.IsTrue(msg.ReadInt16() == 3000);
+ }
+
+ [Test]
+ public void TestReadChar() {
+ BytesMessage msg = new BytesMessage();
+ msg.WriteChar('a');
+ msg.Reset();
+ Assert.IsTrue(msg.ReadChar() == 'a');
+ }
+
+ [Test]
+ public void TestReadInt() {
+ BytesMessage msg = new BytesMessage();
+ msg.WriteInt32(3000);
+ msg.Reset();
+ Assert.IsTrue(msg.ReadInt32() == 3000);
+ }
+
+ [Test]
+ public void TestReadLong() {
+ BytesMessage msg = new BytesMessage();
+ msg.WriteInt64(3000);
+ msg.Reset();
+ Assert.IsTrue(msg.ReadInt64() == 3000);
+ }
+
+ [Test]
+ public void TestReadFloat() {
+ BytesMessage msg = new BytesMessage();
+ msg.WriteSingle(3.3f);
+ msg.Reset();
+ Assert.IsTrue(msg.ReadSingle() == 3.3f);
+ }
+
+ [Test]
+ public void TestReadDouble() {
+ BytesMessage msg = new BytesMessage();
+ msg.WriteDouble(3.3d);
+ msg.Reset();
+ Assert.IsTrue(msg.ReadDouble() == 3.3d);
+ }
+
+ [Test]
+ public void TestReadString() {
+ BytesMessage msg = new BytesMessage();
+ string str = "this is a test";
+ msg.WriteString(str);
+ msg.Reset();
+ Assert.IsTrue(msg.ReadString() == str);
+ }
+
+ [Test]
+ public void TestReadBytesbyteArray()
+ {
+ BytesMessage msg = new BytesMessage();
+ byte[] data = new byte[50];
+ for(int i = 0; i < data.Length; i++)
+ {
+ data[i] = (byte) i;
+ }
+ msg.WriteBytes(data);
+ msg.Reset();
+ byte[] test = new byte[data.Length];
+ msg.ReadBytes(test);
+ for(int i = 0; i < test.Length; i++)
+ {
+ Assert.IsTrue(test[i] == i);
+ }
+ }
+
+ [Test]
+ public void TestWriteObject()
+ {
+ BytesMessage msg = new BytesMessage();
+
+ try
+ {
+ msg.WriteObject("fred");
+ msg.WriteObject((Boolean) true);
+ msg.WriteObject((Char) 'q');
+ msg.WriteObject((Byte) ((byte) 1));
+ msg.WriteObject((Int16) ((short) 3));
+ msg.WriteObject((Int32) 3 );
+ msg.WriteObject((Int64) 300L);
+ msg.WriteObject((Single) 3.3f );
+ msg.WriteObject((Double) 3.3 );
+ msg.WriteObject((Object) new byte[3]);
+ }
+ catch(MessageFormatException)
+ {
+ Assert.Fail("objectified primitives should be allowed");
+ }
+
+ try
+ {
+ msg.WriteObject(new Object());
+ Assert.Fail("only objectified primitives are allowed");
+ }
+ catch(MessageFormatException )
+ {
+ }
+ }
+
+ [Test]
+ public void TestClearBody() {
+ BytesMessage bytesMessage = new BytesMessage();
+ try {
+ bytesMessage.WriteInt32(1);
+ bytesMessage.ClearBody();
+ Assert.IsFalse(bytesMessage.ReadOnlyBody);
+ bytesMessage.WriteInt32(1);
+ bytesMessage.ReadInt32();
+ }
+ catch(MessageNotReadableException)
+ {
+ }
+ catch(MessageNotWriteableException)
+ {
+ Assert.IsTrue(false);
+ }
+ }
+
+ [Test]
+ public void TestReset() {
+
+ BytesMessage message = new BytesMessage();
+
+ try
+ {
+ message.WriteDouble(24.5);
+ message.WriteInt64(311);
+ }
+ catch(MessageNotWriteableException)
+ {
+ Assert.Fail("should be writeable");
+ }
+
+ message.Reset();
+
+ try {
+ Assert.IsTrue(message.ReadOnlyBody);
+ Assert.AreEqual(message.ReadDouble(), 24.5, 0);
+ Assert.AreEqual(message.ReadInt64(), 311);
+ }
+ catch(MessageNotReadableException)
+ {
+ Assert.Fail("should be readable");
+ }
+
+ try
+ {
+ message.WriteInt32(33);
+ Assert.Fail("should throw exception");
+ }
+ catch(MessageNotWriteableException)
+ {
+ }
+ }
+
+ [Test]
+ public void TestReadOnlyBody()
+ {
+ BytesMessage message = new BytesMessage();
+ 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.WriteSingle((float) 1.5);
+ message.WriteInt32(1);
+ message.WriteInt64(1);
+ message.WriteObject("stringobj");
+ message.WriteInt16((short) 1);
+ message.WriteString("utfstring");
+ }
+ catch(MessageNotWriteableException)
+ {
+ Assert.Fail("Should be writeable");
+ }
+
+ message.Reset();
+
+ try
+ {
+ message.ReadBoolean();
+ message.ReadByte();
+ message.ReadBytes(new byte[1]);
+ message.ReadBytes(new byte[2], 2);
+ message.ReadChar();
+ message.ReadDouble();
+ message.ReadSingle();
+ message.ReadInt32();
+ message.ReadInt64();
+ message.ReadString();
+ message.ReadInt16();
+ message.ReadString();
+ }
+ catch(MessageNotReadableException)
+ {
+ Assert.Fail("Should be readable");
+ }
+
+ try
+ {
+ message.WriteBoolean(true);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageNotWriteableException)
+ {
+ }
+
+ try
+ {
+ message.WriteByte((byte) 1);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageNotWriteableException)
+ {
+ }
+
+ try
+ {
+ message.WriteBytes(new byte[1]);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageNotWriteableException)
+ {
+ }
+
+ try
+ {
+ message.WriteBytes(new byte[3], 0, 2);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageNotWriteableException)
+ {
+ }
+
+ try
+ {
+ message.WriteChar('a');
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageNotWriteableException)
+ {
+ }
+
+ try
+ {
+ message.WriteDouble(1.5);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageNotWriteableException)
+ {
+ }
+
+ try
+ {
+ message.WriteSingle((float) 1.5);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageNotWriteableException)
+ {
+ }
+
+ try
+ {
+ message.WriteInt32(1);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageNotWriteableException)
+ {
+ }
+
+ try
+ {
+ message.WriteInt64(1);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageNotWriteableException)
+ {
+ }
+
+ try
+ {
+ message.WriteObject("stringobj");
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageNotWriteableException)
+ {
+ }
+
+ try
+ {
+ message.WriteInt16((short) 1);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageNotWriteableException)
+ {
+ }
+
+ try
+ {
+ message.WriteString("utfstring");
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageNotWriteableException)
+ {
+ }
+ }
+
+ [Test]
+ public void TestWriteOnlyBody()
+ {
+ BytesMessage message = new BytesMessage();
+ 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.WriteSingle((float) 1.5);
+ message.WriteInt32(1);
+ message.WriteInt64(1);
+ message.WriteObject("stringobj");
+ message.WriteInt16((short) 1);
+ message.WriteString("utfstring");
+ }
+ catch(MessageNotWriteableException)
+ {
+ Assert.Fail("Should be writeable");
+ }
+
+ try
+ {
+ message.ReadBoolean();
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageNotReadableException)
+ {
+ }
+
+ try
+ {
+ message.ReadByte();
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageNotReadableException)
+ {
+ }
+
+ try
+ {
+ message.ReadBytes(new byte[1]);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageNotReadableException)
+ {
+ }
+
+ try
+ {
+ message.ReadBytes(new byte[2], 2);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageNotReadableException)
+ {
+ }
+
+ try
+ {
+ message.ReadChar();
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageNotReadableException)
+ {
+ }
+
+ try
+ {
+ message.ReadDouble();
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageNotReadableException)
+ {
+ }
+
+ try
+ {
+ message.ReadSingle();
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageNotReadableException)
+ {
+ }
+
+ try
+ {
+ message.ReadInt32();
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageNotReadableException)
+ {
+ }
+
+ try
+ {
+ message.ReadInt64();
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageNotReadableException)
+ {
+ }
+
+ try
+ {
+ message.ReadString();
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageNotReadableException)
+ {
+ }
+
+ try
+ {
+ message.ReadInt16();
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageNotReadableException)
+ {
+ }
+
+ try
+ {
+ message.ReadString();
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageNotReadableException)
+ {
+ }
+ }
+
+ }
+}
Propchange: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/Commands/BytesMessageTest.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/Commands/BytesMessageTest.cs
------------------------------------------------------------------------------
svn:executable = *
Added: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/Commands/CommandTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/Commands/CommandTest.cs?rev=897016&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/Commands/CommandTest.cs (added)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/Commands/CommandTest.cs Thu Jan 7 21:14:10 2010
@@ -0,0 +1,63 @@
+/*
+ * 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.
+ */
+
+using Apache.NMS.Stomp.Commands;
+using NUnit.Framework;
+using System.Collections;
+
+namespace Apache.NMS.Stomp.Test.Commands
+{
+ [TestFixture]
+ public class CommandTest
+ {
+
+ [Test]
+ public void TestCommand()
+ {
+ ConsumerId value1 = new ConsumerId();
+ value1.ConnectionId = "abc";
+ value1.SessionId = 123;
+ value1.Value = 456;
+
+ ConsumerId value2 = new ConsumerId();
+ value2.ConnectionId = "abc";
+ value2.SessionId = 123;
+ value2.Value = 456;
+
+ ConsumerId value3 = new ConsumerId();
+ value3.ConnectionId = "abc";
+ value3.SessionId = 123;
+ value3.Value = 457;
+
+ Assert.AreEqual(value1, value2, "value1 and value2 should be equal");
+ Assert.AreEqual(value1.GetHashCode(), value2.GetHashCode(), "value1 and value2 hash codes should be equal");
+
+ Assert.IsTrue(!value1.Equals(value3), "value1 and value3 should not be equal");
+ Assert.IsTrue(!value3.Equals(value2), "value3 and value2 should not be equal");
+
+ // now lets test an IDictionary
+ IDictionary dictionary = new Hashtable();
+ dictionary[value1] = value3;
+
+ // now lets lookup with a copy
+ object actual = dictionary[value2];
+
+ Assert.AreEqual(value3, actual, "Should have found item in Map using value2 as a key");
+ }
+ }
+}
+
Propchange: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/Commands/CommandTest.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/Commands/CommandTest.cs
------------------------------------------------------------------------------
svn:executable = *
Added: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/Commands/MessageTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/Commands/MessageTest.cs?rev=897016&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/Commands/MessageTest.cs (added)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/Commands/MessageTest.cs Thu Jan 7 21:14:10 2010
@@ -0,0 +1,1025 @@
+/*
+ * 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.
+ */
+
+using NUnit.Framework;
+using System;
+using System.Text;
+using System.Collections;
+using Apache.NMS.Stomp.Commands;
+using Apache.NMS.Stomp.Protocol;
+using Apache.NMS.Util;
+
+namespace Apache.NMS.Stomp.Test.Commands
+{
+ [TestFixture]
+ public class MessageTest
+ {
+ private string nmsMessageID;
+ private string nmsCorrelationID;
+ private Topic nmsDestination;
+ private TempTopic nmsReplyTo;
+ private MsgDeliveryMode nmsDeliveryMode;
+ private bool nmsRedelivered;
+ private string nmsType;
+ private MsgPriority nmsPriority;
+ private DateTime nmsTimestamp;
+ private long[] consumerIDs;
+
+ [SetUp]
+ public virtual void SetUp()
+ {
+ this.nmsMessageID = "testid";
+ this.nmsCorrelationID = "testcorrelationid";
+ this.nmsDestination = new Topic("test.topic");
+ this.nmsReplyTo = new TempTopic("test.replyto.topic:001");
+ this.nmsDeliveryMode = MsgDeliveryMode.NonPersistent;
+ this.nmsRedelivered = true;
+ this.nmsType = "test type";
+ this.nmsPriority = MsgPriority.High;
+ this.nmsTimestamp = DateTime.Now;
+ this.consumerIDs = new long[3];
+
+ for(int i = 0; i < this.consumerIDs.Length; i++)
+ {
+ this.consumerIDs[i] = i;
+ }
+ }
+
+ [Test]
+ public void TestSetReadOnly()
+ {
+ Message msg = new Message();
+ msg.ReadOnlyProperties = true;
+ bool test = false;
+
+ try
+ {
+ msg.Properties.SetInt("test", 1);
+ }
+ catch(MessageNotWriteableException)
+ {
+ test = true;
+ }
+ catch(NMSException)
+ {
+ test = false;
+ }
+
+ Assert.IsTrue(test);
+ }
+
+ [Test]
+ public void TestSetToForeignNMSID()
+ {
+ Message msg = new Message();
+ msg.NMSMessageId = "ID:EMS-SERVER.8B443C380083:429";
+ }
+
+ [Test]
+ public void TestEqualsObject()
+ {
+ Message msg1 = new Message();
+ Message msg2 = new Message();
+ msg1.NMSMessageId = this.nmsMessageID;
+ Assert.IsTrue(!msg1.Equals(msg2));
+ msg2.NMSMessageId = this.nmsMessageID;
+ Assert.IsTrue(msg1.Equals(msg2));
+ }
+
+ [Test]
+ public void TestShallowCopy()
+ {
+ Message msg1 = new Message();
+ msg1.NMSMessageId = nmsMessageID;
+ Message msg2 = (Message) msg1.Clone();
+ Assert.IsTrue(msg1 != msg2 && msg1.Equals(msg2));
+ }
+
+ [Test]
+ public void TestCopy()
+ {
+ this.nmsMessageID = "ID:1141:45278:429";
+ this.nmsCorrelationID = "testcorrelationid";
+ this.nmsDestination = new Topic("test.topic");
+ this.nmsReplyTo = new TempTopic("test.replyto.topic:001");
+ this.nmsDeliveryMode = MsgDeliveryMode.NonPersistent;
+ this.nmsType = "test type";
+ this.nmsPriority = MsgPriority.High;
+ this.nmsTimestamp = DateTime.Now;
+
+ Message msg1 = new Message();
+ msg1.NMSMessageId = this.nmsMessageID;
+ msg1.NMSCorrelationID = this.nmsCorrelationID;
+ msg1.FromDestination = this.nmsDestination;
+ msg1.NMSReplyTo = this.nmsReplyTo;
+ msg1.NMSDeliveryMode = this.nmsDeliveryMode;
+ msg1.NMSType = this.nmsType;
+ msg1.NMSPriority = this.nmsPriority;
+ msg1.NMSTimestamp = this.nmsTimestamp;
+ msg1.ReadOnlyProperties = true;
+
+ Message msg2 = msg1.Clone() as Message;
+
+ Assert.IsTrue(msg1.NMSMessageId.Equals(msg2.NMSMessageId));
+ Assert.IsTrue(msg1.NMSCorrelationID.Equals(msg2.NMSCorrelationID));
+ Assert.IsTrue(msg1.NMSDestination.Equals(msg2.NMSDestination));
+ Assert.IsTrue(msg1.NMSReplyTo.Equals(msg2.NMSReplyTo));
+ Assert.IsTrue(msg1.NMSDeliveryMode == msg2.NMSDeliveryMode);
+ Assert.IsTrue(msg1.NMSRedelivered == msg2.NMSRedelivered);
+ Assert.IsTrue(msg1.NMSType.Equals(msg2.NMSType));
+ Assert.IsTrue(msg1.NMSPriority == msg2.NMSPriority);
+ Assert.IsTrue(msg1.NMSTimestamp == msg2.NMSTimestamp);
+ }
+
+ [Test]
+ public void TestGetAndSetNMSCorrelationID()
+ {
+ Message msg = new Message();
+ msg.NMSCorrelationID = this.nmsCorrelationID;
+ Assert.IsTrue(msg.NMSCorrelationID.Equals(this.nmsCorrelationID));
+ }
+
+ [Test]
+ public void TestGetAndSetNMSReplyTo()
+ {
+ Message msg = new Message();
+ msg.NMSReplyTo = this.nmsReplyTo;
+ Assert.AreEqual(msg.NMSReplyTo, this.nmsReplyTo);
+ }
+
+ [Test]
+ public void TestGetAndSetNMSDestination()
+ {
+ Message msg = new Message();
+ msg.FromDestination = this.nmsDestination;
+ Assert.AreEqual(msg.NMSDestination, this.nmsDestination);
+ }
+
+ [Test]
+ public void TestGetAndSetNMSDeliveryMode()
+ {
+ Message msg = new Message();
+ msg.NMSDeliveryMode = this.nmsDeliveryMode;
+ Assert.IsTrue(msg.NMSDeliveryMode == this.nmsDeliveryMode);
+ }
+
+ [Test]
+ public void TestGetAndSetMSRedelivered()
+ {
+ Message msg = new Message();
+ msg.RedeliveryCounter = 2;
+ Assert.IsTrue(msg.NMSRedelivered == this.nmsRedelivered);
+ }
+
+ [Test]
+ public void TestGetAndSetNMSType()
+ {
+ Message msg = new Message();
+ msg.NMSType = this.nmsType;
+ Assert.AreEqual(msg.NMSType, this.nmsType);
+ }
+
+ [Test]
+ public void TestGetAndSetNMSPriority()
+ {
+ Message msg = new Message();
+ msg.NMSPriority = this.nmsPriority;
+ Assert.IsTrue(msg.NMSPriority == this.nmsPriority);
+ }
+
+ public void TestClearProperties()
+ {
+ Message msg = new Message();
+ msg.Properties.SetString("test", "test");
+ msg.Content = new byte[1];
+ msg.NMSMessageId = this.nmsMessageID;
+ msg.ClearProperties();
+ Assert.IsNull(msg.Properties.GetString("test"));
+ Assert.IsNotNull(msg.NMSMessageId);
+ Assert.IsNotNull(msg.Content);
+ }
+
+ [Test]
+ public void TestPropertyExists()
+ {
+ Message msg = new Message();
+ msg.Properties.SetString("test", "test");
+ Assert.IsTrue(msg.Properties.Contains("test"));
+ }
+
+ [Test]
+ public void TestGetBooleanProperty()
+ {
+ Message msg = new Message();
+ string name = "booleanProperty";
+ msg.Properties.SetBool(name, true);
+ Assert.IsTrue(msg.Properties.GetBool(name));
+ }
+
+ [Test]
+ public void TestGetByteProperty()
+ {
+ Message msg = new Message();
+ string name = "byteProperty";
+ msg.Properties.SetByte(name, (byte)1);
+ Assert.IsTrue(msg.Properties.GetByte(name) == 1);
+ }
+
+ [Test]
+ public void TestGetShortProperty()
+ {
+ Message msg = new Message();
+ string name = "shortProperty";
+ msg.Properties.SetShort(name, (short)1);
+ Assert.IsTrue(msg.Properties.GetShort(name) == 1);
+ }
+
+ [Test]
+ public void TestGetIntProperty()
+ {
+ Message msg = new Message();
+ string name = "intProperty";
+ msg.Properties.SetInt(name, 1);
+ Assert.IsTrue(msg.Properties.GetInt(name) == 1);
+ }
+
+ [Test]
+ public void TestGetLongProperty()
+ {
+ Message msg = new Message();
+ string name = "longProperty";
+ msg.Properties.SetLong(name, 1);
+ Assert.IsTrue(msg.Properties.GetLong(name) == 1);
+ }
+
+ [Test]
+ public void TestGetFloatProperty()
+ {
+ Message msg = new Message();
+ string name = "floatProperty";
+ msg.Properties.SetFloat(name, 1.3f);
+ Assert.IsTrue(msg.Properties.GetFloat(name) == 1.3f);
+ }
+
+ [Test]
+ public void TestGetDoubleProperty()
+ {
+ Message msg = new Message();
+ string name = "doubleProperty";
+ msg.Properties.SetDouble(name, 1.3d);
+ Assert.IsTrue(msg.Properties.GetDouble(name) == 1.3);
+ }
+
+ [Test]
+ public void TestGetStringProperty()
+ {
+ Message msg = new Message();
+ string name = "stringProperty";
+ msg.Properties.SetString(name, name);
+ Assert.IsTrue(msg.Properties.GetString(name).Equals(name));
+ }
+
+ [Test]
+ public void TestGetObjectProperty()
+ {
+ Message msg = new Message();
+ string name = "floatProperty";
+ msg.Properties.SetFloat(name, 1.3f);
+ Assert.IsTrue(msg.Properties[name] is float);
+ Assert.IsTrue((float)msg.Properties[name] == 1.3f);
+ }
+
+ [Test]
+ public void TestGetPropertyNames()
+ {
+ Message msg = new Message();
+ string name = "floatProperty";
+ msg.Properties.SetFloat(name, 1.3f);
+
+ foreach(string key in msg.Properties.Keys)
+ {
+ Assert.IsTrue(key.Equals(name));
+ }
+ }
+
+ [Test]
+ public void TestSetObjectProperty()
+ {
+ Message msg = new Message();
+ string name = "property";
+
+ try
+ {
+ msg.Properties[name] = "string";
+ msg.Properties[name] = (Byte) 1;
+ msg.Properties[name] = (Int16) 1;
+ msg.Properties[name] = (Int32) 1;
+ msg.Properties[name] = (Int64) 1;
+ msg.Properties[name] = (Single) 1.1f;
+ msg.Properties[name] = (Double) 1.1;
+ msg.Properties[name] = (Boolean) true;
+ msg.Properties[name] = null;
+ }
+ catch(MessageFormatException)
+ {
+ Assert.Fail("should accept object primitives and String");
+ }
+
+ try
+ {
+ msg.Properties[name] = new Object();
+ Assert.Fail("should accept only object primitives and String");
+ }
+ catch(MessageFormatException)
+ {
+ }
+
+ try
+ {
+ msg.Properties[name] = new StringBuilder();
+ Assert.Fail("should accept only object primitives and String");
+ }
+ catch(MessageFormatException)
+ {
+ }
+ }
+
+ [Test]
+ public void TestConvertProperties()
+ {
+ Message msg = new Message();
+
+ msg.Properties["stringProperty"] = "string";
+ msg.Properties["byteProperty"] = (Byte) 1;
+ msg.Properties["shortProperty"] = (Int16) 1;
+ msg.Properties["intProperty"] = (Int32) 1;
+ msg.Properties["longProperty"] = (Int64) 1;
+ msg.Properties["floatProperty"] = (Single) 1.1f;
+ msg.Properties["doubleProperty"] = (Double) 1.1;
+ msg.Properties["booleanProperty"] = (Boolean) true;
+ msg.Properties["nullProperty"] = null;
+
+ msg.BeforeMarshall(new StompWireFormat());
+
+ IPrimitiveMap properties = msg.Properties;
+ Assert.AreEqual(properties["stringProperty"], "string");
+ Assert.AreEqual((byte)properties["byteProperty"], (byte) 1);
+ Assert.AreEqual((short)properties["shortProperty"], (short) 1);
+ Assert.AreEqual((int)properties["intProperty"], (int) 1);
+ Assert.AreEqual((long)properties["longProperty"], (long) 1);
+ Assert.AreEqual((float)properties["floatProperty"], 1.1f, 0);
+ Assert.AreEqual((double)properties["doubleProperty"], 1.1, 0);
+ Assert.AreEqual((bool)properties["booleanProperty"], true);
+ Assert.IsNull(properties["nullProperty"]);
+
+ }
+
+ [Test]
+ public void TestSetNullProperty()
+ {
+ Message msg = new Message();
+ string name = "cheese";
+ msg.Properties.SetString(name, "Cheddar");
+ Assert.AreEqual("Cheddar", msg.Properties.GetString(name));
+
+ msg.Properties.SetString(name, null);
+ Assert.AreEqual(null, msg.Properties.GetString(name));
+ }
+
+ [Test]
+ public void TestSetNullPropertyName()
+ {
+ Message msg = new Message();
+
+ try
+ {
+ msg.Properties.SetString(null, "Cheese");
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(Exception)
+ {
+ }
+ }
+
+ [Test]
+ public void TestSetEmptyPropertyName()
+ {
+ Message msg = new Message();
+
+ try
+ {
+ msg.Properties.SetString("", "Cheese");
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(Exception)
+ {
+ }
+ }
+
+ [Test]
+ public void TestGetAndSetNMSXDeliveryCount()
+ {
+ Message msg = new Message();
+ msg.Properties.SetInt("NMSXDeliveryCount", 1);
+ int count = msg.Properties.GetInt("NMSXDeliveryCount");
+ Assert.IsTrue(count == 1, "expected delivery count = 1 - got: " + count);
+ }
+
+ [Test]
+ public void TestClearBody()
+ {
+ BytesMessage message = new BytesMessage();
+ message.ClearBody();
+ Assert.IsFalse(message.ReadOnlyBody);
+ }
+
+ [Test]
+ public void TestBooleanPropertyConversion()
+ {
+ Message msg = new Message();
+ String propertyName = "property";
+ msg.Properties.SetBool(propertyName, true);
+
+ Assert.AreEqual((bool)msg.Properties[propertyName], true);
+ Assert.IsTrue(msg.Properties.GetBool(propertyName));
+ Assert.AreEqual(msg.Properties.GetString(propertyName), "True");
+ try
+ {
+ msg.Properties.GetByte(propertyName);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageFormatException)
+ {
+ }
+
+ try
+ {
+ msg.Properties.GetShort(propertyName);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageFormatException)
+ {
+ }
+
+ try
+ {
+ msg.Properties.GetInt(propertyName);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageFormatException)
+ {
+ }
+
+ try
+ {
+ msg.Properties.GetLong(propertyName);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageFormatException)
+ {
+ }
+
+ try
+ {
+ msg.Properties.GetFloat(propertyName);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageFormatException)
+ {
+ }
+
+ try
+ {
+ msg.Properties.GetDouble(propertyName);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageFormatException)
+ {
+ }
+ }
+
+ [Test]
+ public void TestBytePropertyConversion()
+ {
+ Message msg = new Message();
+ String propertyName = "property";
+ msg.Properties.SetByte(propertyName, (byte)1);
+
+ Assert.AreEqual((byte)msg.Properties[propertyName], 1);
+ Assert.AreEqual(msg.Properties.GetByte(propertyName), 1);
+ Assert.AreEqual(msg.Properties.GetShort(propertyName), 1);
+ Assert.AreEqual(msg.Properties.GetInt(propertyName), 1);
+ Assert.AreEqual(msg.Properties.GetLong(propertyName), 1);
+ Assert.AreEqual(msg.Properties.GetString(propertyName), "1");
+
+ try
+ {
+ msg.Properties.GetBool(propertyName);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageFormatException)
+ {
+ }
+
+ try
+ {
+ msg.Properties.GetFloat(propertyName);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageFormatException)
+ {
+ }
+
+ try {
+ msg.Properties.GetDouble(propertyName);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageFormatException)
+ {
+ }
+ }
+
+ [Test]
+ public void TestShortPropertyConversion()
+ {
+ Message msg = new Message();
+ String propertyName = "property";
+ msg.Properties.SetShort(propertyName, (short)1);
+
+ Assert.AreEqual((short)msg.Properties[propertyName], 1);
+ Assert.AreEqual(msg.Properties.GetShort(propertyName), 1);
+ Assert.AreEqual(msg.Properties.GetInt(propertyName), 1);
+ Assert.AreEqual(msg.Properties.GetLong(propertyName), 1);
+ Assert.AreEqual(msg.Properties.GetString(propertyName), "1");
+
+ try
+ {
+ msg.Properties.GetBool(propertyName);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageFormatException)
+ {
+ }
+
+ try
+ {
+ msg.Properties.GetByte(propertyName);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageFormatException)
+ {
+ }
+
+ try
+ {
+ msg.Properties.GetFloat(propertyName);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageFormatException)
+ {
+ }
+
+ try
+ {
+ msg.Properties.GetDouble(propertyName);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageFormatException)
+ {
+ }
+ }
+
+ [Test]
+ public void TestIntPropertyConversion()
+ {
+ Message msg = new Message();
+ String propertyName = "property";
+ msg.Properties.SetInt(propertyName, (int)1);
+
+ Assert.AreEqual((int)msg.Properties[propertyName], 1);
+ Assert.AreEqual(msg.Properties.GetInt(propertyName), 1);
+ Assert.AreEqual(msg.Properties.GetLong(propertyName), 1);
+ Assert.AreEqual(msg.Properties.GetString(propertyName), "1");
+
+ try
+ {
+ msg.Properties.GetBool(propertyName);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageFormatException)
+ {
+ }
+
+ try
+ {
+ msg.Properties.GetByte(propertyName);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageFormatException)
+ {
+ }
+
+ try
+ {
+ msg.Properties.GetShort(propertyName);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageFormatException)
+ {
+ }
+
+ try
+ {
+ msg.Properties.GetFloat(propertyName);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageFormatException)
+ {
+ }
+
+ try
+ {
+ msg.Properties.GetDouble(propertyName);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageFormatException)
+ {
+ }
+ }
+
+ [Test]
+ public void TestLongPropertyConversion()
+ {
+ Message msg = new Message();
+ String propertyName = "property";
+ msg.Properties.SetLong(propertyName, 1);
+
+ Assert.AreEqual((long)msg.Properties[propertyName], 1);
+ Assert.AreEqual(msg.Properties.GetLong(propertyName), 1);
+ Assert.AreEqual(msg.Properties.GetString(propertyName), "1");
+
+ try
+ {
+ msg.Properties.GetBool(propertyName);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageFormatException)
+ {
+ }
+
+ try
+ {
+ msg.Properties.GetByte(propertyName);
+ Assert.Fail("Should have thrown exception");
+ } catch(MessageFormatException)
+ {
+ }
+
+ try
+ {
+ msg.Properties.GetShort(propertyName);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageFormatException)
+ {
+ }
+
+ try
+ {
+ msg.Properties.GetInt(propertyName);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageFormatException)
+ {
+ }
+
+ try
+ {
+ msg.Properties.GetFloat(propertyName);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageFormatException)
+ {
+ }
+
+ try
+ {
+ msg.Properties.GetDouble(propertyName);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageFormatException)
+ {
+ }
+ }
+
+ [Test]
+ public void TestFloatPropertyConversion()
+ {
+ Message msg = new Message();
+ String propertyName = "property";
+ float floatValue = (float)1.5;
+ msg.Properties.SetFloat(propertyName, floatValue);
+ Assert.AreEqual((float)msg.Properties[propertyName], floatValue, 0);
+ Assert.AreEqual(msg.Properties.GetFloat(propertyName), floatValue, 0);
+ Assert.AreEqual(msg.Properties.GetDouble(propertyName), floatValue, 0);
+ Assert.AreEqual(msg.Properties.GetString(propertyName), floatValue.ToString());
+
+ try
+ {
+ msg.Properties.GetBool(propertyName);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageFormatException)
+ {
+ }
+
+ try
+ {
+ msg.Properties.GetByte(propertyName);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageFormatException)
+ {
+ }
+
+ try
+ {
+ msg.Properties.GetShort(propertyName);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageFormatException)
+ {
+ }
+
+ try
+ {
+ msg.Properties.GetInt(propertyName);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageFormatException)
+ {
+ }
+
+ try
+ {
+ msg.Properties.GetLong(propertyName);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageFormatException)
+ {
+ }
+ }
+
+ [Test]
+ public void TestDoublePropertyConversion()
+ {
+ Message msg = new Message();
+ String propertyName = "property";
+ Double doubleValue = 1.5;
+ msg.Properties.SetDouble(propertyName, doubleValue);
+ Assert.AreEqual((double)msg.Properties[propertyName], doubleValue, 0);
+ Assert.AreEqual(msg.Properties.GetDouble(propertyName), doubleValue, 0);
+ Assert.AreEqual(msg.Properties.GetString(propertyName), doubleValue.ToString());
+
+ try
+ {
+ msg.Properties.GetBool(propertyName);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageFormatException)
+ {
+ }
+
+ try
+ {
+ msg.Properties.GetByte(propertyName);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageFormatException)
+ {
+ }
+
+ try
+ {
+ msg.Properties.GetShort(propertyName);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageFormatException)
+ {
+ }
+
+ try
+ {
+ msg.Properties.GetInt(propertyName);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageFormatException)
+ {
+ }
+
+ try
+ {
+ msg.Properties.GetLong(propertyName);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageFormatException)
+ {
+ }
+
+ try
+ {
+ msg.Properties.GetFloat(propertyName);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageFormatException)
+ {
+ }
+ }
+
+ [Test]
+ public void TestStringPropertyConversion()
+ {
+ Message msg = new Message();
+ String propertyName = "property";
+ String stringValue = "True";
+ msg.Properties.SetString(propertyName, stringValue);
+ Assert.AreEqual(msg.Properties.GetString(propertyName), stringValue);
+ Assert.AreEqual((string)msg.Properties[propertyName], stringValue);
+ Assert.AreEqual(msg.Properties.GetBool(propertyName), true);
+
+ stringValue = "1";
+ msg.Properties.SetString(propertyName, stringValue);
+ Assert.AreEqual(msg.Properties.GetByte(propertyName), 1);
+ Assert.AreEqual(msg.Properties.GetShort(propertyName), 1);
+ Assert.AreEqual(msg.Properties.GetInt(propertyName), 1);
+ Assert.AreEqual(msg.Properties.GetLong(propertyName), 1);
+
+ Double doubleValue = 1.5;
+ stringValue = doubleValue.ToString();
+ msg.Properties.SetString(propertyName, stringValue);
+ Assert.AreEqual(msg.Properties.GetFloat(propertyName), 1.5, 0);
+ Assert.AreEqual(msg.Properties.GetDouble(propertyName), 1.5, 0);
+
+ stringValue = "bad";
+ msg.Properties.SetString(propertyName, stringValue);
+
+ try
+ {
+ msg.Properties.GetByte(propertyName);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageFormatException)
+ {
+ }
+
+ try
+ {
+ msg.Properties.GetShort(propertyName);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageFormatException)
+ {
+ }
+
+ try
+ {
+ msg.Properties.GetInt(propertyName);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageFormatException)
+ {
+ }
+
+ try
+ {
+ msg.Properties.GetLong(propertyName);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageFormatException)
+ {
+ }
+
+ try
+ {
+ msg.Properties.GetFloat(propertyName);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageFormatException)
+ {
+ }
+
+ try
+ {
+ msg.Properties.GetDouble(propertyName);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageFormatException)
+ {
+ }
+
+ Assert.IsFalse(msg.Properties.GetBool(propertyName));
+ }
+
+ [Test]
+ public void TestReadOnlyProperties()
+ {
+ Message msg = new Message();
+ String propertyName = "property";
+ msg.ReadOnlyProperties = true;
+
+ try
+ {
+ msg.Properties[propertyName] = new Object();
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageNotWriteableException)
+ {
+ }
+
+ try
+ {
+ msg.Properties.SetString(propertyName, "test");
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageNotWriteableException)
+ {
+ }
+
+ try
+ {
+ msg.Properties.SetBool(propertyName, true);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageNotWriteableException)
+ {
+ }
+
+ try
+ {
+ msg.Properties.SetByte(propertyName, (byte)1);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageNotWriteableException) {
+ }
+
+ try
+ {
+ msg.Properties.SetShort(propertyName, (short)1);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageNotWriteableException)
+ {
+ }
+
+ try
+ {
+ msg.Properties.SetInt(propertyName, 1);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageNotWriteableException)
+ {
+ }
+
+ try
+ {
+ msg.Properties.SetLong(propertyName, 1);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageNotWriteableException)
+ {
+ }
+
+ try
+ {
+ msg.Properties.SetFloat(propertyName, (float)1.5);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageNotWriteableException)
+ {
+ }
+
+ try
+ {
+ msg.Properties.SetDouble(propertyName, 1.5);
+ Assert.Fail("Should have thrown exception");
+ }
+ catch(MessageNotWriteableException)
+ {
+ }
+ }
+ }
+}
Propchange: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/Commands/MessageTest.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/Commands/MessageTest.cs
------------------------------------------------------------------------------
svn:executable = *
Added: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/Commands/TextMessageTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/Commands/TextMessageTest.cs?rev=897016&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/Commands/TextMessageTest.cs (added)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/Commands/TextMessageTest.cs Thu Jan 7 21:14:10 2010
@@ -0,0 +1,169 @@
+/*
+ * 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.
+ */
+
+using Apache.NMS.Stomp.Commands;
+using Apache.NMS.Stomp.Protocol;
+using Apache.NMS;
+using Apache.NMS.Util;
+using NUnit.Framework;
+using System;
+using System.Text;
+using System.IO;
+
+namespace Apache.NMS.Stomp.Test.Commands
+{
+ [TestFixture]
+ public class TextMessageTest
+ {
+ [Test]
+ public void TestCommand()
+ {
+ TextMessage message = new TextMessage();
+
+ Assert.IsNull(message.Text);
+
+ // Test with ASCII Data.
+ message.Text = "Hello World";
+ Assert.IsNotNull(message.Text);
+ Assert.AreEqual("Hello World", message.Text);
+
+ String unicodeString =
+ "This unicode string contains two characters " +
+ "with codes outside an 8-bit code range, " +
+ "Pi (\u03a0) and Sigma (\u03a3).";
+
+ message.Text = unicodeString;
+ Assert.IsNotNull(message.Text);
+ Assert.AreEqual(unicodeString, message.Text);
+ }
+
+ [Test]
+ public void TestShallowCopy()
+ {
+ TextMessage msg = new TextMessage();
+ string testString = "str";
+ msg.Text = testString;
+ Message copy = msg.Clone() as Message;
+ Assert.IsTrue(msg.Text == ((TextMessage) copy).Text);
+ }
+
+ [Test]
+ public void TestSetText()
+ {
+ TextMessage msg = new TextMessage();
+ string str = "testText";
+ msg.Text = str;
+ Assert.AreEqual(msg.Text, str);
+ }
+
+ [Test]
+ public void TestClearBody()
+ {
+ TextMessage textMessage = new TextMessage();
+ textMessage.Text = "string";
+ textMessage.ClearBody();
+ Assert.IsFalse(textMessage.ReadOnlyBody);
+ Assert.IsNull(textMessage.Text);
+ try
+ {
+ textMessage.Text = "String";
+ Assert.IsTrue(textMessage.Text.Length > 0);
+ }
+ catch(MessageNotWriteableException)
+ {
+ Assert.Fail("should be writeable");
+ }
+ catch(MessageNotReadableException)
+ {
+ Assert.Fail("should be readable");
+ }
+ }
+
+ [Test]
+ public void TestReadOnlyBody()
+ {
+ TextMessage textMessage = new TextMessage();
+ textMessage.Text = "test";
+ textMessage.ReadOnlyBody = true;
+ try
+ {
+ Assert.IsTrue(textMessage.Text.Length > 0);
+ }
+ catch(MessageNotReadableException)
+ {
+ Assert.Fail("should be readable");
+ }
+ try
+ {
+ textMessage.Text = "test";
+ Assert.Fail("should throw exception");
+ }
+ catch(MessageNotWriteableException)
+ {
+ }
+ }
+
+ [Test]
+ public void TtestWriteOnlyBody()
+ {
+ // should always be readable
+ TextMessage textMessage = new TextMessage();
+ textMessage.ReadOnlyBody = false;
+ try
+ {
+ textMessage.Text = "test";
+ Assert.IsTrue(textMessage.Text.Length > 0);
+ }
+ catch(MessageNotReadableException)
+ {
+ Assert.Fail("should be readable");
+ }
+ textMessage.ReadOnlyBody = true;
+ try
+ {
+ Assert.IsTrue(textMessage.Text.Length > 0);
+ textMessage.Text = "test";
+ Assert.Fail("should throw exception");
+ }
+ catch(MessageNotReadableException)
+ {
+ Assert.Fail("should be readable");
+ }
+ catch(MessageNotWriteableException)
+ {
+ }
+ }
+
+ [Test]
+ public void TestNullText()
+ {
+ TextMessage nullMessage = new TextMessage();
+ SetContent(nullMessage, null);
+ Assert.IsNull(nullMessage.Text);
+ Assert.IsTrue(nullMessage.ToString().Contains("Text = null"));
+ }
+
+ protected void SetContent(Message message, String text)
+ {
+ MemoryStream mstream = new MemoryStream();
+ EndianBinaryWriter dataOut = new EndianBinaryWriter(mstream);
+ dataOut.WriteString32(text);
+ dataOut.Close();
+ message.Content = mstream.ToArray();
+ }
+ }
+}
Propchange: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/Commands/TextMessageTest.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/Commands/TextMessageTest.cs
------------------------------------------------------------------------------
svn:executable = *
Modified: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/DurableTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/DurableTest.cs?rev=897016&r1=897015&r2=897016&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/DurableTest.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/DurableTest.cs Thu Jan 7 21:14:10 2010
@@ -75,6 +75,8 @@
session.Commit();
}
+ Thread.Sleep(1000);
+
consumer = consumeSession.CreateDurableConsumer(topic, CONSUMER_ID, null, false);
ITextMessage msg = consumer.Receive(TimeSpan.FromMilliseconds(1000)) as ITextMessage;
msg.Acknowledge();
@@ -141,6 +143,10 @@
// Change the subscription.
consumer.Dispose();
+
+ // Stomp connection at broker needs some time to cleanup.
+ Thread.Sleep(1000);
+
consumer = session.CreateDurableConsumer(topic, CONSUMER_ID, "color='blue'", false);
sendMessage = session.CreateTextMessage("2nd");
Modified: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/ExclusiveConsumerTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/ExclusiveConsumerTest.cs?rev=897016&r1=897015&r2=897016&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/ExclusiveConsumerTest.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/ExclusiveConsumerTest.cs Thu Jan 7 21:14:10 2010
@@ -33,7 +33,7 @@
private IConnection createConnection(bool start)
{
- IConnection conn = CreateConnection(TEST_CLIENT_ID);
+ IConnection conn = CreateConnection(TEST_CLIENT_ID + ":" + new Random().Next());
if(start)
{
conn.Start();
@@ -305,7 +305,7 @@
ISession exclusiveSession = null;
ISession fallbackSession = null;
ISession senderSession = null;
-
+
try
{
exclusiveSession = conn.CreateSession(AcknowledgementMode.AutoAcknowledge);
Modified: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/vs2008-stomp-test.csproj
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/vs2008-stomp-test.csproj?rev=897016&r1=897015&r2=897016&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/vs2008-stomp-test.csproj (original)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/vs2008-stomp-test.csproj Thu Jan 7 21:14:10 2010
@@ -94,5 +94,9 @@
<Compile Include="src\test\csharp\StompTopicTransactionTest.cs" />
<Compile Include="src\test\csharp\StompTransactionTestSupport.cs" />
<Compile Include="src\test\csharp\StompQueueTransactionTest.cs" />
+ <Compile Include="src\test\csharp\Commands\BytesMessageTest.cs" />
+ <Compile Include="src\test\csharp\Commands\CommandTest.cs" />
+ <Compile Include="src\test\csharp\Commands\MessageTest.cs" />
+ <Compile Include="src\test\csharp\Commands\TextMessageTest.cs" />
</ItemGroup>
</Project>
\ No newline at end of file