summaryrefslogtreecommitdiff
path: root/qpid/dotnet/Qpid.Client.Tests
diff options
context:
space:
mode:
authorTomas Restrepo <tomasr@apache.org>2007-05-10 23:02:46 +0000
committerTomas Restrepo <tomasr@apache.org>2007-05-10 23:02:46 +0000
commitcac9db624b611981e9d8ecf64561fe7ed7e173a6 (patch)
tree62a01b26d41e0ff72fe32807bfb48fd3d3d3032c /qpid/dotnet/Qpid.Client.Tests
parent4477307192b9a5fd46e6f9e91ab4299a1b7abbd3 (diff)
downloadqpid-python-cac9db624b611981e9d8ecf64561fe7ed7e173a6.tar.gz
Merged revisions 537015-537026 via svnmerge from
https://svn.apache.org/repos/asf/incubator/qpid/branches/M2 ........ r537015 | tomasr | 2007-05-10 17:16:49 -0500 (Thu, 10 May 2007) | 1 line QPID-435: Fix HeadersExchangeTest ........ r537019 | tomasr | 2007-05-10 17:25:01 -0500 (Thu, 10 May 2007) | 1 line QPID-441 Fix handling of bounced messages ........ r537026 | tomasr | 2007-05-10 17:46:46 -0500 (Thu, 10 May 2007) | 1 line QPID-398 SSL support for .NET client ........ git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@537031 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/dotnet/Qpid.Client.Tests')
-rw-r--r--qpid/dotnet/Qpid.Client.Tests/HeadersExchange/HeadersExchangeTest.cs10
-rw-r--r--qpid/dotnet/Qpid.Client.Tests/Qpid.Client.Tests.csproj2
-rw-r--r--qpid/dotnet/Qpid.Client.Tests/Security/CallbackHandlerRegistryTests.cs2
-rw-r--r--qpid/dotnet/Qpid.Client.Tests/connection/QpidTestCert.pfxbin0 -> 1759 bytes
-rw-r--r--qpid/dotnet/Qpid.Client.Tests/connection/SslConnectionTest.cs91
-rw-r--r--qpid/dotnet/Qpid.Client.Tests/requestreply1/ServiceRequestingClient.cs2
-rw-r--r--qpid/dotnet/Qpid.Client.Tests/undeliverable/UndeliverableTest.cs142
7 files changed, 188 insertions, 61 deletions
diff --git a/qpid/dotnet/Qpid.Client.Tests/HeadersExchange/HeadersExchangeTest.cs b/qpid/dotnet/Qpid.Client.Tests/HeadersExchange/HeadersExchangeTest.cs
index 2700c4afb2..2ab8c00388 100644
--- a/qpid/dotnet/Qpid.Client.Tests/HeadersExchange/HeadersExchangeTest.cs
+++ b/qpid/dotnet/Qpid.Client.Tests/HeadersExchange/HeadersExchangeTest.cs
@@ -96,7 +96,7 @@ namespace Qpid.Client.Tests
_consumer = _channel.CreateConsumerBuilder(queueName)
.WithPrefetchLow(100)
.WithPrefetchHigh(500)
- .WithNoLocal(true)
+ .WithNoLocal(false) // make sure we get our own messages
.Create();
// Register this to listen for messages on the consumer.
@@ -188,7 +188,7 @@ namespace Qpid.Client.Tests
SendTestMessage(msg, true);
}
- /// <summary>Check that a message matching only some fields of a headers exhcnage is not passed by the exchange.</summary>
+ /// <summary>Check that a message matching only some fields of a headers exchange is not passed by the exchange.</summary>
[Test]
public void TestMatchOneFails()
{
@@ -258,9 +258,9 @@ namespace Qpid.Client.Tests
{
FieldTable matchTable = new FieldTable();
- // Currently all String matching must be prefixed by an "S" ("S" for string because of a failing of the FieldType definition).
- matchTable["Smatch1"] = "foo";
- matchTable["Smatch2"] = "";
+ matchTable["match1"] = "foo";
+ matchTable["match2"] = "";
+ matchTable["x-match"] = "all";
return matchTable;
}
diff --git a/qpid/dotnet/Qpid.Client.Tests/Qpid.Client.Tests.csproj b/qpid/dotnet/Qpid.Client.Tests/Qpid.Client.Tests.csproj
index 3d5af00887..21c6ff9ea2 100644
--- a/qpid/dotnet/Qpid.Client.Tests/Qpid.Client.Tests.csproj
+++ b/qpid/dotnet/Qpid.Client.Tests/Qpid.Client.Tests.csproj
@@ -46,6 +46,7 @@
<ItemGroup>
<Compile Include="bio\BlockingIo.cs" />
<Compile Include="connection\ConnectionTest.cs" />
+ <Compile Include="connection\SslConnectionTest.cs" />
<Compile Include="failover\FailoverTest.cs" />
<Compile Include="failover\FailoverTxTest.cs" />
<Compile Include="HeadersExchange\HeadersExchangeTest.cs" />
@@ -86,6 +87,7 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
+ <EmbeddedResource Include="connection\QpidTestCert.pfx" />
<None Include="Qpid.Common.DLL.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
diff --git a/qpid/dotnet/Qpid.Client.Tests/Security/CallbackHandlerRegistryTests.cs b/qpid/dotnet/Qpid.Client.Tests/Security/CallbackHandlerRegistryTests.cs
index ec0594263f..e18fa15c20 100644
--- a/qpid/dotnet/Qpid.Client.Tests/Security/CallbackHandlerRegistryTests.cs
+++ b/qpid/dotnet/Qpid.Client.Tests/Security/CallbackHandlerRegistryTests.cs
@@ -32,7 +32,7 @@ namespace Qpid.Client.Tests.Security
public void ParsesConfiguration()
{
CallbackHandlerRegistry registry = CallbackHandlerRegistry.Instance;
- Assert.AreEqual(3, registry.Mechanisms.Length);
+ Assert.AreEqual(4, registry.Mechanisms.Length);
Assert.Contains("TEST", registry.Mechanisms);
Type handlerType = registry.GetCallbackHandler("TEST");
diff --git a/qpid/dotnet/Qpid.Client.Tests/connection/QpidTestCert.pfx b/qpid/dotnet/Qpid.Client.Tests/connection/QpidTestCert.pfx
new file mode 100644
index 0000000000..3f1855c6e9
--- /dev/null
+++ b/qpid/dotnet/Qpid.Client.Tests/connection/QpidTestCert.pfx
Binary files differ
diff --git a/qpid/dotnet/Qpid.Client.Tests/connection/SslConnectionTest.cs b/qpid/dotnet/Qpid.Client.Tests/connection/SslConnectionTest.cs
new file mode 100644
index 0000000000..b8941c8459
--- /dev/null
+++ b/qpid/dotnet/Qpid.Client.Tests/connection/SslConnectionTest.cs
@@ -0,0 +1,91 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+using System;
+using System.IO;
+using System.Reflection;
+using System.Security.Cryptography.X509Certificates;
+using NUnit.Framework;
+using Qpid.Client.Qms;
+using Qpid.Messaging;
+
+namespace Qpid.Client.Tests.Connection
+{
+ /// <summary>
+ /// Test SSL/TLS connections to the broker
+ /// </summary>
+ [TestFixture]
+ public class SslConnectionTest
+ {
+ /// <summary>
+ /// Make a test TLS connection to the broker
+ /// without using client-certificates
+ /// </summary>
+ [Test]
+ public void DoSslConnection()
+ {
+ // because for tests we don't usually trust the server certificate
+ // we need here to tell the client to ignore certificate validation errors
+ SslOptions sslConfig = new SslOptions(null, true);
+
+ MakeBrokerConnection(sslConfig);
+ }
+
+ /// <summary>
+ /// Make a TLS connection to the broker with a
+ /// client-side certificate
+ /// </summary>
+ [Test]
+ public void DoSslConnectionWithClientCert()
+ {
+ // because for tests we don't usually trust the server certificate
+ // we need here to tell the client to ignore certificate validation errors
+ SslOptions sslConfig = new SslOptions(LoadClientCert(), true);
+
+ MakeBrokerConnection(sslConfig);
+ }
+
+ private static void MakeBrokerConnection(SslOptions options)
+ {
+ IConnectionInfo connectionInfo = new QpidConnectionInfo();
+ connectionInfo.VirtualHost = "test";
+ connectionInfo.AddBrokerInfo(new AmqBrokerInfo("amqp", "localhost", 8672, options));
+
+ using ( IConnection connection = new AMQConnection(connectionInfo) )
+ {
+ Console.WriteLine("connection = " + connection);
+ }
+ }
+
+ private static X509Certificate LoadClientCert()
+ {
+ // load a self-issued certificate from an embedded
+ // resource
+ const string name = "Qpid.Client.Tests.connection.QpidTestCert.pfx";
+ Assembly assembly = Assembly.GetExecutingAssembly();
+
+ Stream res = assembly.GetManifestResourceStream(name);
+ byte[] buffer = new byte[res.Length];
+ res.Read(buffer, 0, buffer.Length);
+
+ return new X509Certificate(buffer);
+ }
+ }
+}
diff --git a/qpid/dotnet/Qpid.Client.Tests/requestreply1/ServiceRequestingClient.cs b/qpid/dotnet/Qpid.Client.Tests/requestreply1/ServiceRequestingClient.cs
index 68eee90b64..4479d767ea 100644
--- a/qpid/dotnet/Qpid.Client.Tests/requestreply1/ServiceRequestingClient.cs
+++ b/qpid/dotnet/Qpid.Client.Tests/requestreply1/ServiceRequestingClient.cs
@@ -40,7 +40,7 @@ namespace Qpid.Client.Tests
private int _expectedMessageCount = NUM_MESSAGES;
- private long _startTime;
+ private long _startTime = 0;
private string _commandQueueName = "ServiceQ1";
diff --git a/qpid/dotnet/Qpid.Client.Tests/undeliverable/UndeliverableTest.cs b/qpid/dotnet/Qpid.Client.Tests/undeliverable/UndeliverableTest.cs
index 84ae2c92c1..bae5b6d8f9 100644
--- a/qpid/dotnet/Qpid.Client.Tests/undeliverable/UndeliverableTest.cs
+++ b/qpid/dotnet/Qpid.Client.Tests/undeliverable/UndeliverableTest.cs
@@ -26,69 +26,103 @@ using Qpid.Messaging;
namespace Qpid.Client.Tests
{
- [TestFixture]
- public class UndeliverableTest : BaseMessagingTestFixture
- {
- private static ILog _logger = LogManager.GetLogger(typeof(UndeliverableTest));
+ /// <summary>
+ /// Tests that when sending undeliverable messages with the
+ /// mandatory flag set, an exception is raised on the connection
+ /// as the message is bounced back by the broker
+ /// </summary>
+ [TestFixture]
+ public class UndeliverableTest : BaseMessagingTestFixture
+ {
+ private static ILog _logger = LogManager.GetLogger(typeof(UndeliverableTest));
+ private ManualResetEvent _event;
+ public const int TIMEOUT = 1000;
+ private Exception _lastException;
- [SetUp]
- public override void Init()
- {
- base.Init();
+ [SetUp]
+ public override void Init()
+ {
+ base.Init();
+ _event = new ManualResetEvent(false);
+ _lastException = null;
- try
- {
- _connection.ExceptionListener = new ExceptionListenerDelegate(OnException);
- }
- catch (QpidException e)
+ try
+ {
+ _connection.ExceptionListener = new ExceptionListenerDelegate(OnException);
+ } catch ( QpidException e )
+ {
+ _logger.Error("Could not add ExceptionListener", e);
+ }
+ }
+
+ public void OnException(Exception e)
+ {
+ // Here we dig out the AMQUndelivered exception (if present) in order to log the returned message.
+
+ _lastException = e;
+ _logger.Error("OnException handler received connection-level exception", e);
+ if ( e is QpidException )
+ {
+ QpidException qe = (QpidException)e;
+ if ( qe.InnerException is AMQUndeliveredException )
{
- _logger.Error("Could not add ExceptionListener", e);
+ AMQUndeliveredException ue = (AMQUndeliveredException)qe.InnerException;
+ _logger.Error("inner exception is AMQUndeliveredException", ue);
+ _logger.Error(string.Format("Returned message = {0}", ue.GetUndeliveredMessage()));
}
- }
+ }
+ _event.Set();
+ }
- public static void OnException(Exception e)
- {
- // Here we dig out the AMQUndelivered exception (if present) in order to log the returned message.
+ [Test]
+ public void SendUndeliverableMessageOnDefaultExchange()
+ {
+ SendOne("default exchange", null);
+ }
+ [Test]
+ public void SendUndeliverableMessageOnDirectExchange()
+ {
+ SendOne("direct exchange", ExchangeNameDefaults.DIRECT);
+ }
+ [Test]
+ public void SendUndeliverableMessageOnTopicExchange()
+ {
+ SendOne("topic exchange", ExchangeNameDefaults.TOPIC);
+ }
+ [Test]
+ public void SendUndeliverableMessageOnHeadersExchange()
+ {
+ SendOne("headers exchange", ExchangeNameDefaults.HEADERS);
+ }
- _logger.Error("OnException handler received connection-level exception", e);
- if (e is QpidException)
- {
- QpidException qe = (QpidException)e;
- if (qe.InnerException is AMQUndeliveredException)
- {
- AMQUndeliveredException ue = (AMQUndeliveredException)qe.InnerException;
- _logger.Error("inner exception is AMQUndeliveredException", ue);
- _logger.Error(string.Format("Returned message = {0}", ue.GetUndeliveredMessage()));
+ private void SendOne(string exchangeNameFriendly, string exchangeName)
+ {
+ _logger.Info("Sending undeliverable message to " + exchangeNameFriendly);
- }
- }
- }
+ // Send a test message to a non-existant queue
+ // on the specified exchange. See if message is returned!
+ MessagePublisherBuilder builder = _channel.CreatePublisherBuilder()
+ .WithRoutingKey("Non-existant route key!")
+ .WithMandatory(true); // necessary so that the server bounces the message back
+ if ( exchangeName != null )
+ {
+ builder.WithExchangeName(exchangeName);
+ }
+ IMessagePublisher publisher = builder.Create();
+ publisher.Send(_channel.CreateTextMessage("Hiya!"));
- [Test]
- public void SendUndeliverableMessage()
- {
- SendOne("default exchange", null);
- SendOne("direct exchange", ExchangeNameDefaults.DIRECT);
- SendOne("topic exchange", ExchangeNameDefaults.TOPIC);
- SendOne("headers exchange", ExchangeNameDefaults.HEADERS);
+ // check we received an exception on the connection
+ // and that it is of the right type
+ _event.WaitOne(TIMEOUT, true);
- Thread.Sleep(1000); // Wait for message returns!
- }
+ Type expectedException = typeof(AMQUndeliveredException);
+ Exception ex = _lastException;
+ Assert.IsNotNull(ex, "No exception was thrown by the test. Expected " + expectedException);
- private void SendOne(string exchangeNameFriendly, string exchangeName)
- {
- _logger.Info("Sending undeliverable message to " + exchangeNameFriendly);
+ if ( ex.InnerException != null )
+ ex = ex.InnerException;
- // Send a test message to a non-existant queue on the default exchange. See if message is returned!
- MessagePublisherBuilder builder = _channel.CreatePublisherBuilder()
- .WithRoutingKey("Non-existant route key!")
- .WithMandatory(true);
- if (exchangeName != null)
- {
- builder.WithExchangeName(exchangeName);
- }
- IMessagePublisher publisher = builder.Create();
- publisher.Send(_channel.CreateTextMessage("Hiya!"));
- }
- }
+ Assert.IsInstanceOfType(expectedException, ex);
+ }
+ }
}