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
This commit is contained in:
James Strachan 2006-02-24 13:16:09 +00:00
parent 76494afa3f
commit 7130f43c8f
5 changed files with 64 additions and 29 deletions

View File

@ -45,16 +45,20 @@ namespace OpenWire.Client.Commands
} }
} }
public void BeforeMarshall(OpenWireFormat wireFormat) public override void BeforeMarshall(OpenWireFormat wireFormat)
{
if (body == null)
{ {
base.BeforeMarshall(wireFormat);
if (body == null) {
Content = null; Content = null;
} }
else { else
{
Content = body.Marshal(); Content = body.Marshal();
} }
Console.WriteLine("BeforeMarshalling, content is: " + Content);
base.BeforeMarshall(wireFormat);
} }
} }

View File

@ -277,7 +277,7 @@ namespace OpenWire.Client.Commands
return true; return true;
} }
public void BeforeMarshall(OpenWireFormat wireFormat) public virtual void BeforeMarshall(OpenWireFormat wireFormat)
{ {
MarshalledProperties = null; MarshalledProperties = null;
if (properties != 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; return null;
} }

View File

@ -331,6 +331,12 @@ namespace OpenWire.Client.Core
dataOut.Write(SwitchEndian(value)); dataOut.Write(SwitchEndian(value));
} }
public static void WriteLong(long value, BinaryWriter dataOut)
{
dataOut.Write(SwitchEndian(value));
}
/// <summary> /// <summary>
/// Switches from one endian to the other /// Switches from one endian to the other
/// </summary> /// </summary>
@ -361,11 +367,6 @@ namespace OpenWire.Client.Core
return answer; 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) public virtual int Marshal1Long(OpenWireFormat wireFormat, long o, BooleanStream bs)
{ {
if (o == 0L) if (o == 0L)

View File

@ -104,14 +104,14 @@ namespace OpenWire.Client
Assert.AreEqual(custom3, message.Properties["custom3"], "custom3"); Assert.AreEqual(custom3, message.Properties["custom3"], "custom3");
Assert.AreEqual(custom4, message.Properties["custom4"], "custom4"); Assert.AreEqual(custom4, message.Properties["custom4"], "custom4");
// TODO // TODO
//Assert.AreEqual(custom5, message.Properties["custom5"], "custom5"); Assert.AreEqual(custom5, message.Properties["custom5"], "custom5");
Assert.AreEqual(custom6, message.Properties["custom6"], "custom6"); Assert.AreEqual(custom6, message.Properties["custom6"], "custom6");
Assert.AreEqual(custom1, message.Properties.GetBool("custom1"), "custom1"); Assert.AreEqual(custom1, message.Properties.GetBool("custom1"), "custom1");
Assert.AreEqual(custom2, message.Properties.GetByte("custom2"), "custom2"); Assert.AreEqual(custom2, message.Properties.GetByte("custom2"), "custom2");
Assert.AreEqual(custom3, message.Properties.GetShort("custom3"), "custom3"); Assert.AreEqual(custom3, message.Properties.GetShort("custom3"), "custom3");
Assert.AreEqual(custom4, message.Properties.GetInt("custom4"), "custom4"); 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"); Assert.AreEqual(custom6, message.Properties.GetChar("custom6"), "custom6");
// lets now look at some standard JMS headers // lets now look at some standard JMS headers

View File

@ -43,23 +43,53 @@ namespace OpenWire.Client
protected override IMessage CreateMessage(ISession session) protected override IMessage CreateMessage(ISession session)
{ {
IMapMessage request = session.CreateMapMessage(); IMapMessage message = session.CreateMapMessage();
return request;
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) protected override void AssertValidMessage(IMessage message)
{ {
Assert.IsTrue(message is IMapMessage, "Did not receive a MapMessage!"); Assert.IsTrue(message is IMapMessage, "Did not receive a MapMessage!");
Console.WriteLine("Received MapMessage: " + message);
IMapMessage mapMessage = (IMapMessage) message; IMapMessage mapMessage = (IMapMessage) message;
/* Console.WriteLine("Received MapMessage: " + message);
String text = mapMessage.Text; Console.WriteLine("Received Count: " + mapMessage.Body.Count);
Assert.AreEqual(expected, text, "the message text");
*/ 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);
}
}
} }