activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r451036 [2/3] - in /incubator/activemq/activemq-dotnet/trunk: ./ src/main/csharp/ src/main/csharp/ActiveMQ/Commands/ src/main/csharp/ActiveMQ/OpenWire/ src/main/csharp/ActiveMQ/Transport/ src/main/csharp/JMS/ src/main/csharp/MSMQ/ src/main/...
Date Thu, 28 Sep 2006 22:01:07 GMT
Added: incubator/activemq/activemq-dotnet/trunk/src/test/csharp/ActiveMQ/TransactionTest.cs
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-dotnet/trunk/src/test/csharp/ActiveMQ/TransactionTest.cs?view=auto&rev=451036
==============================================================================
--- incubator/activemq/activemq-dotnet/trunk/src/test/csharp/ActiveMQ/TransactionTest.cs (added)
+++ incubator/activemq/activemq-dotnet/trunk/src/test/csharp/ActiveMQ/TransactionTest.cs Thu Sep 28 15:01:04 2006
@@ -0,0 +1,38 @@
+/*
+ * 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 ActiveMQ;
+using NMS;
+using NUnit.Framework;
+using System;
+
+
+namespace ActiveMQ
+{
+	[TestFixture]
+    public class TransactionTest : NMS.Test.TransactionTest 
+    {
+
+        private String brokerURI = "tcp://localhost:61616";
+        protected override IConnectionFactory CreateConnectionFactory()
+        {
+            return new ConnectionFactory(new Uri(brokerURI));
+        }
+		
+    }
+}
+
+

Modified: incubator/activemq/activemq-dotnet/trunk/src/test/csharp/CommonAssemblyInfo.cs
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-dotnet/trunk/src/test/csharp/CommonAssemblyInfo.cs?view=diff&rev=451036&r1=451035&r2=451036
==============================================================================
--- incubator/activemq/activemq-dotnet/trunk/src/test/csharp/CommonAssemblyInfo.cs (original)
+++ incubator/activemq/activemq-dotnet/trunk/src/test/csharp/CommonAssemblyInfo.cs Thu Sep 28 15:01:04 2006
@@ -2,15 +2,15 @@
 using System.Reflection;
 using System.Runtime.InteropServices;
 
-// ------------------------------------------------------------------------------
-//  <autogenerated>
-//      This code was generated by a tool.
-//      Mono Runtime Version: 1.1.4322.2032
-// 
-//      Changes to this file may cause incorrect behavior and will be lost if 
-//      the code is regenerated.
-//  </autogenerated>
-// ------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+// <auto-generated>
+//     This code was generated by a tool.
+//     Runtime Version:2.0.50727.42
+//
+//     Changes to this file may cause incorrect behavior and will be lost if
+//     the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
 
 [assembly: ComVisibleAttribute(false)]
 [assembly: CLSCompliantAttribute(false)]
@@ -22,6 +22,6 @@
 [assembly: AssemblyCopyrightAttribute("Copyright (C) 2005-2006 Apache Software Foundation")]
 [assembly: AssemblyTrademarkAttribute("")]
 [assembly: AssemblyCultureAttribute("")]
-[assembly: AssemblyVersionAttribute("4.0.2460.0")]
+[assembly: AssemblyVersionAttribute("4.0.2462.0")]
 [assembly: AssemblyInformationalVersionAttribute("4.0")]
 

Added: incubator/activemq/activemq-dotnet/trunk/src/test/csharp/MSMQ/MSMQTest.cs
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-dotnet/trunk/src/test/csharp/MSMQ/MSMQTest.cs?view=auto&rev=451036
==============================================================================
--- incubator/activemq/activemq-dotnet/trunk/src/test/csharp/MSMQ/MSMQTest.cs (added)
+++ incubator/activemq/activemq-dotnet/trunk/src/test/csharp/MSMQ/MSMQTest.cs Thu Sep 28 15:01:04 2006
@@ -0,0 +1,126 @@
+/*
+ * 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.Messaging;
+
+namespace MSMQ
+{    
+    /// <summary>
+    /// Use to test and verify MSMQ behaviour.
+    /// </summary>
+	[TestFixture]
+    public class MSMQTest
+    {
+        String queueName = ".\\Private$\\FOO";
+	    
+		[SetUp]
+        public void SetUp()
+        {
+        }
+		
+        [TearDown]
+        public void TearDown()
+        {
+        }		
+		
+        [Test]
+        public void TestSendAndReceive()
+        {
+            // check to make sure the message queue does not exist already
+            if (!MessageQueue.Exists(queueName))
+            {
+                // create the new message queue and make it transactional
+                MessageQueue MQ = MessageQueue.Create(queueName, true);
+
+                // set the label name and close the message queue
+                MQ.Label = "FOO";
+                MQ.Close();
+
+                Console.WriteLine("Created Queue: " + queueName);
+                //Assert.Fail("Should  have thrown an exception!");
+            } 
+            else
+            {
+                Console.WriteLine("Queue Existed: " + queueName);
+                
+            }
+
+
+            if (!MessageQueue.Exists(".\\Private$\\BAR"))
+            {
+                // create the new message queue and make it transactional
+                MessageQueue MQ = MessageQueue.Create(".\\Private$\\BAR", true);
+
+                // set the label name and close the message queue
+                MQ.Label = "BAR Label";
+                MQ.Close();
+
+            }
+            else
+            {
+                Console.WriteLine("Queue Existed: " + queueName);
+
+            }
+
+            // create a message queue transaction and start it
+            MessageQueueTransaction Transaction = new MessageQueueTransaction();
+            Transaction.Begin();
+
+            MessageQueue MQueue = new MessageQueue(queueName);
+
+            Message Msg = new Message("Hello World");
+            Msg.ResponseQueue = new MessageQueue(".\\Private$\\BAR");
+            Msg.Priority = MessagePriority.Normal;
+            Msg.UseJournalQueue = true;
+            Msg.Label = "Test Label";
+
+            Msg.AcknowledgeType = AcknowledgeTypes.FullReceive;
+            Msg.AdministrationQueue = Msg.ResponseQueue;
+
+            // send the message
+            MQueue.Send(Msg, Transaction);
+            MQueue.Send(Msg, Transaction);
+            MQueue.Send(Msg, Transaction);
+
+            // commit the transaction
+            Transaction.Commit();
+
+            
+            // Read the message.
+            MQueue.MessageReadPropertyFilter.SetAll();
+            
+            // the target type we have stored in the message body
+            
+            ((XmlMessageFormatter)MQueue.Formatter).TargetTypes = new Type[] { typeof(String) };
+            
+              // read the message from the queue, but only wait for 5 sec
+              Msg = MQueue.Receive(new TimeSpan(0, 0, 5));
+
+              // read the order from the message body
+              Console.WriteLine("Received: "+Msg.Body);
+            
+
+            // close the mesage queue
+            MQueue.Close();
+		}
+						
+    }
+}
+
+
+

Added: incubator/activemq/activemq-dotnet/trunk/src/test/csharp/MSMQ/ProducerTest.cs
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-dotnet/trunk/src/test/csharp/MSMQ/ProducerTest.cs?view=auto&rev=451036
==============================================================================
--- incubator/activemq/activemq-dotnet/trunk/src/test/csharp/MSMQ/ProducerTest.cs (added)
+++ incubator/activemq/activemq-dotnet/trunk/src/test/csharp/MSMQ/ProducerTest.cs Thu Sep 28 15:01:04 2006
@@ -0,0 +1,66 @@
+/*
+ * 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 NMS;
+using NUnit.Framework;
+
+namespace MSMQ
+{
+	[TestFixture]
+    public class ProducerTest : NMS.Test.NMSTestSupport
+    {
+				
+		[SetUp]
+        override public void SetUp()
+        {
+			base.SetUp();
+        }
+		
+        [TearDown]
+        override public void TearDown()
+        {
+			base.TearDown();
+        }
+
+        override protected IConnectionFactory CreateConnectionFactory()
+        {
+            return new ConnectionFactory();
+        }
+	    
+        protected override string CreateDestinationName()
+        {
+            return ".\\Private$\\" + GetType().Name;
+        }
+	    
+        [Test]
+        public void TestPublishMessage()
+        {            
+            IMessageProducer producer = Session.CreateProducer(Destination);
+			producer.Persistent = true;
+			
+            // Send the messages
+            ITextMessage message = Session.CreateTextMessage("1st");
+//            message.Properties["color"] =  "red";
+            producer.Send(message);
+            
+            
+        }
+				
+    }
+}
+
+
+

Added: incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/AsyncConsumeTest.cs
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/AsyncConsumeTest.cs?view=auto&rev=451036
==============================================================================
--- incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/AsyncConsumeTest.cs (added)
+++ incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/AsyncConsumeTest.cs Thu Sep 28 15:01:04 2006
@@ -0,0 +1,148 @@
+/*
+ * 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 NUnit.Framework;
+
+namespace NMS.Test
+{
+    [TestFixture]
+    public abstract class AsyncConsumeTest : NMSTestSupport
+    {
+        protected Object semaphore = new Object();
+        protected bool received;
+
+
+        [SetUp]
+        public override void SetUp()
+        {
+            base.SetUp();
+        }
+
+        [TearDown]
+        public override void TearDown()
+        {
+            base.TearDown();
+        }
+
+        [Test]
+        public void TestAsynchronousConsume()
+        {
+            // START SNIPPET: demo
+            IMessageConsumer consumer = Session.CreateConsumer(Destination);
+            consumer.Listener += new MessageListener(OnMessage);
+            // END SNIPPET: demo
+
+            // now lets send a message
+            IMessageProducer producer = CreateProducer();
+            IMessage request = CreateMessage();
+            request.NMSCorrelationID = "abc";
+            request.NMSType = "Test";
+            producer.Send(request);
+
+            WaitForMessageToArrive();
+        }
+
+        [Test]
+        public void TestCreateConsumerAfterSend()
+        {
+            // now lets send a message
+            IMessageProducer producer = CreateProducer();
+            IMessage request = CreateMessage();
+            request.NMSCorrelationID = "abc";
+            request.NMSType = "Test";
+            producer.Send(request);
+
+            // lets create an async consumer
+            IMessageConsumer consumer = Session.CreateConsumer(Destination);
+            consumer.Listener += new MessageListener(OnMessage);
+
+            WaitForMessageToArrive();
+        }
+
+        [Test]
+        public void TestCreateConsumerBeforeSendButAddListenerAfterSend()
+        {
+            // lets create an async consumer
+            IMessageConsumer consumer = Session.CreateConsumer(Destination);
+
+            // now lets send a message
+            IMessageProducer producer = CreateProducer();
+            IMessage request = CreateMessage();
+            request.NMSCorrelationID = "abc";
+            request.NMSType = "Test";
+            producer.Send(request);
+
+            // now lets add the listener
+            consumer.Listener += new MessageListener(OnMessage);
+
+            WaitForMessageToArrive();
+        }
+
+        [Test]
+        public void TextMessageSRExample()
+        {
+            using (IConnection connection = Factory.CreateConnection())
+            {
+                AcknowledgementMode acknowledgementMode = AcknowledgementMode.AutoAcknowledge;
+                ISession session = connection.CreateSession(acknowledgementMode);
+
+                IDestination destination = session.GetQueue("FOO.BAR");
+
+                // lets create a consumer and producer
+                IMessageConsumer consumer = session.CreateConsumer(destination);
+                consumer.Listener += new MessageListener(OnMessage);
+
+                IMessageProducer producer = session.CreateProducer(destination);
+                producer.Persistent = true;
+
+                // lets send a message
+                ITextMessage request = session.CreateTextMessage(
+                    "HelloWorld!");
+                request.NMSCorrelationID = "abc";
+                request.Properties["NMSXGroupID"] = "cheese";
+                request.Properties["myHeader"] = "James";
+
+                producer.Send(request);
+
+                WaitForMessageToArrive();
+            }
+        }
+
+        protected void OnMessage(IMessage message)
+        {
+            Console.WriteLine("Received message: " + message);
+            lock (semaphore)
+            {
+                received = true;
+                Monitor.PulseAll(semaphore);
+            }
+        }
+
+        protected void WaitForMessageToArrive()
+        {
+            lock (semaphore)
+            {
+                if (!received)
+                {
+                    Monitor.Wait(semaphore, receiveTimeout);
+                }
+                Assert.AreEqual(true, received, "Should have received a message by now!");
+            }
+        }
+    }
+}
\ No newline at end of file

Added: incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/BadConsumeTest.cs
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/BadConsumeTest.cs?view=auto&rev=451036
==============================================================================
--- incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/BadConsumeTest.cs (added)
+++ incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/BadConsumeTest.cs Thu Sep 28 15:01:04 2006
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+using NUnit.Framework;
+
+namespace NMS.Test
+{
+    [TestFixture]
+    public abstract class BadConsumeTest : NMSTestSupport
+    {
+        [SetUp]
+        public override void SetUp()
+        {
+            base.SetUp();
+        }
+
+        [TearDown]
+        public override void TearDown()
+        {
+            base.TearDown();
+        }
+
+        [Test]
+        public void TestBadConsumeOperationToTestExceptions()
+        {
+            try
+            {
+                IMessageConsumer consumer = Session.CreateConsumer(null);
+                Console.WriteLine("Created consumer: " + consumer);
+                Assert.Fail("Should  have thrown an exception!");
+            }
+            catch (Exception e)
+            {
+                Console.WriteLine("Caught expected exception: " + e);
+                Console.WriteLine("Stack: " + e.StackTrace);
+            }
+        }
+    }
+}
\ No newline at end of file

Added: incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/BytesMessageTest.cs
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/BytesMessageTest.cs?view=auto&rev=451036
==============================================================================
--- incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/BytesMessageTest.cs (added)
+++ incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/BytesMessageTest.cs Thu Sep 28 15:01:04 2006
@@ -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 System;
+using NUnit.Framework;
+
+namespace NMS.Test
+{
+    [TestFixture]
+    public abstract class BytesMessageTest : NMSTestSupport
+    {
+        private byte[] expected = {1, 2, 3, 4, 5, 6, 7, 8};
+
+        [SetUp]
+        public override void SetUp()
+        {
+            base.SetUp();
+        }
+
+        [TearDown]
+        public override void TearDown()
+        {
+            base.TearDown();
+        }
+
+        [Test]
+        public override void SendAndSyncReceive()
+        {
+            base.SendAndSyncReceive();
+        }
+
+        protected override IMessage CreateMessage()
+        {
+            IBytesMessage request = Session.CreateBytesMessage(expected);
+            return request;
+        }
+
+        protected override void AssertValidMessage(IMessage message)
+        {
+            Assert.IsTrue(message is IBytesMessage, "Did not receive a IBytesMessage: " + message);
+
+            Console.WriteLine("Received IBytesMessage: " + message);
+
+            IBytesMessage bytesMessage = (IBytesMessage) message;
+            byte[] actual = bytesMessage.Content;
+            Console.WriteLine("Received message with content: " + actual);
+            Assert.AreEqual(expected, actual, "the message content");
+        }
+    }
+}
\ No newline at end of file

Added: incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/ConsumerTest.cs
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/ConsumerTest.cs?view=auto&rev=451036
==============================================================================
--- incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/ConsumerTest.cs (added)
+++ incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/ConsumerTest.cs Thu Sep 28 15:01:04 2006
@@ -0,0 +1,94 @@
+/*
+ * 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 NUnit.Framework;
+
+namespace NMS.Test
+{
+    [TestFixture]
+    public abstract class ConsumerTest : NMSTestSupport
+    {
+        public bool persistent;
+        public int prefetch;
+        public bool durableConsumer;
+
+        [SetUp]
+        public override void SetUp()
+        {
+            clientId = "test";
+            base.SetUp();
+        }
+
+        [TearDown]
+        public override void TearDown()
+        {
+            base.TearDown();
+        }
+
+
+        [Test]
+        public void TestDurableConsumerSelectorChangePersistent()
+        {
+            destinationType = DestinationType.Topic;
+            persistent = true;
+            doTestDurableConsumerSelectorChange();
+        }
+
+        [Test]
+        public void TestDurableConsumerSelectorChangeNonPersistent()
+        {
+            destinationType = DestinationType.Topic;
+            persistent = true;
+            doTestDurableConsumerSelectorChange();
+        }
+
+        public void doTestDurableConsumerSelectorChange()
+        {
+            IMessageProducer producer = Session.CreateProducer(Destination);
+            producer.Persistent = persistent;
+            IMessageConsumer consumer =
+                Session.CreateDurableConsumer((ITopic) Destination, "test", "color='red'", false);
+
+            // Send the messages
+            ITextMessage message = Session.CreateTextMessage("1st");
+            message.Properties["color"] = "red";
+            producer.Send(message);
+
+            IMessage m = consumer.Receive(TimeSpan.FromMilliseconds(receiveTimeout));
+            Assert.IsNotNull(m);
+            Assert.AreEqual("1st", ((ITextMessage) m).Text);
+
+            // Change the subscription.
+            consumer.Dispose();
+            consumer = Session.CreateDurableConsumer((ITopic) Destination, "test", "color='blue'", false);
+
+            message = Session.CreateTextMessage("2nd");
+            message.Properties["color"] = "red";
+            producer.Send(message);
+            message = Session.CreateTextMessage("3rd");
+            message.Properties["color"] = "blue";
+            producer.Send(message);
+
+            // Selector should skip the 2nd message.
+            m = consumer.Receive(TimeSpan.FromMilliseconds(1000));
+            Assert.IsNotNull(m);
+            Assert.AreEqual("3rd", ((ITextMessage) m).Text);
+
+            Assert.IsNull(consumer.ReceiveNoWait());
+        }
+    }
+}
\ No newline at end of file

Added: incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/DurableTest.cs
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/DurableTest.cs?view=auto&rev=451036
==============================================================================
--- incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/DurableTest.cs (added)
+++ incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/DurableTest.cs Thu Sep 28 15:01:04 2006
@@ -0,0 +1,107 @@
+/*
+ * 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 NUnit.Framework;
+
+namespace NMS.Test
+{
+    [TestFixture]
+    public abstract class DurableTest : NMSTestSupport
+    {
+        private static string TOPIC = "TestTopic";
+        private static String CLIENT_ID = "DurableClientId";
+        private static String CONSUMER_ID = "ConsumerId";
+
+        private int count = 0;
+
+        public void RegisterDurableConsumer()
+        {
+            using (IConnection connection = Factory.CreateConnection())
+            {
+                connection.ClientId = CLIENT_ID;
+                connection.Start();
+
+                using (ISession session = connection.CreateSession(
+                    AcknowledgementMode.DupsOkAcknowledge))
+                {
+                    ITopic topic = session.GetTopic(TOPIC);
+                    IMessageConsumer consumer = session.CreateDurableConsumer(
+                        topic, CONSUMER_ID, "2 > 1", false);
+                    consumer.Dispose();
+                }
+
+                connection.Stop();
+            }
+        }
+
+        public void SendPersistentMessage()
+        {
+            using (IConnection connection = Factory.CreateConnection())
+            {
+                connection.Start();
+                using (ISession session = connection.CreateSession(
+                    AcknowledgementMode.DupsOkAcknowledge))
+                {
+                    ITopic topic = session.GetTopic(TOPIC);
+                    ITextMessage message = session.CreateTextMessage("Hello");
+                    message.NMSPersistent = true;
+                    IMessageProducer producer = session.CreateProducer();
+                    producer.Send(topic, message);
+                    producer.Dispose();
+                }
+
+                connection.Stop();
+            }
+        }
+
+        [Test]
+        public void TestMe()
+        {
+            count = 0;
+
+            RegisterDurableConsumer();
+            SendPersistentMessage();
+
+            using (IConnection connection = Factory.CreateConnection())
+            {
+                connection.ClientId = CLIENT_ID;
+                connection.Start();
+
+                using (ISession session = connection.CreateSession(
+                    AcknowledgementMode.DupsOkAcknowledge))
+                {
+                    ITopic topic = session.GetTopic(TOPIC);
+                    IMessageConsumer consumer = session.CreateDurableConsumer(
+                        topic, CONSUMER_ID, "2 > 1", false);
+                    consumer.Listener += new MessageListener(consumer_Listener);
+                    /// Don't know how else to give the system enough time. /// Thread.Sleep(5000); Assert.AreEqual(0, count); Console.WriteLine("Count = " + count); SendPersistentMessage(); Thread.Sleep(5000); Assert.AreEqual(2, count); Console.WriteLine("Count = " + count); consumer.Dispose(); }
+
+                    connection.Stop();
+                }
+            }
+        }
+
+        /// <summary>
+        ///
+        /// </summary>
+        /// <param name="message"></param>
+        private void consumer_Listener(IMessage message)
+        {
+            ++count;
+        }
+    }
+}
\ No newline at end of file

Added: incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/JMSPropertyTest.cs
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/JMSPropertyTest.cs?view=auto&rev=451036
==============================================================================
--- incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/JMSPropertyTest.cs (added)
+++ incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/JMSPropertyTest.cs Thu Sep 28 15:01:04 2006
@@ -0,0 +1,142 @@
+/*
+ * 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 ActiveMQ;
+using NMS;
+using NUnit.Framework;
+using System;
+
+namespace NMS.Test
+{
+    [ TestFixture ]
+    abstract public class NMSPropertyTest : NMSTestSupport
+    {
+        // standard NMS properties
+        string expectedText = "Hey this works!";
+        string correlationID = "abc";
+        ITemporaryQueue replyTo;
+        bool persistent = true;
+        byte priority = 5;
+        String type = "FooType";
+        String groupID = "MyGroup";
+        int groupSeq = 1;
+        
+        // custom properties
+        string customText = "Cheese";
+        bool custom1 = true;
+        byte custom2 = 12;
+        short custom3 = 0x1234;
+        int custom4 = 0x12345678;
+        long custom5 = 0x1234567812345678;
+        char custom6 = 'J';
+        
+        [SetUp]
+        override public void SetUp()
+        {
+            base.SetUp();
+        }
+        
+        [TearDown]
+        override public void TearDown()
+        {
+            base.TearDown();
+        }
+        
+        [ Test ]
+        public override void SendAndSyncReceive()
+        {
+            base.SendAndSyncReceive();
+        }
+        
+        protected override IMessage CreateMessage()
+        {
+            ITextMessage message = Session.CreateTextMessage(expectedText);
+            replyTo = Session.CreateTemporaryQueue();
+            
+            // lets set the headers
+            message.NMSCorrelationID = correlationID;
+            message.NMSReplyTo = replyTo;
+            message.NMSPersistent = persistent;
+            message.NMSPriority = priority;
+            message.NMSType = type;
+            message.Properties["NMSXGroupID"] = groupID;
+            message.Properties["NMSXGroupSeq"] = groupSeq;
+            
+            // lets set the custom headers
+            message.Properties["customText"] = customText;
+            message.Properties["custom1"] = custom1;
+            message.Properties["custom2"] = custom2;
+            message.Properties["custom3"] = custom3;
+            message.Properties["custom4"] = custom4;
+            message.Properties["custom5"] = custom5;
+            message.Properties["custom6"] = custom6;
+            
+            return message;
+        }
+        
+        protected override void AssertValidMessage(IMessage message)
+        {
+            Assert.IsTrue(message is ITextMessage, "Did not receive a ITextMessage!");
+            
+            Console.WriteLine("Received Message: " + message);
+            
+            ITextMessage textMessage = (ITextMessage) message;
+            String text = textMessage.Text;
+            Assert.AreEqual(expectedText, text, "the message text");
+            
+            // compare standard NMS headers
+            Assert.AreEqual(correlationID, message.NMSCorrelationID, "NMSCorrelationID");
+            Assert.AreEqual(replyTo, message.NMSReplyTo, "NMSReplyTo");
+            Assert.AreEqual(persistent, message.NMSPersistent, "NMSPersistent");
+            Assert.AreEqual(priority, message.NMSPriority, "NMSPriority");
+            Assert.AreEqual(type, message.NMSType, "NMSType");
+            Assert.AreEqual(groupID, message.Properties["NMSXGroupID"], "NMSXGroupID");
+            Assert.AreEqual(groupSeq, message.Properties["NMSXGroupSeq"], "NMSXGroupSeq");
+            
+            // compare custom headers
+            Assert.AreEqual(customText, message.Properties["customText"], "customText");
+            Assert.AreEqual(custom1, message.Properties["custom1"], "custom1");
+            Assert.AreEqual(custom2, message.Properties["custom2"], "custom2");
+            Assert.AreEqual(custom3, message.Properties["custom3"], "custom3");
+            Assert.AreEqual(custom4, message.Properties["custom4"], "custom4");
+            // TODO
+            Assert.AreEqual(custom5, message.Properties["custom5"], "custom5");
+            Object value6 = message.Properties["custom6"];
+            Object expected6 = custom6;
+            Console.WriteLine("actual type is: " + value6.GetType() + " value: " + value6);
+            Console.WriteLine("expected type is: " + expected6.GetType() + " value: " + expected6);
+            Assert.AreEqual(custom6, value6, "custom6 which is of type: " + value6.GetType());
+            
+            Assert.AreEqual(custom1, message.Properties.GetBool("custom1"), "custom1");
+            Assert.AreEqual(custom2, message.Properties.GetByte("custom2"), "custom2");
+            Assert.AreEqual(custom3, message.Properties.GetShort("custom3"), "custom3");
+            Assert.AreEqual(custom4, message.Properties.GetInt("custom4"), "custom4");
+            Assert.AreEqual(custom5, message.Properties.GetLong("custom5"), "custom5");
+            //Assert.AreEqual(custom6, message.Properties.GetChar("custom6"), "custom6");
+            
+            // lets now look at some standard NMS headers
+            Console.WriteLine("NMSExpiration: " + message.NMSExpiration);
+            Console.WriteLine("NMSMessageId: " + message.NMSMessageId);
+            Console.WriteLine("NMSRedelivered: " + message.NMSRedelivered);
+            Console.WriteLine("NMSTimestamp: " + message.NMSTimestamp);
+            Console.WriteLine("NMSXDeliveryCount: " + message.Properties["NMSXDeliveryCount"]);
+            Console.WriteLine("NMSXProducerTXID: " + message.Properties["NMSXProducerTXID"]);
+        }
+    }
+}
+
+
+

Added: incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/MapMessageTest.cs
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/MapMessageTest.cs?view=auto&rev=451036
==============================================================================
--- incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/MapMessageTest.cs (added)
+++ incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/MapMessageTest.cs Thu Sep 28 15:01:04 2006
@@ -0,0 +1,126 @@
+/*
+ * 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 NMS;
+using NUnit.Framework;
+using System;
+
+
+
+namespace NMS.Test
+{
+	[ TestFixture ]
+    abstract public class MapMessageTest : NMSTestSupport
+    {	    
+        bool a = true;
+        byte b = 123;
+        char c = 'c';
+        short d = 0x1234;
+        int e = 0x12345678;
+        long f = 0x1234567812345678;
+        string g = "Hello World!";
+		bool h = false;
+        byte i = 0xFF;
+        short j = -0x1234;
+        int k = -0x12345678;
+        long l = -0x1234567812345678;
+        
+		[SetUp]
+        override public void SetUp()
+        {
+			base.SetUp();
+        }
+		
+        [TearDown]
+        override public void TearDown()
+        {
+			base.TearDown();
+        }
+		
+        [ Test ]
+        public override void SendAndSyncReceive()
+        {
+            base.SendAndSyncReceive();
+        }
+		
+        protected override IMessage CreateMessage()
+        {
+            IMapMessage message = Session.CreateMapMessage();
+            
+            message.Body["a"] = a;
+            message.Body["b"] = b;
+            message.Body["c"] = c;
+            message.Body["d"] = d;
+            message.Body["e"] = e;
+            message.Body["f"] = f;
+            message.Body["g"] = g;
+            message.Body["h"] = h;
+            message.Body["i"] = i;
+            message.Body["j"] = j;
+            message.Body["k"] = k;
+            message.Body["l"] = l;
+            
+            return message;
+        }
+        
+        protected override void AssertValidMessage(IMessage message)
+        {
+            Assert.IsTrue(message is IMapMessage, "Did not receive a MapMessage!");
+            IMapMessage mapMessage = (IMapMessage) message;
+            
+            Console.WriteLine("Received MapMessage: " + message);
+            Console.WriteLine("Received Count: " + mapMessage.Body.Count);
+			
+            Assert.AreEqual(ToHex(f), ToHex(mapMessage.Body.GetLong("f")), "map entry: f as hex");
+            
+            // use generic API to access entries
+            Assert.AreEqual(a, mapMessage.Body["a"], "generic map entry: a");
+            Assert.AreEqual(b, mapMessage.Body["b"], "generic map entry: b");
+            Assert.AreEqual(c, mapMessage.Body["c"], "generic map entry: c");
+            Assert.AreEqual(d, mapMessage.Body["d"], "generic map entry: d");
+            Assert.AreEqual(e, mapMessage.Body["e"], "generic map entry: e");
+            Assert.AreEqual(f, mapMessage.Body["f"], "generic map entry: f");
+            Assert.AreEqual(g, mapMessage.Body["g"], "generic map entry: g");
+            Assert.AreEqual(h, mapMessage.Body["h"], "generic map entry: h");
+            Assert.AreEqual(i, mapMessage.Body["i"], "generic map entry: i");
+            Assert.AreEqual(j, mapMessage.Body["j"], "generic map entry: j");
+            Assert.AreEqual(k, mapMessage.Body["k"], "generic map entry: k");
+            Assert.AreEqual(l, mapMessage.Body["l"], "generic map entry: l");
+            
+            // use type safe APIs
+            Assert.AreEqual(a, mapMessage.Body.GetBool("a"), "map entry: a");
+            Assert.AreEqual(b, mapMessage.Body.GetByte("b"), "map entry: b");
+            Assert.AreEqual(c, mapMessage.Body.GetChar("c"), "map entry: c");
+            Assert.AreEqual(d, mapMessage.Body.GetShort("d"), "map entry: d");
+            Assert.AreEqual(e, mapMessage.Body.GetInt("e"), "map entry: e");
+            Assert.AreEqual(f, mapMessage.Body.GetLong("f"), "map entry: f");
+            Assert.AreEqual(g, mapMessage.Body.GetString("g"), "map entry: g");
+            Assert.AreEqual(h, mapMessage.Body.GetBool("h"), "map entry: h");
+            Assert.AreEqual(i, mapMessage.Body.GetByte("i"), "map entry: i");
+            Assert.AreEqual(j, mapMessage.Body.GetShort("j"), "map entry: j");
+            Assert.AreEqual(k, mapMessage.Body.GetInt("k"), "map entry: k");
+            Assert.AreEqual(l, mapMessage.Body.GetLong("l"), "map entry: l");
+			
+        }
+        
+        protected string ToHex(long value)
+        {
+            return String.Format("{0:x}", value);
+        }
+    }
+}
+
+

Added: incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/MessageTest.cs
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/MessageTest.cs?view=auto&rev=451036
==============================================================================
--- incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/MessageTest.cs (added)
+++ incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/MessageTest.cs Thu Sep 28 15:01:04 2006
@@ -0,0 +1,123 @@
+/*
+ * 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 NMS;
+using NUnit.Framework;
+using System;
+
+
+namespace NMS.Test
+{
+	[ TestFixture ]
+	abstract public class MessageTest : NMSTestSupport
+	{
+	    
+		bool a = true;
+        byte b = 123;
+        char c = 'c';
+        short d = 0x1234;
+        int e = 0x12345678;
+        long f = 0x1234567812345678;
+        string g = "Hello World!";
+		bool h = false;
+        byte i = 0xFF;
+        short j = -0x1234;
+        int k = -0x12345678;
+        long l = -0x1234567812345678;
+        
+		[SetUp]
+        override public void SetUp()
+        {
+			base.SetUp();
+        }
+		
+        [TearDown]
+        override public void TearDown()
+        {
+			base.TearDown();
+        }
+		
+        [ Test ]
+        public override void SendAndSyncReceive()
+        {
+            base.SendAndSyncReceive();
+        }
+		
+        protected override IMessage CreateMessage()
+        {
+            IMessage message = Session.CreateMessage();
+            
+            message.Properties["a"] = a;
+            message.Properties["b"] = b;
+            message.Properties["c"] = c;
+            message.Properties["d"] = d;
+            message.Properties["e"] = e;
+            message.Properties["f"] = f;
+            message.Properties["g"] = g;
+            message.Properties["h"] = h;
+            message.Properties["i"] = i;
+            message.Properties["j"] = j;
+            message.Properties["k"] = k;
+            message.Properties["l"] = l;
+            
+            return message;
+        }
+        
+        protected override void AssertValidMessage(IMessage message)
+        {
+            Console.WriteLine("Received message: " + message);
+            Console.WriteLine("Received Count: " + message.Properties.Count);
+			
+            Assert.AreEqual(ToHex(f), ToHex(message.Properties.GetLong("f")), "map entry: f as hex");
+            
+            // use generic API to access entries
+            Assert.AreEqual(a, message.Properties["a"], "generic map entry: a");
+            Assert.AreEqual(b, message.Properties["b"], "generic map entry: b");
+            Assert.AreEqual(c, message.Properties["c"], "generic map entry: c");
+            Assert.AreEqual(d, message.Properties["d"], "generic map entry: d");
+            Assert.AreEqual(e, message.Properties["e"], "generic map entry: e");
+            Assert.AreEqual(f, message.Properties["f"], "generic map entry: f");
+            Assert.AreEqual(g, message.Properties["g"], "generic map entry: g");
+            Assert.AreEqual(h, message.Properties["h"], "generic map entry: h");
+            Assert.AreEqual(i, message.Properties["i"], "generic map entry: i");
+            Assert.AreEqual(j, message.Properties["j"], "generic map entry: j");
+            Assert.AreEqual(k, message.Properties["k"], "generic map entry: k");
+            Assert.AreEqual(l, message.Properties["l"], "generic map entry: l");
+            
+            // 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");
+            
+        }
+        
+        protected string ToHex(long value)
+        {
+            return String.Format("{0:x}", value);
+        }
+		
+	}
+}
+

Added: incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/NMSTestSupport.cs
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/NMSTestSupport.cs?view=auto&rev=451036
==============================================================================
--- incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/NMSTestSupport.cs (added)
+++ incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/NMSTestSupport.cs Thu Sep 28 15:01:04 2006
@@ -0,0 +1,232 @@
+/*
+ * 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 NMS;
+using NUnit.Framework;
+using System;
+
+/// <summary>
+/// useful base class for test cases
+/// </summary>
+
+namespace NMS.Test
+{
+    [ TestFixture ]
+    public abstract class NMSTestSupport
+    {
+
+        // enable/disable logging of message flows
+        protected bool logging = false;
+
+        private IConnectionFactory factory;
+        private IConnection connection;
+        private ISession session;
+        private IDestination destination;
+
+        protected int receiveTimeout = 1000;
+        protected string clientId;
+        protected DestinationType destinationType = DestinationType.Queue;
+        protected AcknowledgementMode acknowledgementMode = AcknowledgementMode.ClientAcknowledge;
+
+        [SetUp]
+        virtual public void SetUp()
+        {
+        }
+
+        [TearDown]
+        virtual public void TearDown()
+        {
+            Disconnect();
+        }
+
+        // Properties
+        public bool Connected
+        {
+            get { return connection!=null; }
+            set { if( value ) Connect(); else Disconnect(); }
+        }
+
+        public IConnectionFactory Factory
+        {
+            get {
+                if( factory == null ) {
+                    factory = CreateConnectionFactory();
+                    Assert.IsNotNull(factory, "no factory created");
+                }
+                return factory;
+            }
+            set { this.factory = value; }
+        }
+
+        public IConnection Connection
+        {
+            get {
+                if( connection == null ) {
+                    Connect();
+                }
+                return connection;
+            }
+            set { this.connection = value; }
+        }
+
+        public ISession Session
+        {
+            get {
+                if( session == null ) {
+                    session = Connection.CreateSession(acknowledgementMode);
+                    Assert.IsNotNull(connection != null, "no session created");
+                }
+                return session;
+            }
+            set { this.session = value; }
+        }
+
+        virtual protected void Connect()
+        {
+            Console.WriteLine("Connectting...");
+            connection = CreateConnection();
+            Assert.IsNotNull(connection, "no connection created");
+            connection.Start();
+            Console.WriteLine("Connected.");
+            Assert.IsNotNull(connection, "no connection created");
+        }
+
+        virtual protected void Disconnect()
+        {
+            if (connection != null)
+            {
+                Console.WriteLine("Disconnecting...");
+                connection.Dispose();
+                connection = null;
+                session=null;
+                Console.WriteLine("Disconnected.");
+            }
+        }
+        
+        virtual protected void Reconnect()
+        {
+            Disconnect();
+            Connect();
+        }
+
+        protected virtual void Drain()
+        {
+            using (ISession session = Connection.CreateSession())
+            {
+                // Tries to consume any messages on the Destination
+                IMessageConsumer consumer = session.CreateConsumer(Destination);
+
+                // Should only need to wait for first message to arrive due to the way
+                // prefetching works.
+                IMessage msg = consumer.Receive(TimeSpan.FromMilliseconds(receiveTimeout));
+                while (msg != null)
+                {
+                    msg = consumer.ReceiveNoWait();
+                }
+            }
+        }
+
+        public virtual void SendAndSyncReceive()
+        {
+            using (ISession session = Connection.CreateSession())
+            {
+
+                IMessageConsumer consumer = session.CreateConsumer(Destination);
+                IMessageProducer producer = session.CreateProducer(Destination);
+
+                IMessage request = CreateMessage();
+                producer.Send(request);
+
+                IMessage message = consumer.Receive(TimeSpan.FromMilliseconds(receiveTimeout));
+                Assert.IsNotNull(message, "No message returned!");
+                AssertValidMessage(message);
+            }
+        }
+
+        abstract protected IConnectionFactory CreateConnectionFactory();
+
+        protected virtual IConnection CreateConnection()
+        {
+            IConnection connection =  Factory.CreateConnection();
+            if( clientId!=null ) {
+                connection.ClientId = clientId;
+            }
+            return connection;
+        }
+
+        protected virtual IMessageProducer CreateProducer()
+        {
+            IMessageProducer producer = Session.CreateProducer(Destination);
+            return producer;
+        }
+
+        protected virtual IMessageConsumer CreateConsumer()
+        {
+            IMessageConsumer consumer = Session.CreateConsumer(Destination);
+            return consumer;
+        }
+        
+        protected virtual IDestination CreateDestination()
+        {
+            if( destinationType == DestinationType.Queue ) {
+                return Session.GetQueue(CreateDestinationName());
+            } else if( destinationType == DestinationType.Topic ) {
+                return Session.GetTopic(CreateDestinationName());
+            } else if( destinationType == DestinationType.TemporaryQueue ) {
+                return Session.CreateTemporaryQueue();
+            } else if( destinationType == DestinationType.TemporaryTopic ) {
+                return Session.CreateTemporaryTopic();
+            } else {
+                throw new Exception("Unknown destination type: "+destinationType);
+            }
+        }
+
+        protected virtual string CreateDestinationName()
+        {
+            return "Test.DotNet." + GetType().Name;
+        }
+        
+        protected virtual IMessage CreateMessage()
+        {
+            return Session.CreateMessage();
+        }
+        
+        protected virtual  void AssertValidMessage(IMessage message)
+        {
+            Assert.IsNotNull(message, "Null Message!");
+        }
+
+
+        public IDestination Destination
+        {
+            get {
+                if (destination == null)
+                {
+                    destination = CreateDestination();
+                    Assert.IsNotNull(destination, "No destination available!");
+                    Console.WriteLine("Using destination: " + destination);
+                }
+                return destination;
+            }
+            set {
+                destination = value;
+            }
+        }
+
+    }
+}
+
+

Added: incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/TemporaryQueueTest.cs
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/TemporaryQueueTest.cs?view=auto&rev=451036
==============================================================================
--- incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/TemporaryQueueTest.cs (added)
+++ incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/TemporaryQueueTest.cs Thu Sep 28 15:01:04 2006
@@ -0,0 +1,92 @@
+/*
+ * 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 NMS;
+using NUnit.Framework;
+using System;
+using System.Threading;
+
+namespace NMS.Test
+{
+    [ TestFixture ]
+    abstract public class TemporaryQueueTest : NMSTestSupport {
+
+        protected Object semaphore = new Object();
+        protected bool received;
+
+        [ SetUp ]
+        override public void SetUp() {
+            base.SetUp();
+        }
+
+        [ TearDown ]
+        override public void TearDown() {
+            base.TearDown();
+        }
+
+        [ Test ]
+        public void TestAsynchronousConsume() {
+            // lets consume to a regular queue
+            IMessageConsumer consumer = CreateConsumer();
+            consumer.Listener += new MessageListener(OnQueueMessage);
+
+            // lets create a temporary queue and a consumer on it
+            ITemporaryQueue tempQ = Session.CreateTemporaryQueue();
+            IMessageConsumer tempQueueConsumer = Session.CreateConsumer(tempQ);
+            tempQueueConsumer.Listener += new MessageListener(OnTempQueueMessage);
+
+            // Send message to queue which has a listener to reply to the temporary queue
+            IMessageProducer producer = CreateProducer();
+            
+            IMessage request = CreateMessage();
+            request.NMSCorrelationID = "abc";
+            request.NMSReplyTo = tempQ;
+            request.NMSPersistent = false;
+            producer.Send(request);
+
+            // now lets wait for the message to arrive on the temporary queue
+            WaitForMessageToArrive();
+        }
+
+        protected void OnQueueMessage(IMessage message) {
+			Console.WriteLine("First message received: " + message + " so about to reply to temporary queue");
+
+            ITextMessage response = Session.CreateTextMessage("this is a response!!");
+            response.NMSCorrelationID = message.NMSCorrelationID;
+
+            IMessageProducer producerTempQ = Session.CreateProducer(message.NMSReplyTo);
+            //Write msg to temp q.
+            producerTempQ.Send(response); 
+        }
+        
+        protected void OnTempQueueMessage(IMessage message) {
+            Console.WriteLine("Received message on temporary queue: " + message);
+            lock (semaphore) {
+                received = true;
+                Monitor.PulseAll(semaphore);
+            }
+        }
+
+        protected void WaitForMessageToArrive() {
+            lock (semaphore) {
+                if (!received) {
+                    Monitor.Wait(semaphore, receiveTimeout);
+                }
+                Assert.AreEqual(true, received, "Should have received a message by now!");
+            }
+        }
+    }
+}

Added: incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/TextMessage.cs
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/TextMessage.cs?view=auto&rev=451036
==============================================================================
--- incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/TextMessage.cs (added)
+++ incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/TextMessage.cs Thu Sep 28 15:01:04 2006
@@ -0,0 +1,59 @@
+/*
+ * 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 NUnit.Framework;
+
+namespace NMS.Test
+{
+    [TestFixture]
+    public abstract class TextMessage : NMSTestSupport
+    {
+        private string expected = "Hello World!";
+
+        [SetUp]
+        public override void SetUp()
+        {
+            base.SetUp();
+        }
+
+        [TearDown]
+        public override void TearDown()
+        {
+            base.TearDown();
+        }
+
+        [Test]
+        public override void SendAndSyncReceive()
+        {
+            base.SendAndSyncReceive();
+        }
+
+        protected override IMessage CreateMessage()
+        {
+            IMessage request = Session.CreateTextMessage(expected);
+            return request;
+        }
+
+        protected override void AssertValidMessage(IMessage message)
+        {
+            ITextMessage textMessage = (ITextMessage) message;
+            String text = textMessage.Text;
+            Console.WriteLine("Received message with text: " + text);
+            Assert.AreEqual(expected, text, "the message text");
+        }
+    }
+}
\ No newline at end of file

Added: incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/TransactionTest.cs
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/TransactionTest.cs?view=auto&rev=451036
==============================================================================
--- incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/TransactionTest.cs (added)
+++ incubator/activemq/activemq-dotnet/trunk/src/test/csharp/NMS/Test/TransactionTest.cs Thu Sep 28 15:01:04 2006
@@ -0,0 +1,257 @@
+/*
+ * 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.Collections;
+
+
+namespace NMS.Test
+{
+	[TestFixture]
+    abstract public class TransactionTest : NMSTestSupport
+    {
+        private static int destinationCounter;
+        
+        IMessageProducer producer;
+        IMessageConsumer consumer;
+        
+        [SetUp]
+		override public void SetUp()
+        {
+            base.SetUp();
+			acknowledgementMode = AcknowledgementMode.Transactional;
+            Drain();
+            consumer = Session.CreateConsumer(Destination);
+            producer = Session.CreateProducer(Destination);
+        }
+		
+        [TearDown]
+        override public void TearDown()
+        {
+			base.TearDown();
+        }
+		
+		
+        [Test]
+        public void TestSendRollback()
+        {
+            IMessage[] outbound = new IMessage[]{
+                Session.CreateTextMessage("First Message"),
+                Session.CreateTextMessage("Second Message")
+            };
+            
+            //sends a message
+            producer.Send(outbound[0]);
+            Session.Commit();
+            
+            //sends a message that gets rollbacked
+            producer.Send(Session.CreateTextMessage("I'm going to get rolled back."));
+            Session.Rollback();
+            
+            //sends a message
+            producer.Send(outbound[1]);
+            Session.Commit();
+            
+            //receives the first message
+            ArrayList messages = new ArrayList();
+            Console.WriteLine("About to consume message 1");
+            IMessage message = consumer.Receive(TimeSpan.FromMilliseconds(1000));
+            messages.Add(message);
+            Console.WriteLine("Received: " + message);
+            
+            //receives the second message
+            Console.WriteLine("About to consume message 2");
+            message = consumer.Receive(TimeSpan.FromMilliseconds(4000));
+            messages.Add(message);
+            Console.WriteLine("Received: " + message);
+            
+            //validates that the rollbacked was not consumed
+            Session.Commit();
+            IMessage[] inbound = new IMessage[messages.Count];
+            messages.CopyTo(inbound);
+            AssertTextMessagesEqual("Rollback did not work.", outbound, inbound);
+        }
+        
+        [Test]
+        public void TestSendSessionClose()
+        {
+            IMessage[] outbound = new IMessage[]{
+                Session.CreateTextMessage("First Message"),
+                Session.CreateTextMessage("Second Message")
+            };
+            
+            //sends a message
+            producer.Send(outbound[0]);
+            Session.Commit();
+            
+            //sends a message that gets rollbacked
+            producer.Send(Session.CreateTextMessage("I'm going to get rolled back."));
+            consumer.Dispose();
+            Session.Dispose();
+            
+            Reconnect();
+            
+            //sends a message
+            producer.Send(outbound[1]);
+            Session.Commit();
+            
+            //receives the first message
+            ArrayList messages = new ArrayList();
+            Console.WriteLine("About to consume message 1");
+            IMessage message = consumer.Receive(TimeSpan.FromMilliseconds(1000));
+            messages.Add(message);
+            Console.WriteLine("Received: " + message);
+            
+            //receives the second message
+            Console.WriteLine("About to consume message 2");
+            message = consumer.Receive(TimeSpan.FromMilliseconds(4000));
+            messages.Add(message);
+            Console.WriteLine("Received: " + message);
+            
+            //validates that the rollbacked was not consumed
+            Session.Commit();
+            IMessage[] inbound = new IMessage[messages.Count];
+            messages.CopyTo(inbound);
+            AssertTextMessagesEqual("Rollback did not work.", outbound, inbound);
+        }
+        
+        [Test]
+        public void TestReceiveRollback()
+        {
+            IMessage[] outbound = new IMessage[]{
+                Session.CreateTextMessage("First Message"),
+                Session.CreateTextMessage("Second Message")
+            };
+            
+            //sent both messages
+            producer.Send(outbound[0]);
+            producer.Send(outbound[1]);
+            Session.Commit();
+            
+            Console.WriteLine("Sent 0: " + outbound[0]);
+            Console.WriteLine("Sent 1: " + outbound[1]);
+            
+            ArrayList messages = new ArrayList();
+            IMessage message = consumer.Receive(TimeSpan.FromMilliseconds(1000));
+            messages.Add(message);
+            Assert.AreEqual(outbound[0], message);
+            Session.Commit();
+            
+            // rollback so we can get that last message again.
+            message = consumer.Receive(TimeSpan.FromMilliseconds(1000));
+            Assert.IsNotNull(message);
+            Assert.AreEqual(outbound[1], message);
+            Session.Rollback();
+            
+            // Consume again.. the previous message should
+            // get redelivered.
+            message = consumer.Receive(TimeSpan.FromMilliseconds(5000));
+            Assert.IsNotNull(message, "Should have re-received the message again!");
+            messages.Add(message);
+            Session.Commit();
+            
+            IMessage[] inbound = new IMessage[messages.Count];
+            messages.CopyTo(inbound);
+            AssertTextMessagesEqual("Rollback did not work", outbound, inbound);
+        }
+        
+        
+        [Test]
+        public void TestReceiveTwoThenRollback()
+        {
+            IMessage[] outbound = new IMessage[]{
+                Session.CreateTextMessage("First Message"),
+                Session.CreateTextMessage("Second Message")
+            };
+            
+            producer.Send(outbound[0]);
+            producer.Send(outbound[1]);
+            Session.Commit();
+            
+            Console.WriteLine("Sent 0: " + outbound[0]);
+            Console.WriteLine("Sent 1: " + outbound[1]);
+            
+            ArrayList messages = new ArrayList();
+            IMessage message = consumer.Receive(TimeSpan.FromMilliseconds(1000));
+            AssertTextMessageEqual("first mesage received before rollback", outbound[0], message);
+            
+            message = consumer.Receive(TimeSpan.FromMilliseconds(1000));
+            Assert.IsNotNull(message);
+            AssertTextMessageEqual("second message received before rollback", outbound[1], message);
+            Session.Rollback();
+            
+            // Consume again.. the previous message should
+            // get redelivered.
+            message = consumer.Receive(TimeSpan.FromMilliseconds(5000));
+            Assert.IsNotNull(message, "Should have re-received the first message again!");
+            messages.Add(message);
+            AssertTextMessageEqual("first message received after rollback", outbound[0], message);
+            
+            message = consumer.Receive(TimeSpan.FromMilliseconds(5000));
+            Assert.IsNotNull(message, "Should have re-received the second message again!");
+            messages.Add(message);
+            AssertTextMessageEqual("second message received after rollback", outbound[1], message);
+            
+            Assert.IsNull(consumer.ReceiveNoWait());
+            Session.Commit();
+            
+            IMessage[] inbound = new IMessage[messages.Count];
+            messages.CopyTo(inbound);
+            AssertTextMessagesEqual("Rollback did not work", outbound, inbound);
+        }
+        
+        protected override string CreateDestinationName()
+        {
+            // TODO - how can we get the test name?
+            return base.CreateDestinationName() + (++destinationCounter);
+        }
+        
+        protected void AssertTextMessagesEqual(String message, IMessage[] expected, IMessage[] actual)
+        {
+            Assert.AreEqual(expected.Length, actual.Length, "Incorrect number of messages received");
+            
+            for (int i = 0; i < expected.Length; i++)
+            {
+                AssertTextMessageEqual(message + ". Index: " + i, expected[i], actual[i]);
+            }
+        }
+        
+        protected void AssertTextMessageEqual(String message, IMessage expected, IMessage actual)
+        {
+            Assert.IsTrue(expected is ITextMessage, "expected object not a text message");
+            Assert.IsTrue(actual is ITextMessage, "actual object not a text message");
+            
+            String expectedText = ((ITextMessage) expected).Text;
+            String actualText = ((ITextMessage) actual).Text;
+            
+            Assert.AreEqual(expectedText, actualText, message);
+        }
+		
+		/// <summary>
+		/// Method Reconnect
+		/// </summary>
+		protected override void Reconnect()
+		{
+			base.Reconnect();
+            consumer = Session.CreateConsumer(Destination);
+            producer = Session.CreateProducer(Destination);
+		}
+		
+    }
+}
+
+

Added: incubator/activemq/activemq-dotnet/trunk/vs2005-activemq-test.csproj
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-dotnet/trunk/vs2005-activemq-test.csproj?view=auto&rev=451036
==============================================================================
--- incubator/activemq/activemq-dotnet/trunk/vs2005-activemq-test.csproj (added)
+++ incubator/activemq/activemq-dotnet/trunk/vs2005-activemq-test.csproj Thu Sep 28 15:01:04 2006
@@ -0,0 +1,80 @@
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProductVersion>8.0.50727</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{EB943C69-2C9B-45E7-B95B-FB916E7057ED}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <RootNamespace>ActiveMQ</RootNamespace>
+    <AssemblyName>activemq-test</AssemblyName>
+    <WarningLevel>4</WarningLevel>
+    <StartupObject>
+    </StartupObject>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <AllowUnsafeBlocks>false</AllowUnsafeBlocks>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugSymbols>false</DebugSymbols>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <AllowUnsafeBlocks>false</AllowUnsafeBlocks>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="nunit.framework" />
+    <Reference Include="System" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="src\test\csharp\ActiveMQ\BadConsumeTest.cs" />
+    <Compile Include="src\test\csharp\ActiveMQ\BytesMessageTest.cs" />
+    <Compile Include="src\test\csharp\ActiveMQ\Commands\CommandTest.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="src\test\csharp\ActiveMQ\ConsumerTest.cs" />
+    <Compile Include="src\test\csharp\ActiveMQ\DurableTest.cs" />
+    <Compile Include="src\test\csharp\ActiveMQ\JMSPropertyTest.cs" />
+    <Compile Include="src\test\csharp\ActiveMQ\MapMessageTest.cs" />
+    <Compile Include="src\test\csharp\ActiveMQ\OpenWire\BooleanStreamTest.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="src\test\csharp\ActiveMQ\OpenWire\EndianTest.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="src\test\csharp\ActiveMQ\OpenWire\PrimitiveMapTest.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="src\test\csharp\ActiveMQ\TemporaryQueueTest.cs" />
+    <Compile Include="src\test\csharp\ActiveMQ\TestMain.cs">
+      <SubType>Code</SubType>
+    </Compile>
+    <Compile Include="src\test\csharp\ActiveMQ\TextMessage.cs" />
+    <Compile Include="src\test\csharp\ActiveMQ\TransactionTest.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="vs2005-activemq.csproj">
+      <Project>{08321F42-4B3D-4815-B592-95962BAC3B9F}</Project>
+      <Name>vs2005-activemq</Name>
+    </ProjectReference>
+    <ProjectReference Include="vs2005-nms-test.csproj">
+      <Project>{2F3ABCF5-EE87-43B1-9DE7-0548FD6A4E52}</Project>
+      <Name>vs2005-nms-test</Name>
+    </ProjectReference>
+    <ProjectReference Include="vs2005-nms.csproj">
+      <Project>{300C1716-0674-4D01-8F5D-151E59A504FE}</Project>
+      <Name>vs2005-nms</Name>
+    </ProjectReference>
+  </ItemGroup>
+  <ItemGroup>
+    <Folder Include="src\test\csharp\ActiveMQ\OpenWire\V1\" />
+  </ItemGroup>
+  <Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
+</Project>
\ No newline at end of file



Mime
View raw message