You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by jg...@apache.org on 2016/01/06 03:19:57 UTC
svn commit: r1723221 [9/11] - in
/activemq/activemq-dotnet/Apache.NMS.XMS/trunk: ./ keyfile/ src/ src/main/
src/main/csharp/ src/main/csharp/Util/ src/main/ndoc/ src/main/sandcastle/
src/test/ src/test/csharp/ src/test/csharp/Commands/
Added: activemq/activemq-dotnet/Apache.NMS.XMS/trunk/src/test/csharp/EndianBinaryWriterTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.XMS/trunk/src/test/csharp/EndianBinaryWriterTest.cs?rev=1723221&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.XMS/trunk/src/test/csharp/EndianBinaryWriterTest.cs (added)
+++ activemq/activemq-dotnet/Apache.NMS.XMS/trunk/src/test/csharp/EndianBinaryWriterTest.cs Wed Jan 6 02:19:56 2016
@@ -0,0 +1,202 @@
+/*
+ * 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 System;
+using System.IO;
+using Apache.NMS.Util;
+using NUnit.Framework;
+
+namespace Apache.NMS.Test
+{
+ [TestFixture]
+ public class EndianBinaryWriterTest
+ {
+ void writeString16TestHelper(char[] input, byte[] expect)
+ {
+ MemoryStream stream = new MemoryStream();
+ EndianBinaryWriter writer = new EndianBinaryWriter(stream);
+
+ String str = new String(input);
+
+ writer.WriteString16(str);
+
+ byte[] result = stream.GetBuffer();
+
+ Assert.AreEqual(result[0], 0x00);
+ Assert.AreEqual(result[1], expect.Length);
+
+ for(int i = 4; i < expect.Length; ++i)
+ {
+ Assert.AreEqual(result[i], expect[i - 2]);
+ }
+ }
+
+ [Test]
+ public void testWriteString16_1byteUTF8encoding()
+ {
+ // Test data with 1-byte UTF8 encoding.
+ char[] input = { '\u0000', '\u000B', '\u0048', '\u0065', '\u006C', '\u006C', '\u006F', '\u0020', '\u0057', '\u006F', '\u0072', '\u006C', '\u0064' };
+ byte[] expect = { 0xC0, 0x80, 0x0B, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64 };
+
+ writeString16TestHelper(input, expect);
+ }
+
+ [Test]
+ public void testWriteString16_2byteUTF8encoding()
+ {
+ // Test data with 2-byte UT8 encoding.
+ char[] input = { '\u0000', '\u00C2', '\u00A9', '\u00C3', '\u00A6' };
+ byte[] expect = { 0xC0, 0x80, 0xC3, 0x82, 0xC2, 0xA9, 0xC3, 0x83, 0xC2, 0xA6 };
+
+ writeString16TestHelper(input, expect);
+ }
+
+ [Test]
+ public void testWriteString16_1byteAnd2byteEmbeddedNULLs()
+ {
+ // Test data with 1-byte and 2-byte encoding with embedded NULL's.
+ char[] input = { '\u0000', '\u0004', '\u00C2', '\u00A9', '\u00C3', '\u0000', '\u00A6' };
+ byte[] expect = { 0xC0, 0x80, 0x04, 0xC3, 0x82, 0xC2, 0xA9, 0xC3, 0x83, 0xC0, 0x80, 0xC2, 0xA6 };
+
+ writeString16TestHelper(input, expect);
+ }
+
+ [Test]
+ public void testWriteString16_nullstring()
+ {
+ // test that a null string writes no output.
+ MemoryStream stream = new MemoryStream();
+ EndianBinaryWriter writer = new EndianBinaryWriter(stream);
+ writer.WriteString16(null);
+ Assert.AreEqual(0, stream.Length);
+ }
+
+ [Test]
+ public void testWriteString16_emptystring()
+ {
+ // test that a null string writes no output.
+ MemoryStream stream = new MemoryStream();
+ EndianBinaryWriter writer = new EndianBinaryWriter(stream);
+ writer.WriteString16("");
+
+ stream.Seek(0, SeekOrigin.Begin);
+ EndianBinaryReader reader = new EndianBinaryReader(stream);
+ Assert.AreEqual(0, reader.ReadInt16());
+ }
+
+ [Test]
+ [ExpectedException(typeof(IOException))]
+ public void testWriteString16_stringTooLong()
+ {
+ // String of length 65536 of Null Characters.
+ MemoryStream stream = new MemoryStream();
+ EndianBinaryWriter writer = new EndianBinaryWriter(stream);
+ String testStr = new String('a', 65536);
+ writer.Write(testStr);
+ }
+
+ [Test]
+ public void testWriteString16_maxStringLength()
+ {
+ // String of length 65535 of non Null Characters since Null encodes as UTF-8.
+ MemoryStream stream = new MemoryStream();
+ EndianBinaryWriter writer = new EndianBinaryWriter(stream);
+ String testStr = new String('a', 65535);
+ writer.Write(testStr);
+ }
+
+ [Test]
+ [ExpectedException(typeof(IOException))]
+ public void testWriteString16_invalidEncodingHeader()
+ {
+ // Set one of the 65535 bytes to a value that will result in a 2 byte UTF8 encoded sequence.
+ // This will cause the string of length 65535 to have a utf length of 65536.
+ MemoryStream stream = new MemoryStream();
+ EndianBinaryWriter writer = new EndianBinaryWriter(stream);
+ String testStr = new String('a', 65535);
+ char[] array = testStr.ToCharArray();
+ array[0] = '\u0000';
+ testStr = new String(array);
+ writer.Write(testStr);
+ }
+
+ void writeString32TestHelper(char[] input, byte[] expect)
+ {
+ MemoryStream stream = new MemoryStream();
+ EndianBinaryWriter writer = new EndianBinaryWriter(stream);
+
+ String str = new String(input);
+
+ writer.WriteString32(str);
+
+ byte[] result = stream.GetBuffer();
+
+ Assert.AreEqual(result[0], 0x00);
+ Assert.AreEqual(result[1], 0x00);
+ Assert.AreEqual(result[2], 0x00);
+ Assert.AreEqual(result[3], expect.Length);
+
+ for(int i = 4; i < expect.Length; ++i)
+ {
+ Assert.AreEqual(result[i], expect[i - 4]);
+ }
+ }
+
+ [Test]
+ public void testWriteString32_1byteUTF8encoding()
+ {
+ // Test data with 1-byte UTF8 encoding.
+ char[] input = { '\u0000', '\u000B', '\u0048', '\u0065', '\u006C', '\u006C', '\u006F', '\u0020', '\u0057', '\u006F', '\u0072', '\u006C', '\u0064' };
+ byte[] expect = { 0xC0, 0x80, 0x0B, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64 };
+
+ writeString32TestHelper(input, expect);
+ }
+
+ [Test]
+ public void testWriteString32_2byteUTF8encoding()
+ {
+ // Test data with 2-byte UT8 encoding.
+ char[] input = { '\u0000', '\u00C2', '\u00A9', '\u00C3', '\u00A6' };
+ byte[] expect = { 0xC0, 0x80, 0xC3, 0x82, 0xC2, 0xA9, 0xC3, 0x83, 0xC2, 0xA6 };
+
+ writeString32TestHelper(input, expect);
+ }
+
+ [Test]
+ public void testWriteString32_1byteAnd2byteEmbeddedNULLs()
+ {
+ // Test data with 1-byte and 2-byte encoding with embedded NULL's.
+ char[] input = { '\u0000', '\u0004', '\u00C2', '\u00A9', '\u00C3', '\u0000', '\u00A6' };
+ byte[] expect = { 0xC0, 0x80, 0x04, 0xC3, 0x82, 0xC2, 0xA9, 0xC3, 0x83, 0xC0, 0x80, 0xC2, 0xA6 };
+
+ writeString32TestHelper(input, expect);
+ }
+
+ [Test]
+ public void testWriteString32_nullstring()
+ {
+ // test that a null strings writes a -1
+ MemoryStream stream = new MemoryStream();
+ EndianBinaryWriter writer = new EndianBinaryWriter(stream);
+ writer.WriteString32(null);
+
+ stream.Seek(0, SeekOrigin.Begin);
+ EndianBinaryReader reader = new EndianBinaryReader(stream);
+ Assert.AreEqual(-1, reader.ReadInt32());
+ }
+ }
+}
Added: activemq/activemq-dotnet/Apache.NMS.XMS/trunk/src/test/csharp/EndianTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.XMS/trunk/src/test/csharp/EndianTest.cs?rev=1723221&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.XMS/trunk/src/test/csharp/EndianTest.cs (added)
+++ activemq/activemq-dotnet/Apache.NMS.XMS/trunk/src/test/csharp/EndianTest.cs Wed Jan 6 02:19:56 2016
@@ -0,0 +1,131 @@
+/*
+ * 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 System.IO;
+using Apache.NMS.Util;
+using NUnit.Framework;
+
+namespace Apache.NMS.Test
+{
+ [TestFixture]
+ public class EndianTest
+ {
+ [Test]
+ public void TestLongEndian()
+ {
+ long value = 0x0102030405060708L;
+ long newValue = EndianSupport.SwitchEndian(value);
+ Assert.AreEqual(0x0807060504030201L, newValue);
+ long actual = EndianSupport.SwitchEndian(newValue);
+ Assert.AreEqual(value, actual);
+ }
+
+ [Test]
+ public void TestIntEndian()
+ {
+ int value = 0x12345678;
+ int newValue = EndianSupport.SwitchEndian(value);
+ Assert.AreEqual(0x78563412, newValue);
+ int actual = EndianSupport.SwitchEndian(newValue);
+ Assert.AreEqual(value, actual);
+ }
+
+ [Test]
+ public void TestCharEndian()
+ {
+ char value = 'J';
+ char newValue = EndianSupport.SwitchEndian(value);
+ char actual = EndianSupport.SwitchEndian(newValue);
+ Assert.AreEqual(value, actual);
+ }
+
+ [Test]
+ public void TestShortEndian()
+ {
+ short value = 0x1234;
+ short newValue = EndianSupport.SwitchEndian(value);
+ Assert.AreEqual(0x3412, newValue);
+ short actual = EndianSupport.SwitchEndian(newValue);
+ Assert.AreEqual(value, actual);
+ }
+
+ [Test]
+ public void TestNegativeLongEndian()
+ {
+ long value = -0x0102030405060708L;
+ long newValue = EndianSupport.SwitchEndian(value);
+ long actual = EndianSupport.SwitchEndian(newValue);
+ Assert.AreEqual(value, actual);
+ }
+
+ [Test]
+ public void TestNegativeIntEndian()
+ {
+ int value = -0x12345678;
+ int newValue = EndianSupport.SwitchEndian(value);
+ int actual = EndianSupport.SwitchEndian(newValue);
+ Assert.AreEqual(value, actual);
+ }
+
+ [Test]
+ public void TestNegativeShortEndian()
+ {
+ short value = -0x1234;
+ short newValue = EndianSupport.SwitchEndian(value);
+ short actual = EndianSupport.SwitchEndian(newValue);
+ Assert.AreEqual(value, actual);
+ }
+
+ [Test]
+ public void TestFloatDontNeedEndianSwitch()
+ {
+ float value = -1.223F;
+
+ // Convert to int so we can compare to Java version.
+ MemoryStream ms = new MemoryStream(4);
+ BinaryWriter bw = new BinaryWriter(ms);
+ bw.Write(value);
+ bw.Close();
+ ms = new MemoryStream(ms.ToArray());
+ BinaryReader br = new BinaryReader(ms);
+
+ // System.out.println(Integer.toString(Float.floatToIntBits(-1.223F), 16));
+ Assert.AreEqual(-0x406374bc, br.ReadInt32());
+ }
+
+ [Test]
+ public void TestDoublDontNeedEndianSwitch()
+ {
+ double value = -1.223D;
+
+ // Convert to int so we can compare to Java version.
+ MemoryStream ms = new MemoryStream(4);
+ BinaryWriter bw = new BinaryWriter(ms);
+ bw.Write(value);
+ bw.Close();
+ ms = new MemoryStream(ms.ToArray());
+ BinaryReader br = new BinaryReader(ms);
+ long longVersion = br.ReadInt64();
+
+ // System.out.println(Long.toString(Double.doubleToLongBits(-1.223D), 16));
+ Assert.AreEqual(-0x400c6e978d4fdf3b, longVersion);
+ }
+ }
+}
+
+
+
Added: activemq/activemq-dotnet/Apache.NMS.XMS/trunk/src/test/csharp/ForeignMessageTransformationTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.XMS/trunk/src/test/csharp/ForeignMessageTransformationTest.cs?rev=1723221&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.XMS/trunk/src/test/csharp/ForeignMessageTransformationTest.cs (added)
+++ activemq/activemq-dotnet/Apache.NMS.XMS/trunk/src/test/csharp/ForeignMessageTransformationTest.cs Wed Jan 6 02:19:56 2016
@@ -0,0 +1,305 @@
+/*
+ * 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 System;
+using Apache.NMS.Util;
+using Apache.NMS.Commands;
+using NUnit.Framework;
+
+namespace Apache.NMS.Test
+{
+ //[TestFixture]
+ public class ForeignMessageTransformationTest : NMSTest
+ {
+ private string propertyName = "Test-Property";
+ private string propertyValue = "Test-Property-Value";
+ private string mapElementName = "Test-Map-Property";
+ private string mapElementValue = "Test-Map-Property-Value";
+ private string textBody = "This is a TextMessage from a Foreign Provider";
+ private byte[] bytesContent = {1, 2, 3, 4, 5, 6, 7, 8};
+
+ private bool a = true;
+ private byte b = 123;
+ private char c = 'c';
+ private short d = 0x1234;
+ private int e = 0x12345678;
+ private long f = 0x1234567812345678;
+ private string g = "Hello World!";
+ private bool h = false;
+ private byte i = 0xFF;
+ private short j = -0x1234;
+ private int k = -0x12345678;
+ private long l = -0x1234567812345678;
+ private float m = 2.1F;
+ private double n = 2.3;
+
+ protected ForeignMessageTransformationTest(NMSTestSupport testSupport)
+ : base(testSupport)
+ {
+ }
+
+ //[Test]
+ public virtual void TestSendReceiveForeignMessage(
+ //[Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
+ MsgDeliveryMode deliveryMode, string testTopicRef)
+ {
+ using(IConnection connection = CreateConnection())
+ {
+ connection.Start();
+ using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
+ {
+ IDestination destination = GetClearDestination(session, DestinationType.Topic, testTopicRef);
+ using(IMessageConsumer consumer = session.CreateConsumer(destination))
+ using(IMessageProducer producer = session.CreateProducer(destination))
+ {
+ try
+ {
+ producer.DeliveryMode = deliveryMode;
+ Message request = new Message();
+ request.Properties[propertyName] = propertyValue;
+
+ producer.Send(request);
+
+ IMessage message = consumer.Receive(receiveTimeout);
+ Assert.IsNotNull(message, "No message returned!");
+ Assert.AreEqual(request.Properties.Count, message.Properties.Count, "Invalid number of properties.");
+ Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");
+
+ // use generic API to access entries
+ Assert.AreEqual(propertyValue, message.Properties[propertyName], "generic map entry: " + propertyName);
+
+ // use type safe APIs
+ Assert.AreEqual(propertyValue, message.Properties.GetString(propertyName), "map entry: " + propertyName);
+ }
+ catch(NotSupportedException)
+ {
+ }
+ }
+ }
+ }
+ }
+
+ //[Test]
+ public virtual void TestSendReceiveForeignTextMessage(
+ //[Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
+ MsgDeliveryMode deliveryMode, string testTopicRef)
+ {
+ using(IConnection connection = CreateConnection())
+ {
+ connection.Start();
+ using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
+ {
+ IDestination destination = GetClearDestination(session, DestinationType.Topic, testTopicRef);
+ using(IMessageConsumer consumer = session.CreateConsumer(destination))
+ using(IMessageProducer producer = session.CreateProducer(destination))
+ {
+ try
+ {
+ producer.DeliveryMode = deliveryMode;
+ TextMessage request = new TextMessage();
+ request.Properties[propertyName] = propertyValue;
+ request.Text = textBody;
+
+ producer.Send(request);
+
+ ITextMessage message = consumer.Receive(receiveTimeout) as ITextMessage;
+ Assert.IsNotNull(message, "No message returned!");
+ Assert.AreEqual(request.Properties.Count, message.Properties.Count, "Invalid number of properties.");
+ Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");
+
+ // Check the body
+ Assert.AreEqual(textBody, message.Text, "TextMessage body was wrong.");
+
+ // use generic API to access entries
+ Assert.AreEqual(propertyValue, message.Properties[propertyName], "generic map entry: " + propertyName);
+
+ // use type safe APIs
+ Assert.AreEqual(propertyValue, message.Properties.GetString(propertyName), "map entry: " + propertyName);
+ }
+ catch(NotSupportedException)
+ {
+ }
+ }
+ }
+ }
+ }
+
+ //[Test]
+ public virtual void TestSendReceiveForeignBytesMessage(
+ //[Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
+ MsgDeliveryMode deliveryMode, string testTopicRef)
+ {
+ using(IConnection connection = CreateConnection())
+ {
+ connection.Start();
+ using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
+ {
+ IDestination destination = GetClearDestination(session, DestinationType.Topic, testTopicRef);
+ using(IMessageConsumer consumer = session.CreateConsumer(destination))
+ using(IMessageProducer producer = session.CreateProducer(destination))
+ {
+ try
+ {
+ producer.DeliveryMode = deliveryMode;
+ BytesMessage request = new BytesMessage();
+ request.Properties[propertyName] = propertyValue;
+ request.WriteBytes(bytesContent);
+
+ producer.Send(request);
+
+ IBytesMessage message = consumer.Receive(receiveTimeout) as IBytesMessage;
+ Assert.IsNotNull(message, "No message returned!");
+ Assert.AreEqual(request.Properties.Count, message.Properties.Count, "Invalid number of properties.");
+ Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");
+
+ // Check the body
+ byte[] content = new byte[bytesContent.Length];
+ Assert.AreEqual(bytesContent.Length, message.ReadBytes(content));
+ Assert.AreEqual(bytesContent, content, "BytesMessage body was wrong.");
+
+ // use generic API to access entries
+ Assert.AreEqual(propertyValue, message.Properties[propertyName], "generic map entry: " + propertyName);
+
+ // use type safe APIs
+ Assert.AreEqual(propertyValue, message.Properties.GetString(propertyName), "map entry: " + propertyName);
+ }
+ catch(NotSupportedException)
+ {
+ }
+ }
+ }
+ }
+ }
+
+ //[Test]
+ public virtual void TestSendReceiveForeignMapMessage(
+ //[Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
+ MsgDeliveryMode deliveryMode, string testTopicRef)
+ {
+ using(IConnection connection = CreateConnection())
+ {
+ connection.Start();
+ using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
+ {
+ IDestination destination = GetClearDestination(session, DestinationType.Topic, testTopicRef);
+ using(IMessageConsumer consumer = session.CreateConsumer(destination))
+ using(IMessageProducer producer = session.CreateProducer(destination))
+ {
+ try
+ {
+ producer.DeliveryMode = deliveryMode;
+ MapMessage request = new MapMessage();
+ request.Properties[propertyName] = propertyValue;
+ request.Body[mapElementName] = mapElementValue;
+
+ producer.Send(request);
+
+ IMapMessage message = consumer.Receive(receiveTimeout) as IMapMessage;
+ Assert.IsNotNull(message, "No message returned!");
+ Assert.AreEqual(request.Properties.Count, message.Properties.Count, "Invalid number of properties.");
+ Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");
+
+ // Check the body
+ Assert.AreEqual(request.Body.Count, message.Body.Count);
+ Assert.AreEqual(mapElementValue, message.Body[mapElementName], "MapMessage body was wrong.");
+
+ // use generic API to access entries
+ Assert.AreEqual(propertyValue, message.Properties[propertyName], "generic map entry: " + propertyName);
+
+ // use type safe APIs
+ Assert.AreEqual(propertyValue, message.Properties.GetString(propertyName), "map entry: " + propertyName);
+ }
+ catch(NotSupportedException)
+ {
+ }
+ }
+ }
+ }
+ }
+
+ //[Test]
+ public virtual void TestSendReceiveForeignStreamMessage(
+ //[Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
+ MsgDeliveryMode deliveryMode, string testTopicRef)
+ {
+ using(IConnection connection = CreateConnection())
+ {
+ connection.Start();
+ using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
+ {
+ IDestination destination = GetClearDestination(session, DestinationType.Topic, testTopicRef);
+ using(IMessageConsumer consumer = session.CreateConsumer(destination))
+ using(IMessageProducer producer = session.CreateProducer(destination))
+ {
+ try
+ {
+ producer.DeliveryMode = deliveryMode;
+ StreamMessage request = new StreamMessage();
+ request.Properties[propertyName] = propertyValue;
+
+ request.WriteBoolean(a);
+ request.WriteByte(b);
+ request.WriteChar(c);
+ request.WriteInt16(d);
+ request.WriteInt32(e);
+ request.WriteInt64(f);
+ request.WriteString(g);
+ request.WriteBoolean(h);
+ request.WriteByte(i);
+ request.WriteInt16(j);
+ request.WriteInt32(k);
+ request.WriteInt64(l);
+ request.WriteSingle(m);
+ request.WriteDouble(n);
+
+ producer.Send(request);
+
+ IStreamMessage message = consumer.Receive(receiveTimeout) as IStreamMessage;
+ Assert.IsNotNull(message, "No message returned!");
+ Assert.AreEqual(request.Properties.Count, message.Properties.Count, "Invalid number of properties.");
+ Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");
+
+ // Check the body
+ Assert.AreEqual(a, message.ReadBoolean(), "Stream Boolean Value: a");
+ Assert.AreEqual(b, message.ReadByte(), "Stream Byte Value: b");
+ Assert.AreEqual(c, message.ReadChar(), "Stream Char Value: c");
+ Assert.AreEqual(d, message.ReadInt16(), "Stream Int16 Value: d");
+ Assert.AreEqual(e, message.ReadInt32(), "Stream Int32 Value: e");
+ Assert.AreEqual(f, message.ReadInt64(), "Stream Int64 Value: f");
+ Assert.AreEqual(g, message.ReadString(), "Stream String Value: g");
+ Assert.AreEqual(h, message.ReadBoolean(), "Stream Boolean Value: h");
+ Assert.AreEqual(i, message.ReadByte(), "Stream Byte Value: i");
+ Assert.AreEqual(j, message.ReadInt16(), "Stream Int16 Value: j");
+ Assert.AreEqual(k, message.ReadInt32(), "Stream Int32 Value: k");
+ Assert.AreEqual(l, message.ReadInt64(), "Stream Int64 Value: l");
+ Assert.AreEqual(m, message.ReadSingle(), "Stream Single Value: m");
+ Assert.AreEqual(n, message.ReadDouble(), "Stream Double Value: n");
+
+ // use generic API to access entries
+ Assert.AreEqual(propertyValue, message.Properties[propertyName], "generic map entry: " + propertyName);
+
+ // use type safe APIs
+ Assert.AreEqual(propertyValue, message.Properties.GetString(propertyName), "map entry: " + propertyName);
+ }
+ catch(NotSupportedException)
+ {
+ }
+ }
+ }
+ }
+ }
+ }
+}
Added: activemq/activemq-dotnet/Apache.NMS.XMS/trunk/src/test/csharp/MapMessageTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.XMS/trunk/src/test/csharp/MapMessageTest.cs?rev=1723221&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.XMS/trunk/src/test/csharp/MapMessageTest.cs (added)
+++ activemq/activemq-dotnet/Apache.NMS.XMS/trunk/src/test/csharp/MapMessageTest.cs Wed Jan 6 02:19:56 2016
@@ -0,0 +1,208 @@
+/*
+ * 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 System;
+using System.Collections;
+using Apache.NMS.Util;
+using NUnit.Framework;
+
+namespace Apache.NMS.Test
+{
+ //[TestFixture]
+ public class MapMessageTest : NMSTest
+ {
+ protected bool a = true;
+ protected byte b = 123;
+ protected char c = 'c';
+ protected short d = 0x1234;
+ protected int e = 0x12345678;
+ protected long f = 0x1234567812345678;
+ protected string g = "Hello World!";
+ protected bool h = false;
+ protected byte i = 0xFF;
+ protected short j = -0x1234;
+ protected int k = -0x12345678;
+ protected long l = -0x1234567812345678;
+ protected float m = 2.1F;
+ protected double n = 2.3;
+ protected byte[] o = {1, 2, 3, 4, 5};
+
+ protected MapMessageTest(NMSTestSupport testSupport)
+ : base(testSupport)
+ {
+ }
+
+ //[Test]
+ public virtual void TestSendReceiveMapMessage(
+ //[Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
+ MsgDeliveryMode deliveryMode, string testQueueRef)
+ {
+ using(IConnection connection = CreateConnection(GetTestClientId()))
+ {
+ connection.Start();
+ using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
+ {
+ IDestination destination = GetClearDestination(session, DestinationType.Queue, testQueueRef);
+ using(IMessageConsumer consumer = session.CreateConsumer(destination))
+ using(IMessageProducer producer = session.CreateProducer(destination))
+ {
+ producer.DeliveryMode = deliveryMode;
+ IMapMessage request = session.CreateMapMessage();
+ request.Body["a"] = a;
+ request.Body["b"] = b;
+ request.Body["c"] = c;
+ request.Body["d"] = d;
+ request.Body["e"] = e;
+ request.Body["f"] = f;
+ request.Body["g"] = g;
+ request.Body["h"] = h;
+ request.Body["i"] = i;
+ request.Body["j"] = j;
+ request.Body["k"] = k;
+ request.Body["l"] = l;
+ request.Body["m"] = m;
+ request.Body["n"] = n;
+ request.Body["o"] = o;
+ producer.Send(request);
+
+ IMapMessage message = consumer.Receive(receiveTimeout) as IMapMessage;
+ Assert.IsNotNull(message, "No message returned!");
+ Assert.AreEqual(request.Body.Count, message.Body.Count, "Invalid number of message maps.");
+ Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");
+ Assert.AreEqual(ToHex(f), ToHex(message.Body.GetLong("f")), "map entry: f as hex");
+
+ // use generic API to access entries
+ Assert.AreEqual(a, message.Body["a"], "generic map entry: a");
+ Assert.AreEqual(b, message.Body["b"], "generic map entry: b");
+ Assert.AreEqual(c, message.Body["c"], "generic map entry: c");
+ Assert.AreEqual(d, message.Body["d"], "generic map entry: d");
+ Assert.AreEqual(e, message.Body["e"], "generic map entry: e");
+ Assert.AreEqual(f, message.Body["f"], "generic map entry: f");
+ Assert.AreEqual(g, message.Body["g"], "generic map entry: g");
+ Assert.AreEqual(h, message.Body["h"], "generic map entry: h");
+ Assert.AreEqual(i, message.Body["i"], "generic map entry: i");
+ Assert.AreEqual(j, message.Body["j"], "generic map entry: j");
+ Assert.AreEqual(k, message.Body["k"], "generic map entry: k");
+ Assert.AreEqual(l, message.Body["l"], "generic map entry: l");
+ Assert.AreEqual(m, message.Body["m"], "generic map entry: m");
+ Assert.AreEqual(n, message.Body["n"], "generic map entry: n");
+ Assert.AreEqual(o, message.Body["o"], "generic map entry: o");
+
+ // use type safe APIs
+ Assert.AreEqual(a, message.Body.GetBool("a"), "map entry: a");
+ Assert.AreEqual(b, message.Body.GetByte("b"), "map entry: b");
+ Assert.AreEqual(c, message.Body.GetChar("c"), "map entry: c");
+ Assert.AreEqual(d, message.Body.GetShort("d"), "map entry: d");
+ Assert.AreEqual(e, message.Body.GetInt("e"), "map entry: e");
+ Assert.AreEqual(f, message.Body.GetLong("f"), "map entry: f");
+ Assert.AreEqual(g, message.Body.GetString("g"), "map entry: g");
+ Assert.AreEqual(h, message.Body.GetBool("h"), "map entry: h");
+ Assert.AreEqual(i, message.Body.GetByte("i"), "map entry: i");
+ Assert.AreEqual(j, message.Body.GetShort("j"), "map entry: j");
+ Assert.AreEqual(k, message.Body.GetInt("k"), "map entry: k");
+ Assert.AreEqual(l, message.Body.GetLong("l"), "map entry: l");
+ Assert.AreEqual(m, message.Body.GetFloat("m"), "map entry: m");
+ Assert.AreEqual(n, message.Body.GetDouble("n"), "map entry: n");
+ Assert.AreEqual(o, message.Body.GetBytes("o"), "map entry: o");
+ }
+ }
+ }
+ }
+
+ //[Test]
+ public virtual void TestSendReceiveNestedMapMessage(
+ //[Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
+ MsgDeliveryMode deliveryMode, string testQueueRef)
+ {
+ using(IConnection connection = CreateConnection(GetTestClientId()))
+ {
+ connection.Start();
+ using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
+ {
+ IDestination destination = GetClearDestination(session, DestinationType.Queue, testQueueRef);
+ using(IMessageConsumer consumer = session.CreateConsumer(destination))
+ using(IMessageProducer producer = session.CreateProducer(destination))
+ {
+ try
+ {
+ producer.DeliveryMode = deliveryMode;
+ IMapMessage request = session.CreateMapMessage();
+ const string textFieldValue = "Nested Map Messages Rule!";
+
+ request.Body.SetString("textField", textFieldValue);
+
+ IDictionary grandChildMap = new Hashtable();
+ grandChildMap["x"] = "abc";
+ grandChildMap["y"] = new ArrayList(new object[] { "a", "b", "c" });
+
+ IDictionary nestedMap = new Hashtable();
+ nestedMap["a"] = "foo";
+ nestedMap["b"] = (int) 23;
+ nestedMap["c"] = (long) 45;
+ nestedMap["d"] = grandChildMap;
+
+ request.Body.SetDictionary("mapField", nestedMap);
+ request.Body.SetList("listField", new ArrayList(new Object[] { "a", "b", "c" }));
+
+ producer.Send(request);
+
+ IMapMessage message = consumer.Receive(receiveTimeout) as IMapMessage;
+ Assert.IsNotNull(message, "No message returned!");
+ Assert.AreEqual(request.Body.Count, message.Body.Count, "Invalid number of message maps.");
+ Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");
+
+ string textFieldResponse = message.Body.GetString("textField");
+ Assert.AreEqual(textFieldValue, textFieldResponse, "textField does not match.");
+
+ IDictionary nestedMapResponse = message.Body.GetDictionary("mapField");
+ Assert.IsNotNull(nestedMapResponse, "Nested map not returned.");
+ Assert.AreEqual(nestedMap.Count, nestedMapResponse.Count, "nestedMap: Wrong number of elements");
+ Assert.AreEqual("foo", nestedMapResponse["a"], "nestedMap: a");
+ Assert.AreEqual(23, nestedMapResponse["b"], "nestedMap: b");
+ Assert.AreEqual(45, nestedMapResponse["c"], "nestedMap: c");
+
+ IDictionary grandChildMapResponse = nestedMapResponse["d"] as IDictionary;
+ Assert.IsNotNull(grandChildMapResponse, "Grand child map not returned.");
+ Assert.AreEqual(grandChildMap.Count, grandChildMapResponse.Count, "grandChildMap: Wrong number of elements");
+ Assert.AreEqual(grandChildMapResponse["x"], "abc", "grandChildMap: x");
+
+ IList grandChildList = grandChildMapResponse["y"] as IList;
+ Assert.IsNotNull(grandChildList, "Grand child list not returned.");
+ Assert.AreEqual(3, grandChildList.Count, "grandChildList: Wrong number of list elements.");
+ Assert.AreEqual("a", grandChildList[0], "grandChildList: a");
+ Assert.AreEqual("b", grandChildList[1], "grandChildList: b");
+ Assert.AreEqual("c", grandChildList[2], "grandChildList: c");
+
+ IList listFieldResponse = message.Body.GetList("listField");
+ Assert.IsNotNull(listFieldResponse, "Nested list not returned.");
+ Assert.AreEqual(3, listFieldResponse.Count, "listFieldResponse: Wrong number of list elements.");
+ Assert.AreEqual("a", listFieldResponse[0], "listFieldResponse: a");
+ Assert.AreEqual("b", listFieldResponse[1], "listFieldResponse: b");
+ Assert.AreEqual("c", listFieldResponse[2], "listFieldResponse: c");
+ }
+ catch(NotSupportedException)
+ {
+ }
+ catch(NMSException e)
+ {
+ Assert.IsTrue(e.InnerException.GetType() == typeof(NotSupportedException));
+ }
+ }
+ }
+ }
+ }
+ }
+}
Added: activemq/activemq-dotnet/Apache.NMS.XMS/trunk/src/test/csharp/MessageSelectorTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.XMS/trunk/src/test/csharp/MessageSelectorTest.cs?rev=1723221&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.XMS/trunk/src/test/csharp/MessageSelectorTest.cs (added)
+++ activemq/activemq-dotnet/Apache.NMS.XMS/trunk/src/test/csharp/MessageSelectorTest.cs Wed Jan 6 02:19:56 2016
@@ -0,0 +1,184 @@
+/*
+ * 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 System;
+using System.Threading;
+using Apache.NMS.Util;
+using NUnit.Framework;
+
+namespace Apache.NMS.Test
+{
+ //[TestFixture]
+ //[Category("LongRunning")]
+ public class MessageSelectorTest : NMSTest
+ {
+ private int receivedNonIgnoredMsgCount = 0;
+ private int receivedIgnoredMsgCount = 0;
+ private bool simulateSlowConsumer = false;
+
+ protected MessageSelectorTest(NMSTestSupport testSupport)
+ : base(testSupport)
+ {
+ }
+
+ //[Test]
+ public virtual void TestFilterIgnoredMessages(
+ //[Values(SELECTOR_TEST_QUEUE_URI, SELECTOR_TEST_TOPIC_URI)]
+ string testDestinationURI)
+ {
+ simulateSlowConsumer = false;
+ RunFilterIgnoredMessagesTest(testDestinationURI);
+ }
+
+ /// <summary>
+ /// A slow consumer will trigger the producer flow control on the broker when the destination is
+ /// a queue. It will also trigger the consumer flow control by slowing down the feed to all of the
+ /// consumers on the queue to only send messages as fast as the slowest consumer can run.
+ /// When sending to a topic, the producer will not be slowed down, and consumers will be allowed
+ /// to run as fast as they can go.
+ /// Since this test can take a long time to run, it is marked as explicit.
+ /// </summary>
+ /// <param name="testDestinationURI"></param>
+ //[Test]
+ public virtual void TestFilterIgnoredMessagesSlowConsumer(
+ //[Values(SELECTOR_TEST_QUEUE_URI, SELECTOR_TEST_TOPIC_URI)]
+ string testDestinationURI)
+ {
+ simulateSlowConsumer = true;
+ RunFilterIgnoredMessagesTest(testDestinationURI);
+ }
+
+ public void RunFilterIgnoredMessagesTest(string testDestinationURI)
+ {
+ TimeSpan ttl = TimeSpan.FromMinutes(30);
+ const int MaxNumRequests = 100000;
+
+ using(IConnection connection1 = CreateConnection(GetTestClientId()))
+ using(IConnection connection2 = CreateConnection(GetTestClientId()))
+ using(IConnection connection3 = CreateConnection(GetTestClientId()))
+ {
+ connection1.Start();
+ connection2.Start();
+ connection3.Start();
+ using(ISession session1 = connection1.CreateSession(AcknowledgementMode.AutoAcknowledge))
+ using(ISession session2 = connection2.CreateSession(AcknowledgementMode.AutoAcknowledge))
+ using(ISession session3 = connection3.CreateSession(AcknowledgementMode.AutoAcknowledge))
+ {
+ IDestination destination1 = GetClearDestination(session1, testDestinationURI);
+ IDestination destination2 = GetClearDestination(session2, testDestinationURI);
+ IDestination destination3 = GetClearDestination(session3, testDestinationURI);
+
+ using(IMessageProducer producer = session1.CreateProducer(destination1))
+ using(IMessageConsumer consumer1 = session2.CreateConsumer(destination2, "JMSType NOT LIKE '%IGNORE'"))
+ {
+ int numNonIgnoredMsgsSent = 0;
+ int numIgnoredMsgsSent = 0;
+
+ producer.DeliveryMode = MsgDeliveryMode.NonPersistent;
+
+ receivedNonIgnoredMsgCount = 0;
+ receivedIgnoredMsgCount = 0;
+ consumer1.Listener += new MessageListener(OnNonIgnoredMessage);
+ IMessageConsumer consumer2 = null;
+
+ for(int index = 1; index <= MaxNumRequests; index++)
+ {
+ IMessage request = session1.CreateTextMessage(String.Format("Hello World! [{0} of {1}]", index, MaxNumRequests));
+
+ request.NMSTimeToLive = ttl;
+ if(0 == (index % 2))
+ {
+ request.NMSType = "ACTIVE";
+ numNonIgnoredMsgsSent++;
+ }
+ else
+ {
+ request.NMSType = "ACTIVE.IGNORE";
+ numIgnoredMsgsSent++;
+ }
+
+ producer.Send(request);
+
+ if(2000 == index)
+ {
+ // Start the second consumer
+ if(destination3.IsTopic)
+ {
+ // Reset the ignored message sent count, since all previous messages
+ // will not have been consumed on a topic.
+ numIgnoredMsgsSent = 0;
+ }
+
+ consumer2 = session3.CreateConsumer(destination3, "JMSType LIKE '%IGNORE'");
+ consumer2.Listener += new MessageListener(OnIgnoredMessage);
+ }
+ }
+
+ // Create a waiting loop that will coordinate the end of the test. It checks
+ // to see that all intended messages were received. It will continue to wait as
+ // long as new messages are being received. If it stops receiving messages before
+ // it receives everything it expects, it will eventually timeout and the test will fail.
+ int waitCount = 0;
+ int lastReceivedINongnoredMsgCount = receivedNonIgnoredMsgCount;
+ int lastReceivedIgnoredMsgCount = receivedIgnoredMsgCount;
+
+ while(receivedNonIgnoredMsgCount < numNonIgnoredMsgsSent
+ || receivedIgnoredMsgCount < numIgnoredMsgsSent)
+ {
+ if(lastReceivedINongnoredMsgCount != receivedNonIgnoredMsgCount
+ || lastReceivedIgnoredMsgCount != receivedIgnoredMsgCount)
+ {
+ // Reset the wait count.
+ waitCount = 0;
+ }
+ else
+ {
+ waitCount++;
+ }
+
+ lastReceivedINongnoredMsgCount = receivedNonIgnoredMsgCount;
+ lastReceivedIgnoredMsgCount = receivedIgnoredMsgCount;
+
+ Assert.IsTrue(waitCount <= 30, String.Format("Timeout waiting for all messages to be delivered. Only {0} of {1} non-ignored messages delivered. Only {2} of {3} ignored messages delivered.",
+ receivedNonIgnoredMsgCount, numNonIgnoredMsgsSent, receivedIgnoredMsgCount, numIgnoredMsgsSent));
+ Thread.Sleep(1000);
+ }
+
+ consumer2.Dispose();
+ }
+ }
+ }
+ }
+
+ protected void OnNonIgnoredMessage(IMessage message)
+ {
+ receivedNonIgnoredMsgCount++;
+ Assert.AreEqual(message.NMSType, "ACTIVE");
+ }
+
+ protected void OnIgnoredMessage(IMessage message)
+ {
+ receivedIgnoredMsgCount++;
+ Assert.AreEqual(message.NMSType, "ACTIVE.IGNORE");
+ if(simulateSlowConsumer)
+ {
+ // Simulate a slow consumer It doesn't have to be too slow in a high speed environment
+ // in order to trigger producer flow control.
+ Thread.Sleep(10);
+ }
+ }
+ }
+}
Added: activemq/activemq-dotnet/Apache.NMS.XMS/trunk/src/test/csharp/MessageTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.XMS/trunk/src/test/csharp/MessageTest.cs?rev=1723221&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.XMS/trunk/src/test/csharp/MessageTest.cs (added)
+++ activemq/activemq-dotnet/Apache.NMS.XMS/trunk/src/test/csharp/MessageTest.cs Wed Jan 6 02:19:56 2016
@@ -0,0 +1,147 @@
+/*
+ * 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 System;
+using Apache.NMS.Util;
+using NUnit.Framework;
+
+namespace Apache.NMS.Test
+{
+ //[TestFixture]
+ public class MessageTest : NMSTest
+ {
+ protected bool a = true;
+ protected byte b = 123;
+ protected char c = 'c';
+ protected short d = 0x1234;
+ protected int e = 0x12345678;
+ protected long f = 0x1234567812345678;
+ protected string g = "Hello World!";
+ protected bool h = false;
+ protected byte i = 0xFF;
+ protected short j = -0x1234;
+ protected int k = -0x12345678;
+ protected long l = -0x1234567812345678;
+ protected float m = 2.1F;
+ protected double n = 2.3;
+ protected byte[] o = {1, 2, 3, 4, 5};
+
+ protected MessageTest(NMSTestSupport testSupport)
+ : base(testSupport)
+ {
+ }
+
+ //[Test]
+ public virtual void TestSendReceiveMessageProperties(
+ //[Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
+ MsgDeliveryMode deliveryMode, string testQueueRef)
+ {
+ using(IConnection connection = CreateConnection(GetTestClientId()))
+ {
+ connection.Start();
+ using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
+ {
+ IDestination destination = GetClearDestination(session, DestinationType.Queue, testQueueRef);
+ using(IMessageConsumer consumer = session.CreateConsumer(destination))
+ using(IMessageProducer producer = session.CreateProducer(destination))
+ {
+ producer.DeliveryMode = deliveryMode;
+ IMessage request = session.CreateMessage();
+ request.Properties["a"] = a;
+ request.Properties["b"] = b;
+ request.Properties["c"] = c;
+ request.Properties["d"] = d;
+ request.Properties["e"] = e;
+ request.Properties["f"] = f;
+ request.Properties["g"] = g;
+ request.Properties["h"] = h;
+ request.Properties["i"] = i;
+ request.Properties["j"] = j;
+ request.Properties["k"] = k;
+ request.Properties["l"] = l;
+ request.Properties["m"] = m;
+ request.Properties["n"] = n;
+
+ try
+ {
+ request.Properties["o"] = o;
+ Assert.Fail("Should not be able to add a Byte[] to the Properties of a Message.");
+ }
+ catch
+ {
+ // Expected
+ }
+
+ try
+ {
+ request.Properties.SetBytes("o", o);
+ Assert.Fail("Should not be able to add a Byte[] to the Properties of a Message.");
+ }
+ catch
+ {
+ // Expected
+ }
+
+ producer.Send(request);
+
+ IMessage message = consumer.Receive(receiveTimeout);
+ Assert.IsNotNull(message, "No message returned!");
+ Assert.AreEqual(request.Properties.Count, message.Properties.Count, "Invalid number of properties.");
+ Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");
+ Assert.AreEqual(ToHex(f), ToHex(message.Properties.GetLong("f")), "map entry: f as hex");
+
+ // use generic API to access entries
+ // Perform a string only comparison here since some NMS providers are type limited and
+ // may return only a string instance from the generic [] accessor. Each provider should
+ // further test this functionality to determine that the correct type is returned if
+ // it is capable of doing so.
+ Assert.AreEqual(a.ToString(), message.Properties["a"].ToString(), "generic map entry: a");
+ Assert.AreEqual(b.ToString(), message.Properties["b"].ToString(), "generic map entry: b");
+ Assert.AreEqual(c.ToString(), message.Properties["c"].ToString(), "generic map entry: c");
+ Assert.AreEqual(d.ToString(), message.Properties["d"].ToString(), "generic map entry: d");
+ Assert.AreEqual(e.ToString(), message.Properties["e"].ToString(), "generic map entry: e");
+ Assert.AreEqual(f.ToString(), message.Properties["f"].ToString(), "generic map entry: f");
+ Assert.AreEqual(g.ToString(), message.Properties["g"].ToString(), "generic map entry: g");
+ Assert.AreEqual(h.ToString(), message.Properties["h"].ToString(), "generic map entry: h");
+ Assert.AreEqual(i.ToString(), message.Properties["i"].ToString(), "generic map entry: i");
+ Assert.AreEqual(j.ToString(), message.Properties["j"].ToString(), "generic map entry: j");
+ Assert.AreEqual(k.ToString(), message.Properties["k"].ToString(), "generic map entry: k");
+ Assert.AreEqual(l.ToString(), message.Properties["l"].ToString(), "generic map entry: l");
+ Assert.AreEqual(m.ToString(), message.Properties["m"].ToString(), "generic map entry: m");
+ Assert.AreEqual(n.ToString(), message.Properties["n"].ToString(), "generic map entry: n");
+
+ // use type safe APIs
+ Assert.AreEqual(a, message.Properties.GetBool("a"), "map entry: a");
+ Assert.AreEqual(b, message.Properties.GetByte("b"), "map entry: b");
+ Assert.AreEqual(c, message.Properties.GetChar("c"), "map entry: c");
+ Assert.AreEqual(d, message.Properties.GetShort("d"), "map entry: d");
+ Assert.AreEqual(e, message.Properties.GetInt("e"), "map entry: e");
+ Assert.AreEqual(f, message.Properties.GetLong("f"), "map entry: f");
+ Assert.AreEqual(g, message.Properties.GetString("g"), "map entry: g");
+ Assert.AreEqual(h, message.Properties.GetBool("h"), "map entry: h");
+ Assert.AreEqual(i, message.Properties.GetByte("i"), "map entry: i");
+ Assert.AreEqual(j, message.Properties.GetShort("j"), "map entry: j");
+ Assert.AreEqual(k, message.Properties.GetInt("k"), "map entry: k");
+ Assert.AreEqual(l, message.Properties.GetLong("l"), "map entry: l");
+ Assert.AreEqual(m, message.Properties.GetFloat("m"), "map entry: m");
+ Assert.AreEqual(n, message.Properties.GetDouble("n"), "map entry: n");
+ }
+ }
+ }
+ }
+ }
+}
+
Added: activemq/activemq-dotnet/Apache.NMS.XMS/trunk/src/test/csharp/MessageTransformerTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.XMS/trunk/src/test/csharp/MessageTransformerTest.cs?rev=1723221&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.XMS/trunk/src/test/csharp/MessageTransformerTest.cs (added)
+++ activemq/activemq-dotnet/Apache.NMS.XMS/trunk/src/test/csharp/MessageTransformerTest.cs Wed Jan 6 02:19:56 2016
@@ -0,0 +1,124 @@
+/*
+ * 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 System;
+using Apache.NMS.Util;
+using NUnit.Framework;
+
+namespace Apache.NMS.Test
+{
+ //[TestFixture]
+ public class MessageTransformerTest : NMSTest
+ {
+ private string propertyName = "ADDITIONAL-PROPERTY";
+ private string propertyValue = "ADDITIONAL-PROPERTY-VALUE";
+
+ protected MessageTransformerTest(NMSTestSupport testSupport)
+ : base(testSupport)
+ {
+ }
+
+ //[Test]
+ public virtual void TestProducerTransformer(
+ //[Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
+ MsgDeliveryMode deliveryMode)
+ {
+ using(IConnection connection = CreateConnection())
+ {
+ connection.Start();
+ using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
+ {
+ IDestination destination = session.CreateTemporaryTopic();
+ using(IMessageConsumer consumer = session.CreateConsumer(destination))
+ using(IMessageProducer producer = session.CreateProducer(destination))
+ {
+ producer.DeliveryMode = deliveryMode;
+ producer.ProducerTransformer = DoProducerTransform;
+
+ IMessage message = session.CreateMessage();
+
+ message.Properties["Test"] = "Value";
+
+ producer.Send(message);
+
+ message = consumer.Receive(TimeSpan.FromMilliseconds(5000));
+
+ Assert.IsNotNull(message);
+ Assert.IsTrue(message.Properties.Count == 2);
+
+ Assert.AreEqual("Value", message.Properties["Test"]);
+ Assert.AreEqual(propertyValue, message.Properties[propertyName]);
+ }
+ }
+ }
+ }
+
+ //[Test]
+ public virtual void TestConsumerTransformer(
+ //[Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
+ MsgDeliveryMode deliveryMode)
+ {
+ using(IConnection connection = CreateConnection())
+ {
+ connection.Start();
+ using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
+ {
+ IDestination destination = session.CreateTemporaryTopic();
+ using(IMessageConsumer consumer = session.CreateConsumer(destination))
+ using(IMessageProducer producer = session.CreateProducer(destination))
+ {
+ producer.DeliveryMode = deliveryMode;
+
+ consumer.ConsumerTransformer = DoConsumerTransform;
+
+ IMessage message = session.CreateMessage();
+
+ message.Properties["Test"] = "Value";
+
+ producer.Send(message);
+
+ message = consumer.Receive(TimeSpan.FromMilliseconds(5000));
+
+ Assert.IsNotNull(message);
+ Assert.IsTrue(message.Properties.Count == 2, "Property Count should be 2");
+
+ Assert.AreEqual("Value", message.Properties["Test"], "Property 'Value' was incorrect");
+ Assert.AreEqual(propertyValue, message.Properties[propertyName], "Property not inserted");
+ }
+ }
+ }
+ }
+
+ private IMessage DoProducerTransform(ISession session, IMessageProducer producer, IMessage message)
+ {
+ message.Properties[propertyName] = propertyValue;
+
+ return message;
+ }
+
+ private IMessage DoConsumerTransform(ISession session, IMessageConsumer consumer, IMessage message)
+ {
+ IMessage newMessage = session.CreateMessage();
+
+ MessageTransformation.CopyNMSMessageProperties(message, newMessage);
+
+ newMessage.Properties[propertyName] = propertyValue;
+
+ return newMessage;
+ }
+ }
+}
+
Added: activemq/activemq-dotnet/Apache.NMS.XMS/trunk/src/test/csharp/NMSPropertyTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.XMS/trunk/src/test/csharp/NMSPropertyTest.cs?rev=1723221&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.XMS/trunk/src/test/csharp/NMSPropertyTest.cs (added)
+++ activemq/activemq-dotnet/Apache.NMS.XMS/trunk/src/test/csharp/NMSPropertyTest.cs Wed Jan 6 02:19:56 2016
@@ -0,0 +1,82 @@
+/*
+ * 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 System;
+using Apache.NMS.Util;
+using NUnit.Framework;
+
+namespace Apache.NMS.Test
+{
+ //[TestFixture]
+ public class NMSPropertyTest : NMSTest
+ {
+ // standard NMS properties
+ protected string expectedText = "Hey this works!";
+ protected string correlationID = "FooBar";
+ protected MsgPriority priority = MsgPriority.Normal;
+ protected String type = "FooType";
+ protected String groupID = "BarGroup";
+ protected int groupSeq = 1;
+
+ protected NMSPropertyTest(NMSTestSupport testSupport)
+ : base (testSupport)
+ {
+ }
+
+ //[Test]
+ public void TestSendReceiveNMSProperties(
+ //[Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
+ MsgDeliveryMode deliveryMode, string testQueueRef)
+ {
+ using(IConnection connection = CreateConnection(GetTestClientId()))
+ {
+ connection.Start();
+ using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
+ {
+ IDestination destination = GetClearDestination(session, DestinationType.Queue, testQueueRef);
+ using(IMessageConsumer consumer = session.CreateConsumer(destination))
+ using(IMessageProducer producer = session.CreateProducer(destination))
+ {
+ producer.Priority = priority;
+ producer.DeliveryMode = deliveryMode;
+ ITextMessage request = session.CreateTextMessage(expectedText);
+
+ // Set the headers
+ request.NMSCorrelationID = correlationID;
+ request.NMSType = type;
+ request.Properties["NMSXGroupID"] = groupID;
+ request.Properties["NMSXGroupSeq"] = groupSeq;
+
+ producer.Send(request);
+
+ ITextMessage message = consumer.Receive(receiveTimeout) as ITextMessage;
+
+ Assert.IsNotNull(message, "Did not receive an ITextMessage!");
+ Assert.AreEqual(expectedText, message.Text, "Message text does not match.");
+
+ // compare standard NMS headers
+ Assert.AreEqual(correlationID, message.NMSCorrelationID, "NMSCorrelationID does not match");
+ Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");
+ Assert.AreEqual(priority, message.NMSPriority, "NMSPriority does not match");
+ Assert.AreEqual(type, message.NMSType, "NMSType does not match");
+ Assert.AreEqual(groupID, message.Properties["NMSXGroupID"], "NMSXGroupID does not match");
+ Assert.AreEqual(groupSeq, message.Properties["NMSXGroupSeq"], "NMSXGroupSeq does not match");
+ }
+ }
+ }
+ }
+ }
+}
Added: activemq/activemq-dotnet/Apache.NMS.XMS/trunk/src/test/csharp/NMSTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.XMS/trunk/src/test/csharp/NMSTest.cs?rev=1723221&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.XMS/trunk/src/test/csharp/NMSTest.cs (added)
+++ activemq/activemq-dotnet/Apache.NMS.XMS/trunk/src/test/csharp/NMSTest.cs Wed Jan 6 02:19:56 2016
@@ -0,0 +1,508 @@
+/*
+ * 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 System;
+using System.Xml;
+using Apache.NMS.Util;
+using NUnit.Framework;
+
+namespace Apache.NMS.Test
+{
+ /// <summary>
+ /// Base class for test cases
+ /// </summary>
+ public abstract class NMSTest
+ {
+ protected TimeSpan receiveTimeout = TimeSpan.FromMilliseconds(15000);
+
+ public static string ToHex(long value)
+ {
+ return String.Format("{0:x}", value);
+ }
+
+ #region Constructors and test support
+
+ private NMSTestSupport testSupport;
+
+ static NMSTest()
+ {
+ Apache.NMS.Tracer.Trace = new NMSTracer();
+ }
+
+ protected NMSTest(NMSTestSupport testSupport)
+ {
+ this.testSupport = testSupport;
+ this.testSupport.TestClassType = this.GetType();
+ }
+
+ #endregion
+
+ #region Set up and tear down
+
+ [SetUp]
+ public virtual void SetUp()
+ {
+ this.testSupport.SetUp();
+ }
+
+ [TearDown]
+ public virtual void TearDown()
+ {
+ this.testSupport.TearDown();
+ }
+
+ #endregion
+
+ #region Configuration file
+
+ /// <summary>
+ /// The configuration document.
+ /// </summary>
+ public XmlDocument ConfigurationDocument
+ {
+ get { return this.testSupport.ConfigurationDocument; }
+ }
+
+ /// <summary>
+ /// Loads the configuration file.
+ /// </summary>
+ /// <returns>XmlDocument of the configuration file</returns>
+ protected virtual XmlDocument LoadConfigFile()
+ {
+ return this.testSupport.LoadConfigFile();
+ }
+
+ /// <summary>
+ /// Loads the configuration file.
+ /// </summary>
+ /// <param name="configFilePath">Configuration file path</param>
+ /// <returns>XmlDocument of the configuration file</returns>
+ protected virtual XmlDocument LoadConfigFile(string configFilePath)
+ {
+ return this.testSupport.LoadConfigFile(configFilePath);
+ }
+
+ /// <summary>
+ /// Gets the path of the configuration filename.
+ /// </summary>
+ /// <returns>Path of the configuration filename</returns>
+ protected virtual string GetConfigFilePath()
+ {
+ return this.testSupport.GetConfigFilePath();
+ }
+
+ /// <summary>
+ /// Gets the environment variable name for the configuration file path.
+ /// </summary>
+ /// <returns>Environment variable name</returns>
+ protected virtual string GetConfigEnvVarName()
+ {
+ return this.testSupport.GetConfigEnvVarName();
+ }
+
+ /// <summary>
+ /// Gets the default name for the configuration filename.
+ /// </summary>
+ /// <returns>Default name of the configuration filename</returns>
+ protected virtual string GetDefaultConfigFileName()
+ {
+ return this.testSupport.GetDefaultConfigFileName();
+ }
+
+ /// <summary>
+ /// Gets the value of the "value" attribute of the specified node.
+ /// </summary>
+ /// <param name="parentNode">Parent node</param>
+ /// <param name="nodeName">Node name</param>
+ /// <param name="defaultVaue">Default value</param>
+ /// <returns></returns>
+ protected virtual string GetNodeValueAttribute(XmlElement parentNode,
+ string nodeName, string defaultVaue)
+ {
+ return this.testSupport.GetNodeValueAttribute(parentNode,
+ nodeName, defaultVaue);
+ }
+
+ #endregion
+
+ #region URI node
+
+ /// <summary>
+ /// Gets the URI node for the default configuration.
+ /// </summary>
+ /// <returns>URI node for the default configuration name</returns>
+ public virtual XmlElement GetURINode()
+ {
+ return this.testSupport.GetURINode();
+ }
+
+ /// <summary>
+ /// Gets the URI node for the default configuration.
+ /// </summary>
+ /// <param name="nameTestURI">Name of the default configuration node
+ /// </param>
+ /// <returns>URI node for the default configuration name</returns>
+ public virtual XmlElement GetURINode(string nameTestURI)
+ {
+ return this.testSupport.GetURINode(nameTestURI);
+ }
+
+ /// <summary>
+ /// Gets the name of the default connection configuration to be loaded.
+ /// </summary>
+ /// <returns>Default configuration name</returns>
+ protected virtual string GetNameTestURI()
+ {
+ return this.testSupport.GetNameTestURI();
+ }
+
+ #endregion
+
+ #region Factory
+
+ private NMSConnectionFactory nmsFactory;
+ /// <summary>
+ /// The connection factory interface property.
+ /// </summary>
+ public IConnectionFactory Factory
+ {
+ get { return this.testSupport.Factory; }
+ }
+
+ /// <summary>
+ /// Create the NMS Factory that can create NMS Connections.
+ /// </summary>
+ /// <returns>Connection factory</returns>
+ protected NMSConnectionFactory CreateNMSFactory()
+ {
+ return this.testSupport.CreateNMSFactory();
+ }
+
+ /// <summary>
+ /// Create the NMS Factory that can create NMS Connections. This
+ /// function loads the connection settings from the configuration file.
+ /// </summary>
+ /// <param name="nameTestURI">The named connection configuration.
+ /// </param>
+ /// <returns>Connection factory</returns>
+ protected NMSConnectionFactory CreateNMSFactory(string nameTestURI)
+ {
+ return this.testSupport.CreateNMSFactory(nameTestURI);
+ }
+
+ /// <summary>
+ /// Get the parameters for the ConnectionFactory from the configuration
+ /// file.
+ /// </summary>
+ /// <param name="uriNode">Parent node of the factoryParams node.</param>
+ /// <returns>Object array of parameter objects to be passsed to provider
+ /// factory object. Null if no parameters are specified in
+ /// configuration file.</returns>
+ protected object[] GetFactoryParams(XmlElement uriNode)
+ {
+ return this.testSupport.GetFactoryParams(uriNode);
+ }
+
+ #endregion
+
+ #region Client id and connection
+
+ /// <summary>
+ /// Client id.
+ /// </summary>
+ public string ClientId
+ {
+ get { return this.testSupport.ClientId; }
+ }
+
+ /// <summary>
+ /// Gets a new client id.
+ /// </summary>
+ /// <returns>Client id</returns>
+ public virtual string GetTestClientId()
+ {
+ return this.testSupport.GetTestClientId();
+ }
+
+ /// <summary>
+ /// Create a new connection to the broker.
+ /// </summary>
+ /// <returns>New connection</returns>
+ public virtual IConnection CreateConnection()
+ {
+ return this.testSupport.CreateConnection();
+ }
+
+ /// <summary>
+ /// Create a new connection to the broker.
+ /// </summary>
+ /// <param name="newClientId">Client ID of the new connection.</param>
+ /// <returns>New connection</returns>
+ public virtual IConnection CreateConnection(string newClientId)
+ {
+ return this.testSupport.CreateConnection(newClientId);
+ }
+
+ /// <summary>
+ /// Create a new connection to the broker, and start it.
+ /// </summary>
+ /// <returns>Started connection</returns>
+ public virtual IConnection CreateConnectionAndStart()
+ {
+ return this.testSupport.CreateConnectionAndStart();
+ }
+
+ /// <summary>
+ /// Create a new connection to the broker, and start it.
+ /// </summary>
+ /// <param name="newClientId">Client ID of the new connection.</param>
+ /// <returns>Started connection</returns>
+ public virtual IConnection CreateConnectionAndStart(string newClientId)
+ {
+ return this.testSupport.CreateConnectionAndStart(newClientId);
+ }
+
+ #endregion
+
+ #region Destination
+
+ /// <summary>
+ /// Gets a clear destination.
+ /// </summary>
+ /// <param name="session">Session</param>
+ /// <param name="type">Destination type</param>
+ /// <param name="destinationRef">Configuration node name for the
+ /// destination URI</param>
+ /// <returns>Destination</returns>
+ public virtual IDestination GetClearDestination(ISession session,
+ DestinationType type, string destinationRef)
+ {
+ return this.testSupport.GetClearDestination(session, type, destinationRef);
+ }
+
+ /// <summary>
+ /// Gets a clear destination. This will try to delete an existing
+ /// destination and re-create it.
+ /// </summary>
+ /// <param name="session">Session</param>
+ /// <param name="destinationURI">Destination URI</param>
+ /// <returns>Clear destination</returns>
+ public virtual IDestination GetClearDestination(ISession session,
+ string destinationURI)
+ {
+ return this.testSupport.GetClearDestination(session, destinationURI);
+ }
+
+ /// <summary>
+ /// Gets an existing destination. Don't clear its contents.
+ /// </summary>
+ /// <param name="session">Session</param>
+ /// <param name="type">Destination type</param>
+ /// <param name="destinationRef">Configuration node name for the
+ /// destination URI</param>
+ /// <returns>Destination</returns>
+ public virtual IDestination GetDestination(ISession session,
+ DestinationType type, string destinationRef)
+ {
+ return this.testSupport.GetDestination(session, type, destinationRef);
+ }
+
+ /// <summary>
+ /// Gets a destination URI.
+ /// </summary>
+ /// <param name="type">Destination type</param>
+ /// <param name="destinationRef">Configuration node name for the
+ /// destination URI</param>
+ /// <returns>Destination URI</returns>
+ public virtual string GetDestinationURI(DestinationType type, string destinationRef)
+ {
+ return this.testSupport.GetDestinationURI(type, destinationRef);
+ }
+
+ #endregion
+
+ #region Durable consumer
+
+ /// <summary>
+ /// Register a durable consumer
+ /// </summary>
+ /// <param name="connectionID">Connection ID of the consumer.</param>
+ /// <param name="destination">Destination name to register. Supports
+ /// embedded prefix names.</param>
+ /// <param name="consumerID">Name of the durable consumer.</param>
+ /// <param name="selector">Selector parameters for consumer.</param>
+ /// <param name="noLocal"></param>
+ protected void RegisterDurableConsumer(string connectionID,
+ string destination, string consumerID, string selector, bool noLocal)
+ {
+ using(IConnection connection = CreateConnection(connectionID))
+ {
+ connection.Start();
+ using(ISession session = connection.CreateSession(
+ AcknowledgementMode.DupsOkAcknowledge))
+ {
+ ITopic destinationTopic = (ITopic)SessionUtil.GetDestination(session, destination);
+ Assert.IsNotNull(destinationTopic, "Could not get destination topic.");
+
+ using(IMessageConsumer consumer = session.CreateDurableConsumer(destinationTopic, consumerID, selector, noLocal))
+ {
+ Assert.IsNotNull(consumer, "Could not create durable consumer.");
+ }
+ }
+ }
+ }
+
+ /// <summary>
+ /// Unregister a durable consumer for the given connection ID.
+ /// </summary>
+ /// <param name="connectionID">Connection ID of the consumer.</param>
+ /// <param name="consumerID">Name of the durable consumer.</param>
+ protected void UnregisterDurableConsumer(string connectionID, string consumerID)
+ {
+ using(IConnection connection = CreateConnection(connectionID))
+ {
+ connection.Start();
+ using(ISession session = connection.CreateSession(AcknowledgementMode.DupsOkAcknowledge))
+ {
+ session.DeleteDurableConsumer(consumerID);
+ }
+ }
+ }
+
+ #endregion
+
+ #region Send messages
+
+ /// <summary>
+ /// Sends a specified number of text messages to the designated
+ /// destination.
+ /// </summary>
+ /// <param name="destination">Destination.</param>
+ /// <param name="deliveryMode">Delivery mode.</param>
+ /// <param name="count">Number of messages to be sent.</param>
+ public void SendMessages(IDestination destination,
+ MsgDeliveryMode deliveryMode, int count)
+ {
+ IConnection connection = CreateConnection();
+ connection.Start();
+ SendMessages(connection, destination, deliveryMode, count);
+ connection.Close();
+ }
+
+ /// <summary>
+ /// Sends a specified number of text messages to the designated
+ /// destination.
+ /// </summary>
+ /// <param name="connection">Connection.</param>
+ /// <param name="destination">Destination.</param>
+ /// <param name="deliveryMode">Delivery mode.</param>
+ /// <param name="count">Number of messages to be sent.</param>
+ public void SendMessages(IConnection connection,
+ IDestination destination, MsgDeliveryMode deliveryMode, int count)
+ {
+ ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
+ SendMessages(session, destination, deliveryMode, count);
+ session.Close();
+ }
+
+ /// <summary>
+ /// Sends a specified number of text messages to the designated
+ /// destination.
+ /// </summary>
+ /// <param name="session">Session.</param>
+ /// <param name="destination">Destination.</param>
+ /// <param name="deliveryMode">Delivery mode.</param>
+ /// <param name="count">Number of messages to be sent.</param>
+ public void SendMessages(ISession session, IDestination destination,
+ MsgDeliveryMode deliveryMode, int count)
+ {
+ IMessageProducer producer = session.CreateProducer(destination);
+ producer.DeliveryMode = deliveryMode;
+ for(int i = 0; i < count; i++)
+ {
+ producer.Send(session.CreateTextMessage("" + i));
+ }
+ producer.Close();
+ }
+
+ #endregion
+
+ #region Check messages
+
+ protected void AssertTextMessagesEqual(IMessage[] firstSet, IMessage[] secondSet)
+ {
+ AssertTextMessagesEqual(firstSet, secondSet, "");
+ }
+
+ protected void AssertTextMessagesEqual(IMessage[] firstSet, IMessage[] secondSet, string messsage)
+ {
+ Assert.AreEqual(firstSet.Length, secondSet.Length, "Message count does not match: " + messsage);
+
+ for(int i = 0; i < secondSet.Length; i++)
+ {
+ ITextMessage m1 = firstSet[i] as ITextMessage;
+ ITextMessage m2 = secondSet[i] as ITextMessage;
+
+ AssertTextMessageEqual(m1, m2, "Message " + (i + 1) + " did not match : ");
+ }
+ }
+
+ protected void AssertEquals(ITextMessage m1, ITextMessage m2)
+ {
+ AssertEquals(m1, m2, "");
+ }
+
+ protected void AssertTextMessageEqual(ITextMessage m1, ITextMessage m2, string message)
+ {
+ Assert.IsFalse(m1 == null ^ m2 == null, message + ": expected {" + m1 + "}, but was {" + m2 + "}");
+
+ if(m1 == null)
+ {
+ return;
+ }
+
+ Assert.AreEqual(m1.Text, m2.Text, message);
+ }
+
+ protected void AssertEquals(IMessage m1, IMessage m2)
+ {
+ AssertEquals(m1, m2, "");
+ }
+
+ protected void AssertEquals(IMessage m1, IMessage m2, string message)
+ {
+ Assert.IsFalse(m1 == null ^ m2 == null, message + ": expected {" + m1 + "}, but was {" + m2 + "}");
+
+ if(m1 == null)
+ {
+ return;
+ }
+
+ Assert.IsTrue(m1.GetType() == m2.GetType(), message + ": expected {" + m1 + "}, but was {" + m2 + "}");
+
+ if(m1 is ITextMessage)
+ {
+ AssertTextMessageEqual((ITextMessage) m1, (ITextMessage) m2, message);
+ }
+ else
+ {
+ Assert.AreEqual(m1, m2, message);
+ }
+ }
+
+ #endregion
+ }
+}