qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tom...@apache.org
Subject svn commit: r537954 - in /incubator/qpid/branches/M2/dotnet: Qpid.Client.Tests/Qpid.Client.Tests.csproj Qpid.Client.Tests/url/ConnectionUrlTest.cs Qpid.Client/Client/AmqBrokerInfo.cs Qpid.Client/Client/QpidConnectionInfo.cs
Date Mon, 14 May 2007 19:11:01 GMT
Author: tomasr
Date: Mon May 14 12:10:59 2007
New Revision: 537954

URL: http://svn.apache.org/viewvc?view=rev&rev=537954
Log:
* QPID-487 (Contributed by Carlos Medina) Fix QpidConnectionInfo.ToString()
* QPID-485 (Contributed by Carlos Medina) Fix AmqBrokerInfo.Equals()
* QPID-456 Enforce virtual host names start with '/'

Modified:
    incubator/qpid/branches/M2/dotnet/Qpid.Client.Tests/Qpid.Client.Tests.csproj
    incubator/qpid/branches/M2/dotnet/Qpid.Client.Tests/url/ConnectionUrlTest.cs
    incubator/qpid/branches/M2/dotnet/Qpid.Client/Client/AmqBrokerInfo.cs
    incubator/qpid/branches/M2/dotnet/Qpid.Client/Client/QpidConnectionInfo.cs

Modified: incubator/qpid/branches/M2/dotnet/Qpid.Client.Tests/Qpid.Client.Tests.csproj
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2/dotnet/Qpid.Client.Tests/Qpid.Client.Tests.csproj?view=diff&rev=537954&r1=537953&r2=537954
==============================================================================
--- incubator/qpid/branches/M2/dotnet/Qpid.Client.Tests/Qpid.Client.Tests.csproj (original)
+++ incubator/qpid/branches/M2/dotnet/Qpid.Client.Tests/Qpid.Client.Tests.csproj Mon May 14
12:10:59 2007
@@ -45,6 +45,7 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="bio\BlockingIo.cs" />
+    <Compile Include="BrokerDetails\BrokerDetailsTest.cs" />
     <Compile Include="connection\ConnectionTest.cs" />
     <Compile Include="connection\SslConnectionTest.cs" />
     <Compile Include="failover\FailoverTest.cs" />

Modified: incubator/qpid/branches/M2/dotnet/Qpid.Client.Tests/url/ConnectionUrlTest.cs
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2/dotnet/Qpid.Client.Tests/url/ConnectionUrlTest.cs?view=diff&rev=537954&r1=537953&r2=537954
==============================================================================
--- incubator/qpid/branches/M2/dotnet/Qpid.Client.Tests/url/ConnectionUrlTest.cs (original)
+++ incubator/qpid/branches/M2/dotnet/Qpid.Client.Tests/url/ConnectionUrlTest.cs Mon May 14
12:10:59 2007
@@ -404,5 +404,43 @@
                 Assert.AreEqual("Unterminated option", e.Message);
             }
         }
+
+        [Test]
+        public void ValidateQpidConnectionInfoFromToString()
+        {
+            String url = "amqp://ritchiem:bob@default/temp?brokerlist='tcp://localhost:5672;tcp://fancyserver:3000/',failover='roundrobin'";
+
+            IConnectionInfo connectionInfo = QpidConnectionInfo.FromUrl(url);
+            IConnectionInfo connectionInfo1 = QpidConnectionInfo.FromUrl(connectionInfo.ToString());
+
+            Console.WriteLine(connectionInfo.ToString());
+            Console.WriteLine(connectionInfo1.ToString());
+
+            Assert.AreEqual(connectionInfo.Username, connectionInfo1.Username);
+            Assert.AreEqual(connectionInfo.Password, connectionInfo1.Password);
+            Assert.AreEqual(connectionInfo.VirtualHost, connectionInfo1.VirtualHost);
+
+            Assert.IsTrue((connectionInfo1.GetAllBrokerInfos().Count == 2));
+            Assert.IsTrue(connectionInfo.GetBrokerInfo(0).Equals(connectionInfo1.GetBrokerInfo(0)));
+            Assert.IsTrue(connectionInfo.GetBrokerInfo(1).Equals(connectionInfo1.GetBrokerInfo(1)));
+
+        }
+
+        [Test]
+        public void EnsureVirtualHostStartsWithSlash()
+        {
+           IConnectionInfo connection = new QpidConnectionInfo();
+           connection.VirtualHost = "test";
+           Assert.AreEqual("/test", connection.VirtualHost);
+
+           connection.VirtualHost = "/mytest";
+           Assert.AreEqual("/mytest", connection.VirtualHost);
+
+           connection.VirtualHost = "";
+           Assert.AreEqual("/", connection.VirtualHost);
+
+           connection.VirtualHost = null;
+           Assert.AreEqual("/", connection.VirtualHost);
+        }
     }
 }

Modified: incubator/qpid/branches/M2/dotnet/Qpid.Client/Client/AmqBrokerInfo.cs
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2/dotnet/Qpid.Client/Client/AmqBrokerInfo.cs?view=diff&rev=537954&r1=537953&r2=537954
==============================================================================
--- incubator/qpid/branches/M2/dotnet/Qpid.Client/Client/AmqBrokerInfo.cs (original)
+++ incubator/qpid/branches/M2/dotnet/Qpid.Client/Client/AmqBrokerInfo.cs Mon May 14 12:10:59
2007
@@ -260,7 +260,7 @@
             sb.Append(_transport);
             sb.Append("://");
 
