From 7130f43c8f6b874b3e9b86cd27d179991476483d Mon Sep 17 00:00:00 2001 From: James Strachan Date: Fri, 24 Feb 2006 13:16:09 +0000 Subject: [PATCH] added full test for MapMessage together with fixing a bug with long marshalling types and headers git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@380666 13f79535-47bb-0310-9956-ffa450edef68 --- .../Commands/ActiveMQMapMessage.cs | 18 ++++--- .../Commands/ActiveMQMessage.cs | 12 ++--- .../Core/DataStreamMarshaller.cs | 11 +++-- .../tests/OpenWire.Client/JMSPropertyTest.cs | 4 +- .../tests/OpenWire.Client/MapMessageTest.cs | 48 +++++++++++++++---- 5 files changed, 64 insertions(+), 29 deletions(-) diff --git a/openwire-dotnet/src/OpenWire.Client/Commands/ActiveMQMapMessage.cs b/openwire-dotnet/src/OpenWire.Client/Commands/ActiveMQMapMessage.cs index 5f314dd4f6..cdff0f11d7 100644 --- a/openwire-dotnet/src/OpenWire.Client/Commands/ActiveMQMapMessage.cs +++ b/openwire-dotnet/src/OpenWire.Client/Commands/ActiveMQMapMessage.cs @@ -39,22 +39,26 @@ namespace OpenWire.Client.Commands get { if (body == null) { - body = PrimitiveMap.Unmarshal(Content); - } + body = PrimitiveMap.Unmarshal(Content); + } return body; } } - public void BeforeMarshall(OpenWireFormat wireFormat) + public override void BeforeMarshall(OpenWireFormat wireFormat) { - base.BeforeMarshall(wireFormat); - - if (body == null) { + if (body == null) + { Content = null; } - else { + else + { Content = body.Marshal(); } + + Console.WriteLine("BeforeMarshalling, content is: " + Content); + + base.BeforeMarshall(wireFormat); } } diff --git a/openwire-dotnet/src/OpenWire.Client/Commands/ActiveMQMessage.cs b/openwire-dotnet/src/OpenWire.Client/Commands/ActiveMQMessage.cs index a3714e3bdc..846e3dfb4a 100644 --- a/openwire-dotnet/src/OpenWire.Client/Commands/ActiveMQMessage.cs +++ b/openwire-dotnet/src/OpenWire.Client/Commands/ActiveMQMessage.cs @@ -277,7 +277,7 @@ namespace OpenWire.Client.Commands return true; } - public void BeforeMarshall(OpenWireFormat wireFormat) + public virtual void BeforeMarshall(OpenWireFormat wireFormat) { MarshalledProperties = null; if (properties != null) @@ -286,23 +286,23 @@ namespace OpenWire.Client.Commands } } - public void AfterMarshall(OpenWireFormat wireFormat) + public virtual void AfterMarshall(OpenWireFormat wireFormat) { } - public void BeforeUnmarshall(OpenWireFormat wireFormat) + public virtual void BeforeUnmarshall(OpenWireFormat wireFormat) { } - public void AfterUnmarshall(OpenWireFormat wireFormat) + public virtual void AfterUnmarshall(OpenWireFormat wireFormat) { } - public void SetMarshalledForm(OpenWireFormat wireFormat, byte[] data) + public virtual void SetMarshalledForm(OpenWireFormat wireFormat, byte[] data) { } - public byte[] GetMarshalledForm(OpenWireFormat wireFormat) + public virtual byte[] GetMarshalledForm(OpenWireFormat wireFormat) { return null; } diff --git a/openwire-dotnet/src/OpenWire.Client/Core/DataStreamMarshaller.cs b/openwire-dotnet/src/OpenWire.Client/Core/DataStreamMarshaller.cs index edd66725e2..557388c7f2 100755 --- a/openwire-dotnet/src/OpenWire.Client/Core/DataStreamMarshaller.cs +++ b/openwire-dotnet/src/OpenWire.Client/Core/DataStreamMarshaller.cs @@ -331,6 +331,12 @@ namespace OpenWire.Client.Core dataOut.Write(SwitchEndian(value)); } + public static void WriteLong(long value, BinaryWriter dataOut) + { + dataOut.Write(SwitchEndian(value)); + } + + /// /// Switches from one endian to the other /// @@ -361,11 +367,6 @@ namespace OpenWire.Client.Core return answer; } - public static void WriteLong(long value, BinaryWriter dataOut) - { - dataOut.Write(IPAddress.HostToNetworkOrder(value)); - } - public virtual int Marshal1Long(OpenWireFormat wireFormat, long o, BooleanStream bs) { if (o == 0L) diff --git a/openwire-dotnet/tests/OpenWire.Client/JMSPropertyTest.cs b/openwire-dotnet/tests/OpenWire.Client/JMSPropertyTest.cs index 8d1304a7df..ad3003200c 100644 --- a/openwire-dotnet/tests/OpenWire.Client/JMSPropertyTest.cs +++ b/openwire-dotnet/tests/OpenWire.Client/JMSPropertyTest.cs @@ -104,14 +104,14 @@ namespace OpenWire.Client Assert.AreEqual(custom3, message.Properties["custom3"], "custom3"); Assert.AreEqual(custom4, message.Properties["custom4"], "custom4"); // TODO - //Assert.AreEqual(custom5, message.Properties["custom5"], "custom5"); + Assert.AreEqual(custom5, message.Properties["custom5"], "custom5"); Assert.AreEqual(custom6, message.Properties["custom6"], "custom6"); 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(custom5, message.Properties.GetLong("custom5"), "custom5"); Assert.AreEqual(custom6, message.Properties.GetChar("custom6"), "custom6"); // lets now look at some standard JMS headers diff --git a/openwire-dotnet/tests/OpenWire.Client/MapMessageTest.cs b/openwire-dotnet/tests/OpenWire.Client/MapMessageTest.cs index 4e7d68cd26..51de428ec1 100644 --- a/openwire-dotnet/tests/OpenWire.Client/MapMessageTest.cs +++ b/openwire-dotnet/tests/OpenWire.Client/MapMessageTest.cs @@ -43,23 +43,53 @@ namespace OpenWire.Client protected override IMessage CreateMessage(ISession session) { - IMapMessage request = session.CreateMapMessage(); - return request; + 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; + + return message; } protected override void AssertValidMessage(IMessage message) { Assert.IsTrue(message is IMapMessage, "Did not receive a MapMessage!"); - - Console.WriteLine("Received MapMessage: " + message); - IMapMessage mapMessage = (IMapMessage) message; - /* - String text = mapMessage.Text; - Assert.AreEqual(expected, text, "the message text"); - */ + 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"); + + // 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"); + + } + protected string ToHex(long value) + { + return String.Format("{0:x}", value); + } } }