You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2010/01/14 17:46:30 UTC

svn commit: r899288 - in /activemq/activemq-dotnet/Apache.NMS.Stomp/trunk: src/main/csharp/Protocol/StompWireFormat.cs src/main/csharp/Protocol/XmlPrimitiveMapMarshaler.cs src/test/csharp/MapMessageTest.cs vs2008-stomp-test.csproj

Author: tabish
Date: Thu Jan 14 16:46:29 2010
New Revision: 899288

URL: http://svn.apache.org/viewvc?rev=899288&view=rev
Log:
Adds MapMessageTest for sending and receiving MapMessage.  Fixes issue with unmarshal of byte when value is > 127

Added:
    activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/MapMessageTest.cs   (with props)
Modified:
    activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Protocol/StompWireFormat.cs
    activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Protocol/XmlPrimitiveMapMarshaler.cs
    activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/vs2008-stomp-test.csproj

Modified: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Protocol/StompWireFormat.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Protocol/StompWireFormat.cs?rev=899288&r1=899287&r2=899288&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Protocol/StompWireFormat.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Protocol/StompWireFormat.cs Thu Jan 14 16:46:29 2010
@@ -424,7 +424,7 @@
             }
 
             // ActiveMQ extensions to STOMP
-            // frame.SetProperty("transformation", "jms-map-xml");
+            frame.SetProperty("transformation", "jms-map-xml");
             frame.SetProperty("activemq.dispatchAsync", command.DispatchAsync);
 
             if(command.Exclusive)

Modified: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Protocol/XmlPrimitiveMapMarshaler.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Protocol/XmlPrimitiveMapMarshaler.cs?rev=899288&r1=899287&r2=899288&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Protocol/XmlPrimitiveMapMarshaler.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/main/csharp/Protocol/XmlPrimitiveMapMarshaler.cs Thu Jan 14 16:46:29 2010
@@ -144,7 +144,7 @@
                     reader.ReadEndElement();
                     break;
                 case "byte":
-                    value = Convert.ToByte(reader.ReadElementContentAsString());
+                    value = (byte) Convert.ToInt16(reader.ReadElementContentAsString());
                     reader.ReadEndElement();
                     break;
                 case "boolean":
@@ -162,7 +162,6 @@
                 };
 
                 // Now store the value into our new PrimitiveMap.
-                Console.WriteLine("result[{0}] = {1}", key, value);
                 result[key] = value;
             }
 