-            if (!(_transport.ToLower().Equals("vm")))
+            if (!(StringEqualsIgnoreCase(_transport, "vm")))
             {
                 sb.Append(_host);
             }
@@ -268,8 +268,7 @@
             sb.Append(':');
             sb.Append(_port);
 
-            // XXX
-//            sb.Append(printOptionsURL());
+            sb.Append(URLHelper.printOptions(_options));
 
             return sb.ToString();
         }
@@ -284,7 +283,8 @@
 	        IBrokerInfo bd = (IBrokerInfo) obj;
 	        return StringEqualsIgnoreCase(_host, bd.Host) &&
 	        	_port == bd.Port &&
-                _transport == bd.Transport;
+                StringEqualsIgnoreCase(_transport, bd.Transport) &&
+                UseSSL == bd.UseSSL;
         }
     	
 		public override int GetHashCode()
@@ -297,35 +297,6 @@
         {
             return one.ToLower().Equals(two.ToLower());
         }
-
-//        private string printOptionsURL()
-//        {
-//            stringBuffer optionsURL = new stringBuffer();
-//
-//            optionsURL.Append('?');
-//
-//            if (!(_options.isEmpty()))
-//            {
-//
-//                for (string key : _options.keySet())
-//                {
-//                    optionsURL.Append(key);
-//
-//                    optionsURL.Append("='");
-//
-//                    optionsURL.Append(_options.get(key));
-//
-//                    optionsURL.Append("'");
-//
-//                    optionsURL.Append(URLHelper.DEFAULT_OPTION_SEPERATOR);
-//                }
-//            }
-//
-//            //remove the extra DEFAULT_OPTION_SEPERATOR or the '?' if there are no options
-//            optionsURL.deleteCharAt(optionsURL.length() - 1);
-//
-//            return optionsURL.tostring();
-//        }
 
         public bool UseSSL
         {

Modified: incubator/qpid/branches/M2/dotnet/Qpid.Client/Client/QpidConnectionInfo.cs
URL: http://svn.apache.org/viewvc/incubator/qpid/branches/M2/dotnet/Qpid.Client/Client/QpidConnectionInfo.cs?view=diff&rev=537954&r1=537953&r2=537954
==============================================================================
--- incubator/qpid/branches/M2/dotnet/Qpid.Client/Client/QpidConnectionInfo.cs (original)
+++ incubator/qpid/branches/M2/dotnet/Qpid.Client/Client/QpidConnectionInfo.cs Mon May 14
12:10:59 2007
@@ -171,19 +171,10 @@
                 sb.Append('?');
                 foreach (String key in options.Keys)
                 {
-                    sb.Append(key);
-
-                    sb.Append("='");
-
-                    sb.Append(options[key]);
-
-                    sb.Append("'");
-                    sb.Append(DEFAULT_OPTION_SEPERATOR);
+                    sb.AppendFormat("{0}='{1}'{2}", key, options[key], DEFAULT_OPTION_SEPERATOR);
                 }
 
                 sb.Remove(sb.Length - 1, 1);
-                //                sb.deleteCharAt(sb.length() - 1);
-
                 return sb.ToString();
             }
         }
@@ -358,9 +349,10 @@
 
     public class QpidConnectionInfo : IConnectionInfo
     {
+        const string DEFAULT_VHOST = "/";
         string _username = "guest";
         string _password = "guest";
-        string _virtualHost = "/";
+        string _virtualHost = DEFAULT_VHOST;
 
         string _failoverMethod = null;
         IDictionary _failoverOptions = new Hashtable();
@@ -385,15 +377,51 @@
 
         public string AsUrl()
         {
-            string result = "amqp://";
-            foreach (IBrokerInfo info in _brokerInfos)
+            StringBuilder sb = new StringBuilder();
+            sb.AppendFormat("{0}://", ConnectionUrlConstants.AMQ_PROTOCOL);
+
+            if (_username != null)
             {
-                result += info.ToString();
+                sb.Append(_username);
+                if (_password != null)
+                {
+                    sb.AppendFormat(":{0}", _password);
+                }
+                sb.Append("@");
             }
-            return result;
 
+            sb.Append(_clientName);
+            sb.Append(_virtualHost);
+            sb.Append(OptionsToString());
+
+            return sb.ToString();
         }
 
+        private String OptionsToString()
+        {
+            StringBuilder sb = new StringBuilder();
+            sb.AppendFormat("?{0}='", ConnectionUrlConstants.OPTIONS_BROKERLIST);
+
+            foreach (IBrokerInfo broker in _brokerInfos)
+            {
+                sb.AppendFormat("{0};", broker);
+            }
+
+            sb.Remove(sb.Length - 1, 1);
+            sb.Append("'");
+
+            if (_failoverMethod != null)
+            {
+                sb.AppendFormat("{0}{1}='{2}{3}'", URLHelper.DEFAULT_OPTION_SEPERATOR,
+                    ConnectionUrlConstants.OPTIONS_FAILOVER,
+                    _failoverMethod,
+                    URLHelper.printOptions((Hashtable)_failoverOptions));
+            }
+
+            return sb.ToString();
+        }
+
+
         public string FailoverMethod
         {
             get { return _failoverMethod; }
@@ -449,7 +477,13 @@
         public string VirtualHost
         {
             get { return _virtualHost; }
-            set { _virtualHost = value; }
+            set { 
+               _virtualHost = value;
+               if ( _virtualHost == null || _virtualHost.Length == 0 )
+                  _virtualHost = DEFAULT_VHOST;
+               if ( _virtualHost[0] != '/' )
+                  _virtualHost = '/' + _virtualHost;
+            }
         }
 
         public string GetOption(string key)



Mime
View raw message