Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 37914 invoked from network); 6 Jan 2010 14:36:02 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 6 Jan 2010 14:36:02 -0000 Received: (qmail 71219 invoked by uid 500); 6 Jan 2010 14:36:02 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 71175 invoked by uid 500); 6 Jan 2010 14:36:02 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 71166 invoked by uid 99); 6 Jan 2010 14:36:02 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Jan 2010 14:36:02 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Jan 2010 14:35:57 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 5C7A823889BB; Wed, 6 Jan 2010 14:35:35 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r896454 - in /activemq/activemq-dotnet/Apache.NMS.Stomp/trunk: ./ src/test/csharp/ Date: Wed, 06 Jan 2010 14:35:34 -0000 To: commits@activemq.apache.org From: tabish@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100106143535.5C7A823889BB@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: tabish Date: Wed Jan 6 14:35:34 2010 New Revision: 896454 URL: http://svn.apache.org/viewvc?rev=896454&view=rev Log: Add some initial tests ported from the Apache.NMS project and customized to work within Stomp's limitations. Added: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/AsyncConsumeTest.cs (with props) activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/BadConsumeTest.cs (with props) activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/BytesMessageTest.cs (with props) activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/ConnectionTest.cs (with props) activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/MessageTest.cs (with props) activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/ProducerTest.cs (with props) activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/TextMessageTest.cs (with props) Modified: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/Apache.NMS.Stomp.Test.nunit activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/vs2008-stomp-test.csproj Modified: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/Apache.NMS.Stomp.Test.nunit URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/Apache.NMS.Stomp.Test.nunit?rev=896454&r1=896453&r2=896454&view=diff ============================================================================== --- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/Apache.NMS.Stomp.Test.nunit (original) +++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/Apache.NMS.Stomp.Test.nunit Wed Jan 6 14:35:34 2010 @@ -2,6 +2,5 @@ - Added: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/AsyncConsumeTest.cs URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/AsyncConsumeTest.cs?rev=896454&view=auto ============================================================================== --- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/AsyncConsumeTest.cs (added) +++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/AsyncConsumeTest.cs Wed Jan 6 14:35:34 2010 @@ -0,0 +1,258 @@ +/* + * 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; +using Apache.NMS.Util; +using Apache.NMS.Test; +using NUnit.Framework; +using NUnit.Framework.Extensions; + +namespace Apache.NMS.Stomp.Test +{ + [TestFixture] + public class AsyncConsumeTest : NMSTestSupport + { + protected static string DESTINATION_NAME = "AsyncConsumeDestination"; + protected static string TEST_CLIENT_ID = "AsyncConsumeClientId"; + protected static string RESPONSE_CLIENT_ID = "AsyncConsumeResponseClientId"; + protected AutoResetEvent semaphore; + protected bool received; + protected IMessage receivedMsg; + protected int postfix; + + [SetUp] + public override void SetUp() + { + base.SetUp(); + semaphore = new AutoResetEvent(false); + received = false; + receivedMsg = null; + + Random rand = new Random(); + this.postfix = rand.Next(); + } + + [TearDown] + public override void TearDown() + { + receivedMsg = null; + base.TearDown(); + } + + [RowTest] + [Row(MsgDeliveryMode.Persistent)] + [Row(MsgDeliveryMode.NonPersistent)] + public void TestAsynchronousConsume(MsgDeliveryMode deliveryMode) + { + using(IConnection connection = CreateConnection(TEST_CLIENT_ID + ":" + this.postfix)) + { + connection.Start(); + using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge)) + { + IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME); + using(IMessageConsumer consumer = session.CreateConsumer(destination)) + using(IMessageProducer producer = session.CreateProducer(destination)) + { + producer.DeliveryMode = deliveryMode; + producer.RequestTimeout = receiveTimeout; + consumer.Listener += new MessageListener(OnMessage); + + IMessage request = session.CreateMessage(); + request.NMSCorrelationID = "AsyncConsume"; + request.NMSType = "Test"; + producer.Send(request); + + WaitForMessageToArrive(); + Assert.AreEqual(request.NMSCorrelationID, receivedMsg.NMSCorrelationID, "Invalid correlation ID."); + } + } + } + } + + [RowTest] + [Row(MsgDeliveryMode.Persistent)] + [Row(MsgDeliveryMode.NonPersistent)] + public void TestCreateConsumerAfterSend(MsgDeliveryMode deliveryMode) + { + using(IConnection connection = CreateConnection(TEST_CLIENT_ID + ":" + this.postfix)) + { + connection.Start(); + using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge)) + { + IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME); + using(IMessageProducer producer = session.CreateProducer(destination)) + { + producer.DeliveryMode = deliveryMode; + producer.RequestTimeout = receiveTimeout; + + IMessage request = session.CreateMessage(); + request.NMSCorrelationID = "AsyncConsumeAfterSend"; + request.NMSType = "Test"; + producer.Send(request); + + using(IMessageConsumer consumer = session.CreateConsumer(destination)) + { + consumer.Listener += new MessageListener(OnMessage); + WaitForMessageToArrive(); + Assert.AreEqual(request.NMSCorrelationID, receivedMsg.NMSCorrelationID, "Invalid correlation ID."); + } + } + } + } + } + + [RowTest] + [Row(MsgDeliveryMode.Persistent)] + [Row(MsgDeliveryMode.NonPersistent)] + public void TestCreateConsumerBeforeSendAddListenerAfterSend(MsgDeliveryMode deliveryMode) + { + using(IConnection connection = CreateConnection(TEST_CLIENT_ID + ":" + this.postfix)) + { + connection.Start(); + using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge)) + { + IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME); + using(IMessageConsumer consumer = session.CreateConsumer(destination)) + using(IMessageProducer producer = session.CreateProducer(destination)) + { + producer.DeliveryMode = deliveryMode; + producer.RequestTimeout = receiveTimeout; + + IMessage request = session.CreateMessage(); + request.NMSCorrelationID = "AsyncConsumeAfterSendLateListener"; + request.NMSType = "Test"; + producer.Send(request); + + // now lets add the listener + consumer.Listener += new MessageListener(OnMessage); + WaitForMessageToArrive(); + Assert.AreEqual(request.NMSCorrelationID, receivedMsg.NMSCorrelationID, "Invalid correlation ID."); + } + } + } + } + + [RowTest] + [Row(MsgDeliveryMode.Persistent)] + [Row(MsgDeliveryMode.NonPersistent)] + public void TestAsynchronousTextMessageConsume(MsgDeliveryMode deliveryMode) + { + using(IConnection connection = CreateConnection(TEST_CLIENT_ID + ":" + this.postfix)) + { + connection.Start(); + using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge)) + { + IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME); + using(IMessageConsumer consumer = session.CreateConsumer(destination)) + { + consumer.Listener += new MessageListener(OnMessage); + using(IMessageProducer producer = session.CreateProducer(destination)) + { + producer.DeliveryMode = deliveryMode; + producer.RequestTimeout = receiveTimeout; + + ITextMessage request = session.CreateTextMessage("Hello, World!"); + request.NMSCorrelationID = "AsyncConsumeTextMessage"; + request.Properties["NMSXGroupID"] = "cheese"; + request.Properties["myHeader"] = "James"; + + producer.Send(request); + + WaitForMessageToArrive(); + Assert.AreEqual(request.NMSCorrelationID, receivedMsg.NMSCorrelationID, "Invalid correlation ID."); + Assert.AreEqual(request.Properties["NMSXGroupID"], receivedMsg.Properties["NMSXGroupID"], "Invalid NMSXGroupID."); + Assert.AreEqual(request.Properties["myHeader"], receivedMsg.Properties["myHeader"], "Invalid myHeader."); + Assert.AreEqual(request.Text, ((ITextMessage) receivedMsg).Text, "Invalid text body."); + } + } + } + } + } + + [RowTest] + [Row(MsgDeliveryMode.Persistent)] + [Row(MsgDeliveryMode.NonPersistent)] + public void TestTemporaryQueueAsynchronousConsume(MsgDeliveryMode deliveryMode) + { + using(IConnection connection = CreateConnection(TEST_CLIENT_ID + ":" + this.postfix)) + { + connection.Start(); + using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge)) + { + IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME); + ITemporaryQueue tempReplyDestination = session.CreateTemporaryQueue(); + + using(IMessageConsumer consumer = session.CreateConsumer(destination)) + using(IMessageConsumer tempConsumer = session.CreateConsumer(tempReplyDestination)) + using(IMessageProducer producer = session.CreateProducer(destination)) + { + producer.DeliveryMode = deliveryMode; + producer.RequestTimeout = receiveTimeout; + tempConsumer.Listener += new MessageListener(OnMessage); + consumer.Listener += new MessageListener(OnQueueMessage); + + IMessage request = session.CreateMessage(); + request.NMSCorrelationID = "TemqQueueAsyncConsume"; + request.NMSType = "Test"; + request.NMSReplyTo = tempReplyDestination; + producer.Send(request); + + WaitForMessageToArrive(); + Assert.AreEqual("TempQueueAsyncResponse", receivedMsg.NMSCorrelationID, "Invalid correlation ID."); + } + } + } + } + + protected void OnQueueMessage(IMessage message) + { + Assert.AreEqual("TemqQueueAsyncConsume", message.NMSCorrelationID, "Invalid correlation ID."); + using(IConnection connection = CreateConnection(RESPONSE_CLIENT_ID + ":" + this.postfix)) + { + connection.Start(); + using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge)) + { + using(IMessageProducer producer = session.CreateProducer(message.NMSReplyTo)) + { + producer.DeliveryMode = message.NMSDeliveryMode; + producer.RequestTimeout = receiveTimeout; + + ITextMessage response = session.CreateTextMessage("Asynchronous Response Message Text"); + response.NMSCorrelationID = "TempQueueAsyncResponse"; + response.NMSType = message.NMSType; + producer.Send(response); + } + } + } + } + + protected void OnMessage(IMessage message) + { + receivedMsg = message; + received = true; + semaphore.Set(); + } + + protected void WaitForMessageToArrive() + { + semaphore.WaitOne((int) receiveTimeout.TotalMilliseconds, true); + Assert.IsTrue(received, "Should have received a message by now!"); + } + } +} Propchange: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/AsyncConsumeTest.cs ------------------------------------------------------------------------------ svn:eol-style = native Propchange: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/AsyncConsumeTest.cs ------------------------------------------------------------------------------ svn:executable = * Added: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/BadConsumeTest.cs URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/BadConsumeTest.cs?rev=896454&view=auto ============================================================================== --- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/BadConsumeTest.cs (added) +++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/BadConsumeTest.cs Wed Jan 6 14:35:34 2010 @@ -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 System; +using NUnit.Framework; +using Apache.NMS.Test; + +namespace Apache.NMS.Stomp.Test +{ + [TestFixture] + public class BadConsumeTest : NMSTestSupport + { + protected static string TEST_CLIENT_ID = "BadConsumeTestClientId"; + protected IConnection connection; + protected ISession session; + + [SetUp] + public override void SetUp() + { + connection = CreateConnection(TEST_CLIENT_ID); + connection.Start(); + session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge); + } + + [TearDown] + public override void TearDown() + { + if(null != session) + { + session.Dispose(); + session = null; + } + + if(null != connection) + { + connection.Dispose(); + connection = null; + } + } + + [Test] + [ExpectedException(Handler="ExceptionValidationCheck")] + public void TestBadConsumerException() + { + session.CreateConsumer(null); + } + + public void ExceptionValidationCheck(Exception ex) + { + Assert.IsNotNull(ex as NMSException, "Invalid exception was thrown."); + } + } +} Propchange: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/BadConsumeTest.cs ------------------------------------------------------------------------------ svn:eol-style = native Propchange: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/BadConsumeTest.cs ------------------------------------------------------------------------------ svn:executable = * Added: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/BytesMessageTest.cs URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/BytesMessageTest.cs?rev=896454&view=auto ============================================================================== --- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/BytesMessageTest.cs (added) +++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/BytesMessageTest.cs Wed Jan 6 14:35:34 2010 @@ -0,0 +1,157 @@ +/* + * 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.Test; +using Apache.NMS.Util; +using NUnit.Framework; +using NUnit.Framework.Extensions; + +namespace Apache.NMS.Stomp.Test +{ + [TestFixture] + public class BytesMessageTest : NMSTestSupport + { + protected static string DESTINATION_NAME = "BytesMessageDestination"; + protected static string TEST_CLIENT_ID = "BytesMessageClientId"; + protected byte[] msgContent = {1, 2, 3, 4, 5, 6, 7, 8}; + protected int postfix; + + [SetUp] + public override void SetUp() + { + this.postfix = new Random().Next(); + } + + [TearDown] + public override void TearDown() + { + } + + [RowTest] + [Row(MsgDeliveryMode.Persistent)] + [Row(MsgDeliveryMode.NonPersistent)] + public void SendReceiveBytesMessage(MsgDeliveryMode deliveryMode) + { + using(IConnection connection = CreateConnection(TEST_CLIENT_ID + ":" + this.postfix)) + { + connection.Start(); + using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge)) + { + IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME); + using(IMessageConsumer consumer = session.CreateConsumer(destination)) + using(IMessageProducer producer = session.CreateProducer(destination)) + { + producer.DeliveryMode = deliveryMode; + producer.RequestTimeout = receiveTimeout; + IMessage request = session.CreateBytesMessage(msgContent); + producer.Send(request); + + IMessage message = consumer.Receive(receiveTimeout); + AssertBytesMessageEqual(request, message); + AssertMessageIsReadOnly(message); + Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match"); + + } + } + } + } + + [RowTest] + [Row(MsgDeliveryMode.Persistent)] + [Row(MsgDeliveryMode.NonPersistent)] + public void SendReceiveBytesMessageContentTest(MsgDeliveryMode deliveryMode) + { + using(IConnection connection = CreateConnection(TEST_CLIENT_ID + ":" + this.postfix)) + { + connection.Start(); + using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge)) + { + IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME); + using(IMessageConsumer consumer = session.CreateConsumer(destination)) + using(IMessageProducer producer = session.CreateProducer(destination)) + { + producer.DeliveryMode = deliveryMode; + producer.RequestTimeout = receiveTimeout; + IBytesMessage request = session.CreateBytesMessage(); + + request.WriteBoolean(true); + request.WriteByte((byte) 1); + request.WriteBytes(new byte[1]); + request.WriteBytes(new byte[3], 0, 2); + request.WriteChar('a'); + request.WriteDouble(1.5); + request.WriteSingle((float) 1.5); + request.WriteInt32(1); + request.WriteInt64(1); + request.WriteObject("stringobj"); + request.WriteInt16((short) 1); + request.WriteString("utfstring"); + + producer.Send(request); + + IMessage message = consumer.Receive(receiveTimeout); + AssertBytesMessageEqual(request, message); + AssertMessageIsReadOnly(message); + Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match"); + + } + } + } + } + + protected void AssertMessageIsReadOnly(IMessage message) + { + IBytesMessage theMessage = message as IBytesMessage; + Assert.IsNotNull(theMessage); + try + { + theMessage.WriteBoolean(true); + theMessage.WriteByte((byte) 1); + theMessage.WriteBytes(new byte[1]); + theMessage.WriteBytes(new byte[3], 0, 2); + theMessage.WriteChar('a'); + theMessage.WriteDouble(1.5); + theMessage.WriteSingle((float) 1.5); + theMessage.WriteInt32(1); + theMessage.WriteInt64(1); + theMessage.WriteObject("stringobj"); + theMessage.WriteInt16((short) 1); + theMessage.WriteString("utfstring"); + Assert.Fail("Message should not have been Writable"); + } + catch(MessageNotWriteableException) + { + } + } + + /// + /// Assert that two messages are IBytesMessages and their contents are equal. + /// + /// + /// + protected void AssertBytesMessageEqual(IMessage expected, IMessage actual) + { + IBytesMessage expectedBytesMsg = expected as IBytesMessage; + expectedBytesMsg.Reset(); + Assert.IsNotNull(expectedBytesMsg, "'expected' message not a bytes message"); + IBytesMessage actualBytesMsg = actual as IBytesMessage; + Assert.IsNotNull(actualBytesMsg, "'actual' message not a bytes message"); + Assert.AreEqual(expectedBytesMsg.Content, actualBytesMsg.Content, "Bytes message contents do not match."); + } + } +} Propchange: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/BytesMessageTest.cs ------------------------------------------------------------------------------ svn:eol-style = native Propchange: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/BytesMessageTest.cs ------------------------------------------------------------------------------ svn:executable = * Added: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/ConnectionTest.cs URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/ConnectionTest.cs?rev=896454&view=auto ============================================================================== --- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/ConnectionTest.cs (added) +++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/ConnectionTest.cs Wed Jan 6 14:35:34 2010 @@ -0,0 +1,195 @@ +/* + * 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; +using NUnit.Framework.Extensions; +using Apache.NMS.Test; + +namespace Apache.NMS.Stomp.Test +{ + [TestFixture] + public class ConnectionTest : NMSTestSupport + { + protected static string TEST_CLIENT_ID = "ConnectionTestClientId"; + protected int postfix; + + IConnection startedConnection = null; + IConnection stoppedConnection = null; + + [SetUp] + public override void SetUp() + { + base.SetUp(); + + startedConnection = CreateConnection(null); + startedConnection.Start(); + stoppedConnection = CreateConnection(null); + + this.postfix = new Random().Next(); + } + + [TearDown] + public override void TearDown() + { + startedConnection.Close(); + stoppedConnection.Close(); + + base.TearDown(); + } + + /// + /// Verify that it is possible to create multiple connections to the broker. + /// There was a bug in the connection factory which set the clientId member which made + /// it impossible to create an additional connection. + /// + [Test] + public void TwoConnections() + { + using(IConnection connection1 = CreateConnection(null)) + { + connection1.Start(); + using(IConnection connection2 = CreateConnection(null)) + { + // with the bug present we'll get an exception in connection2.start() + connection2.Start(); + } + } + } + + [RowTest] + [Row(true)] + [Row(false)] + public void CreateAndDisposeWithConsumer(bool disposeConsumer) + { + using(IConnection connection = CreateConnection("DisposalTestConnection" + ":" + this.postfix)) + { + connection.Start(); + + using(ISession session = connection.CreateSession()) + { + IQueue queue = session.GetQueue("DisposalTestQueue"); + IMessageConsumer consumer = session.CreateConsumer(queue); + + connection.Stop(); + if(disposeConsumer) + { + consumer.Dispose(); + } + } + } + } + + [RowTest] + [Row(true)] + [Row(false)] + public void CreateAndDisposeWithProducer(bool disposeProducer) + { + using(IConnection connection = CreateConnection("DisposalTestConnection" + ":" + this.postfix)) + { + connection.Start(); + + using(ISession session = connection.CreateSession()) + { + IQueue queue = session.GetQueue("DisposalTestQueue"); + IMessageProducer producer = session.CreateProducer(queue); + + connection.Stop(); + if(disposeProducer) + { + producer.Dispose(); + } + } + } + } + + [RowTest] + [Row(MsgDeliveryMode.Persistent, DestinationType.Queue)] + [Row(MsgDeliveryMode.Persistent, DestinationType.Topic)] + [Row(MsgDeliveryMode.NonPersistent, DestinationType.Queue)] + [Row(MsgDeliveryMode.NonPersistent, DestinationType.Topic)] + public void TestStartAfterSend(MsgDeliveryMode deliveryMode, DestinationType destinationType) + { + using(IConnection connection = CreateConnection(TEST_CLIENT_ID + ":" + this.postfix)) + { + ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge); + IDestination destination = CreateDestination(session, destinationType); + IMessageConsumer consumer = session.CreateConsumer(destination); + + // Send the messages + SendMessages(session, destination, deliveryMode, 1); + + // Start the conncection after the message was sent. + connection.Start(); + + // Make sure only 1 message was delivered. + Assert.IsNotNull(consumer.Receive(TimeSpan.FromMilliseconds(1000))); + Assert.IsNull(consumer.ReceiveNoWait()); + } + } + + /// + /// Tests if the consumer receives the messages that were sent before the + /// connection was started. + /// + [Test] + public void TestStoppedConsumerHoldsMessagesTillStarted() + { + ISession startedSession = startedConnection.CreateSession(AcknowledgementMode.AutoAcknowledge); + ISession stoppedSession = stoppedConnection.CreateSession(AcknowledgementMode.AutoAcknowledge); + + // Setup the consumers. + ITopic topic = startedSession.GetTopic("ConnectionTestTopic"); + IMessageConsumer startedConsumer = startedSession.CreateConsumer(topic); + IMessageConsumer stoppedConsumer = stoppedSession.CreateConsumer(topic); + + // Send the message. + IMessageProducer producer = startedSession.CreateProducer(topic); + ITextMessage message = startedSession.CreateTextMessage("Hello"); + producer.Send(message); + + // Test the assertions. + IMessage m = startedConsumer.Receive(TimeSpan.FromMilliseconds(1000)); + Assert.IsNotNull(m); + + m = stoppedConsumer.Receive(TimeSpan.FromMilliseconds(1000)); + Assert.IsNull(m); + + stoppedConnection.Start(); + m = stoppedConsumer.Receive(TimeSpan.FromMilliseconds(5000)); + Assert.IsNotNull(m); + + startedSession.Close(); + stoppedSession.Close(); + } + + /// + /// Tests if the consumer is able to receive messages eveb when the + /// connecction restarts multiple times. + /// + [Test] + public void TestMultipleConnectionStops() + { + TestStoppedConsumerHoldsMessagesTillStarted(); + stoppedConnection.Stop(); + TestStoppedConsumerHoldsMessagesTillStarted(); + stoppedConnection.Stop(); + TestStoppedConsumerHoldsMessagesTillStarted(); + } + } +} Propchange: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/ConnectionTest.cs ------------------------------------------------------------------------------ svn:eol-style = native Propchange: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/ConnectionTest.cs ------------------------------------------------------------------------------ svn:executable = * Added: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/MessageTest.cs URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/MessageTest.cs?rev=896454&view=auto ============================================================================== --- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/MessageTest.cs (added) +++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/MessageTest.cs Wed Jan 6 14:35:34 2010 @@ -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 System; +using NUnit.Framework; +using NUnit.Framework.Extensions; +using Apache.NMS.Util; +using Apache.NMS.Test; + +namespace Apache.NMS.Stomp.Test +{ + [TestFixture] + public class MessageTest : NMSTestSupport + { + protected static string DESTINATION_NAME = "MessagePropsDestination"; + protected static string TEST_CLIENT_ID = "MessagePropsClientId"; + + 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; + + [RowTest] + [Row(MsgDeliveryMode.Persistent)] + [Row(MsgDeliveryMode.NonPersistent)] + public void SendReceiveMessageProperties(MsgDeliveryMode deliveryMode) + { + using(IConnection connection = CreateConnection(TEST_CLIENT_ID + ":" + new Random().Next())) + { + connection.Start(); + using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge)) + { + IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME); + using(IMessageConsumer consumer = session.CreateConsumer(destination)) + using(IMessageProducer producer = session.CreateProducer(destination)) + { + producer.DeliveryMode = deliveryMode; + producer.RequestTimeout = receiveTimeout; + 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; + 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 + Assert.AreEqual(a.ToString(), message.Properties["a"], "generic map entry: a"); + Assert.AreEqual(b.ToString(), message.Properties["b"], "generic map entry: b"); + Assert.AreEqual(c.ToString(), message.Properties["c"], "generic map entry: c"); + Assert.AreEqual(d.ToString(), message.Properties["d"], "generic map entry: d"); + Assert.AreEqual(e.ToString(), message.Properties["e"], "generic map entry: e"); + Assert.AreEqual(f.ToString(), message.Properties["f"], "generic map entry: f"); + Assert.AreEqual(g.ToString(), message.Properties["g"], "generic map entry: g"); + Assert.AreEqual(h.ToString(), message.Properties["h"], "generic map entry: h"); + Assert.AreEqual(i.ToString(), message.Properties["i"], "generic map entry: i"); + Assert.AreEqual(j.ToString(), message.Properties["j"], "generic map entry: j"); + Assert.AreEqual(k.ToString(), message.Properties["k"], "generic map entry: k"); + Assert.AreEqual(l.ToString(), message.Properties["l"], "generic map entry: l"); + Assert.AreEqual(m.ToString(), message.Properties["m"], "generic map entry: m"); + Assert.AreEqual(n.ToString(), message.Properties["n"], "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.ToString(), message.Properties.GetString("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"); + } + } + } + } + } +} + Propchange: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/MessageTest.cs ------------------------------------------------------------------------------ svn:eol-style = native Propchange: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/MessageTest.cs ------------------------------------------------------------------------------ svn:executable = * Added: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/ProducerTest.cs URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/ProducerTest.cs?rev=896454&view=auto ============================================================================== --- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/ProducerTest.cs (added) +++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/ProducerTest.cs Wed Jan 6 14:35:34 2010 @@ -0,0 +1,116 @@ +/* + * 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; +using Apache.NMS.Test; +using Apache.NMS.Util; +using NUnit.Framework; +using NUnit.Framework.Extensions; + +namespace Apache.NMS.Stomp.Test +{ + [TestFixture] + public class ProducerTest : NMSTestSupport + { + protected static string TEST_CLIENT_ID = "TestProducerClientId"; + + [Test] + public void TestProducerSendToNullDestinationWithoutDefault() + { + using(IConnection connection = CreateConnection(TEST_CLIENT_ID + ":" + new Random().Next())) + { + connection.Start(); + using(ISession session = connection.CreateSession()) + { + IMessageProducer producer = session.CreateProducer(null); + + try + { + producer.Send(null, session.CreateTextMessage("Message")); + Assert.Fail("Producer should have thrown an NotSupportedException"); + } + catch(NotSupportedException) + { + } + catch(Exception ex) + { + Assert.Fail("Wrong Exception Type Thrown: " + ex.GetType().Name); + } + } + } + } + + [Test] + public void TestProducerSendToNullDestinationWithDefault() + { + using(IConnection connection = CreateConnection(TEST_CLIENT_ID + ":" + new Random().Next())) + { + connection.Start(); + using(ISession session = connection.CreateSession()) + { + IDestination unusedDest = session.CreateTemporaryQueue(); + + IMessageProducer producer = session.CreateProducer(unusedDest); + + try + { + producer.Send(null, session.CreateTextMessage("Message")); + Assert.Fail("Producer should have thrown an InvalidDestinationException"); + } + catch(InvalidDestinationException) + { + } + catch(Exception ex) + { + Assert.Fail("Wrong Exception Type Thrown: " + ex.GetType().Name); + } + } + } + } + + [Test] + public void TestProducerSendToNonDefaultDestination() + { + using(IConnection connection = CreateConnection(TEST_CLIENT_ID + ":" + new Random().Next())) + { + connection.Start(); + using(ISession session = connection.CreateSession()) + { + IDestination unusedDest = session.CreateTemporaryQueue(); + IDestination usedDest = session.CreateTemporaryQueue(); + + IMessageProducer producer = session.CreateProducer(unusedDest); + + try + { + producer.Send(usedDest, session.CreateTextMessage("Message")); + Assert.Fail("Producer should have thrown an NotSupportedException"); + } + catch(NotSupportedException) + { + } + catch(Exception ex) + { + Assert.Fail("Wrong Exception Type Thrown: " + ex.GetType().Name); + } + } + } + } + } +} Propchange: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/ProducerTest.cs ------------------------------------------------------------------------------ svn:eol-style = native Added: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/TextMessageTest.cs URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/TextMessageTest.cs?rev=896454&view=auto ============================================================================== --- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/TextMessageTest.cs (added) +++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/TextMessageTest.cs Wed Jan 6 14:35:34 2010 @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using Apache.NMS.Util; +using Apache.NMS.Test; +using NUnit.Framework; +using NUnit.Framework.Extensions; + +namespace Apache.NMS.Stomp.Test +{ + [TestFixture] + public class TextMessageTest : NMSTestSupport + { + protected static string DESTINATION_NAME = "TextMessageDestination"; + protected static string TEST_CLIENT_ID = "TextMessageClientId"; + + [RowTest] + [Row(MsgDeliveryMode.Persistent)] + [Row(MsgDeliveryMode.NonPersistent)] + public void SendReceiveTextMessage(MsgDeliveryMode deliveryMode) + { + using(IConnection connection = CreateConnection(TEST_CLIENT_ID)) + { + connection.Start(); + using(ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge)) + { + IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME); + using(IMessageConsumer consumer = session.CreateConsumer(destination)) + using(IMessageProducer producer = session.CreateProducer(destination)) + { + producer.DeliveryMode = deliveryMode; + producer.RequestTimeout = receiveTimeout; + IMessage request = session.CreateTextMessage("Hello World!"); + producer.Send(request); + + IMessage message = consumer.Receive(receiveTimeout); + AssertTextMessageEqual(request, message); + Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match"); + } + } + } + } + + /// + /// Assert that two messages are ITextMessages and their text bodies are equal. + /// + /// + /// + protected void AssertTextMessageEqual(IMessage expected, IMessage actual) + { + ITextMessage expectedTextMsg = expected as ITextMessage; + Assert.IsNotNull(expectedTextMsg, "'expected' message not a text message"); + ITextMessage actualTextMsg = actual as ITextMessage; + Assert.IsNotNull(actualTextMsg, "'actual' message not a text message"); + Assert.AreEqual(expectedTextMsg.Text, actualTextMsg.Text, "Text message does not match."); + } + } +} Propchange: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/TextMessageTest.cs ------------------------------------------------------------------------------ svn:eol-style = native Propchange: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/TextMessageTest.cs ------------------------------------------------------------------------------ svn:executable = * Modified: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/vs2008-stomp-test.csproj URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/vs2008-stomp-test.csproj?rev=896454&r1=896453&r2=896454&view=diff ============================================================================== --- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/vs2008-stomp-test.csproj (original) +++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/vs2008-stomp-test.csproj Wed Jan 6 14:35:34 2010 @@ -74,5 +74,11 @@ + + + + + + \ No newline at end of file