@@ -188,7 +187,7 @@
             }
             else if(value is byte)
             {
-                writer.WriteElementString("byte", value.ToString());
+                writer.WriteElementString("byte", ((Byte) value).ToString());
             }
             else if(value is short)
             {

Added: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/MapMessageTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/MapMessageTest.cs?rev=899288&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/MapMessageTest.cs (added)
+++ activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/MapMessageTest.cs Thu Jan 14 16:46:29 2010
@@ -0,0 +1,198 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Collections;
+using Apache.NMS;
+using Apache.NMS.Test;
+using Apache.NMS.Util;
+using NUnit.Framework;
+using NUnit.Framework.Extensions;
+
+namespace Apache.NMS.Stomp.Test
+{
+    [TestFixture]
+    public class MapMessageTest : 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 SendReceiveMapMessage(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;
+                        IMapMessage request = session.CreateMapMessage();
+                        request.Body["a"] = a;
+                        request.Body["b"] = b;
+                        request.Body["c"] = c;
+                        request.Body["d"] = d;
+                        request.Body["e"] = e;
+                        request.Body["f"] = f;
+                        request.Body["g"] = g;
+                        request.Body["h"] = h;
+                        request.Body["i"] = i;
+                        request.Body["j"] = j;
+                        request.Body["k"] = k;
+                        request.Body["l"] = l;
+                        request.Body["m"] = m;
+                        request.Body["n"] = n;
+                        producer.Send(request);
+
+                        IMapMessage message = consumer.Receive(receiveTimeout) as IMapMessage;
+                        Assert.IsNotNull(message, "No message returned!");
+                        Assert.AreEqual(request.Body.Count, message.Body.Count, "Invalid number of message maps.");
+                        Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");
+                        Assert.AreEqual(ToHex(f), ToHex(message.Body.GetLong("f")), "map entry: f as hex");
+
+                        // use generic API to access entries
+                        Assert.AreEqual(a, message.Body["a"], "generic map entry: a");
+                        Assert.AreEqual(b, message.Body["b"], "generic map entry: b");
+                        Assert.AreEqual(c, message.Body["c"], "generic map entry: c");
+                        Assert.AreEqual(d, message.Body["d"], "generic map entry: d");
+                        Assert.AreEqual(e, message.Body["e"], "generic map entry: e");
+                        Assert.AreEqual(f, message.Body["f"], "generic map entry: f");
+                        Assert.AreEqual(g, message.Body["g"], "generic map entry: g");
+                        Assert.AreEqual(h, message.Body["h"], "generic map entry: h");
+                        Assert.AreEqual(i, message.Body["i"], "generic map entry: i");
+                        Assert.AreEqual(j, message.Body["j"], "generic map entry: j");
+                        Assert.AreEqual(k, message.Body["k"], "generic map entry: k");
+                        Assert.AreEqual(l, message.Body["l"], "generic map entry: l");
+                        Assert.AreEqual(m, message.Body["m"], "generic map entry: m");
+                        Assert.AreEqual(n, message.Body["n"], "generic map entry: n");
+
+                        // use type safe APIs
+                        Assert.AreEqual(a, message.Body.GetBool("a"), "map entry: a");
+                        Assert.AreEqual(b, message.Body.GetByte("b"), "map entry: b");
+                        Assert.AreEqual(c, message.Body.GetChar("c"), "map entry: c");
+                        Assert.AreEqual(d, message.Body.GetShort("d"), "map entry: d");
+                        Assert.AreEqual(e, message.Body.GetInt("e"), "map entry: e");
+                        Assert.AreEqual(f, message.Body.GetLong("f"), "map entry: f");
+                        Assert.AreEqual(g, message.Body.GetString("g"), "map entry: g");
+                        Assert.AreEqual(h, message.Body.GetBool("h"), "map entry: h");
+                        Assert.AreEqual(i, message.Body.GetByte("i"), "map entry: i");
+                        Assert.AreEqual(j, message.Body.GetShort("j"), "map entry: j");
+                        Assert.AreEqual(k, message.Body.GetInt("k"), "map entry: k");
+                        Assert.AreEqual(l, message.Body.GetLong("l"), "map entry: l");
+                        Assert.AreEqual(m, message.Body.GetFloat("m"), "map entry: m");
+                        Assert.AreEqual(n, message.Body.GetDouble("n"), "map entry: n");
+                    }
+                }
+            }
+        }
+
+//        [RowTest]
+//        [Row(MsgDeliveryMode.Persistent)]
+//        [Row(MsgDeliveryMode.NonPersistent)]
+        public void SendReceiveNestedMapMessage(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;
+                        IMapMessage request = session.CreateMapMessage();
+                        const string textFieldValue = "Nested Map Messages Rule!";
+
+                        request.Body.SetString("textField", textFieldValue);
+
+                        IDictionary grandChildMap = new Hashtable();
+                        grandChildMap["x"] = "abc";
+                        grandChildMap["y"] = new ArrayList(new object[] { "a", "b", "c" });
+
+                        IDictionary nestedMap = new Hashtable();
+                        nestedMap["a"] = "foo";
+                        nestedMap["b"] = (int) 23;
+                        nestedMap["c"] = (long) 45;
+                        nestedMap["d"] = grandChildMap;
+
+                        request.Body.SetDictionary("mapField", nestedMap);
+                        request.Body.SetList("listField", new ArrayList(new Object[] { "a", "b", "c" }));
+
+                        producer.Send(request);
+
+                        IMapMessage message = consumer.Receive(receiveTimeout) as IMapMessage;
+                        Assert.IsNotNull(message, "No message returned!");
+                        Assert.AreEqual(request.Body.Count, message.Body.Count, "Invalid number of message maps.");
+                        Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");
+
+                        string textFieldResponse = message.Body.GetString("textField");
+                        Assert.AreEqual(textFieldValue, textFieldResponse, "textField does not match.");
+
+                        IDictionary nestedMapResponse = message.Body.GetDictionary("mapField");
+                        Assert.IsNotNull(nestedMapResponse, "Nested map not returned.");
+                        Assert.AreEqual(nestedMap.Count, nestedMapResponse.Count, "nestedMap: Wrong number of elements");
+                        Assert.AreEqual("foo", nestedMapResponse["a"], "nestedMap: a");
+                        Assert.AreEqual(23, nestedMapResponse["b"], "nestedMap: b");
+                        Assert.AreEqual(45, nestedMapResponse["c"], "nestedMap: c");
+
+                        IDictionary grandChildMapResponse = nestedMapResponse["d"] as IDictionary;
+                        Assert.IsNotNull(grandChildMapResponse, "Grand child map not returned.");
+                        Assert.AreEqual(grandChildMap.Count, grandChildMapResponse.Count, "grandChildMap: Wrong number of elements");
+                        Assert.AreEqual(grandChildMapResponse["x"], "abc", "grandChildMap: x");
+
+                        IList grandChildList = grandChildMapResponse["y"] as IList;
+                        Assert.IsNotNull(grandChildList, "Grand child list not returned.");
+                        Assert.AreEqual(3, grandChildList.Count, "grandChildList: Wrong number of list elements.");
+                        Assert.AreEqual("a", grandChildList[0], "grandChildList: a");
+                        Assert.AreEqual("b", grandChildList[1], "grandChildList: b");
+                        Assert.AreEqual("c", grandChildList[2], "grandChildList: c");
+
+                        IList listFieldResponse = message.Body.GetList("listField");
+                        Assert.IsNotNull(listFieldResponse, "Nested list not returned.");
+                        Assert.AreEqual(3, listFieldResponse.Count, "listFieldResponse: Wrong number of list elements.");
+                        Assert.AreEqual("a", listFieldResponse[0], "listFieldResponse: a");
+                        Assert.AreEqual("b", listFieldResponse[1], "listFieldResponse: b");
+                        Assert.AreEqual("c", listFieldResponse[2], "listFieldResponse: c");
+                    }
+                }
+            }
+        }
+    }
+}

Propchange: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/MapMessageTest.cs
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/activemq-dotnet/Apache.NMS.Stomp/trunk/src/test/csharp/MapMessageTest.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=899288&r1=899287&r2=899288&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 Thu Jan 14 16:46:29 2010
@@ -102,6 +102,7 @@
     <Compile Include="src\test\csharp\Threads\DedicatedTaskRunnerTest.cs" />
     <Compile Include="src\test\csharp\Commands\MapMessageTest.cs" />
     <Compile Include="src\test\csharp\Protocol\XmlPrimitiveMapMarshalerTest.cs" />
+    <Compile Include="src\test\csharp\MapMessageTest.cs" />
   </ItemGroup>
   <ItemGroup>
     <Folder Include="src\test\csharp\Protocol\" />