public void TestGetBoolean() { ActiveMQMapMessage msg = new ActiveMQMapMessage(); msg.Body.SetBool(name, true); msg.ReadOnlyBody = true; Assert.IsTrue(msg.Body.GetBool(name)); msg.ClearBody(); msg.Body.SetString(name, "True"); msg = (ActiveMQMapMessage)msg.Clone(); Assert.IsTrue(msg.Body.GetBool(name)); }
public void TestBytesConversion() { ActiveMQMapMessage msg = new ActiveMQMapMessage(); msg.Body.SetBool("boolean", true); msg.Body.SetByte("byte", (byte)1); msg.Body["bytes"] = new byte[1]; msg.Body.SetChar("char", 'a'); msg.Body.SetDouble("double", 1.5); msg.Body.SetFloat("float", 1.5f); msg.Body.SetInt("int", 1); msg.Body.SetLong("long", 1); msg.Body["object"] = "stringObj"; msg.Body.SetShort("short", (short)1); msg.Body.SetString("string", "string"); // Test with a 1Meg String StringBuilder bigSB = new StringBuilder(1024 * 1024); for(int i = 0; i < 1024 * 1024; i++) { bigSB.Append((char)'a' + i % 26); } String bigString = bigSB.ToString(); msg.Body.SetString("bigString", bigString); msg = (ActiveMQMapMessage)msg.Clone(); Assert.AreEqual(msg.Body.GetBool("boolean"), true); Assert.AreEqual(msg.Body.GetByte("byte"), (byte)1); Assert.AreEqual((msg.Body["bytes"] as byte[]).Length, 1); Assert.AreEqual(msg.Body.GetChar("char"), 'a'); Assert.AreEqual(msg.Body.GetDouble("double"), 1.5, 0); Assert.AreEqual(msg.Body.GetFloat("float"), 1.5f, 0); Assert.AreEqual(msg.Body.GetInt("int"), 1); Assert.AreEqual(msg.Body.GetLong("long"), 1); Assert.AreEqual(msg.Body["object"], "stringObj"); Assert.AreEqual(msg.Body.GetShort("short"), (short)1); Assert.AreEqual(msg.Body.GetString("string"), "string"); Assert.AreEqual(msg.Body.GetString("bigString"), bigString); }
public void TestGetShort() { ActiveMQMapMessage msg = new ActiveMQMapMessage(); try { msg.Body.SetShort(this.name, (short)1); msg = (ActiveMQMapMessage)msg.Clone(); Assert.IsTrue(msg.Body.GetShort(this.name) == (short)1); } catch(NMSException) { Assert.IsTrue(false); } }
public void TestGetByte() { ActiveMQMapMessage msg = new ActiveMQMapMessage(); msg.Body.SetByte(this.name, (byte)1); msg = (ActiveMQMapMessage)msg.Clone(); Assert.IsTrue(msg.Body.GetByte(this.name) == (byte)1); }
public void TestClearBody() { ActiveMQMapMessage mapMessage = new ActiveMQMapMessage(); mapMessage.Body.SetString("String", "String"); mapMessage.ClearBody(); Assert.IsFalse(mapMessage.ReadOnlyBody); mapMessage.OnSend(); mapMessage.Content = mapMessage.Content; Assert.IsNull(mapMessage.Body.GetString("String")); mapMessage.ClearBody(); mapMessage.Body.SetString("String", "String"); mapMessage = (ActiveMQMapMessage)mapMessage.Clone(); mapMessage.Body.GetString("String"); }
public void TestItemExists() { ActiveMQMapMessage mapMessage = new ActiveMQMapMessage(); mapMessage.Body.SetString("exists", "test"); mapMessage = (ActiveMQMapMessage)mapMessage.Clone(); Assert.IsTrue(mapMessage.Body.Contains("exists")); Assert.IsFalse(mapMessage.Body.Contains("doesntExist")); }
public void TestGetMapNames() { ActiveMQMapMessage msg = new ActiveMQMapMessage(); msg.Body.SetBool("boolean", true); msg.Body.SetByte("byte", (byte)1); msg.Body["bytes1"] = new byte[1]; msg.Body.SetChar("char", 'a'); msg.Body.SetDouble("double", 1.5); msg.Body.SetFloat("float", 1.5f); msg.Body.SetInt("int", 1); msg.Body.SetLong("long", 1); msg.Body["object"] = "stringObj"; msg.Body.SetShort("short", (short)1); msg.Body.SetString("string", "string"); msg = (ActiveMQMapMessage)msg.Clone(); ICollection mapNames = msg.Body.Keys; System.Collections.ArrayList mapNamesList = new System.Collections.ArrayList(mapNames); Assert.AreEqual(mapNamesList.Count, 11); Assert.IsTrue(mapNamesList.Contains("boolean")); Assert.IsTrue(mapNamesList.Contains("byte")); Assert.IsTrue(mapNamesList.Contains("bytes1")); Assert.IsTrue(mapNamesList.Contains("char")); Assert.IsTrue(mapNamesList.Contains("double")); Assert.IsTrue(mapNamesList.Contains("float")); Assert.IsTrue(mapNamesList.Contains("int")); Assert.IsTrue(mapNamesList.Contains("long")); Assert.IsTrue(mapNamesList.Contains("object")); Assert.IsTrue(mapNamesList.Contains("short")); Assert.IsTrue(mapNamesList.Contains("string")); }
public void TestGetObject() { ActiveMQMapMessage msg = new ActiveMQMapMessage(); Boolean booleanValue = true; Byte byteValue = Byte.Parse("1"); byte[] bytesValue = new byte[3]; Char charValue = (Char) 'a'; Double doubleValue = Double.Parse("1.5", CultureInfo.InvariantCulture); Single floatValue = Single.Parse("1.5", CultureInfo.InvariantCulture); Int32 intValue = Int32.Parse("1"); Int64 longValue = Int64.Parse("1"); Int16 shortValue = Int16.Parse("1"); String stringValue = "string"; try { msg.Body["boolean"] = booleanValue; msg.Body["byte"] = byteValue; msg.Body["bytes"] = bytesValue; msg.Body["char"] = charValue; msg.Body["double"] = doubleValue; msg.Body["float"] = floatValue; msg.Body["int"] = intValue; msg.Body["long"] = longValue; msg.Body["short"] = shortValue; msg.Body["string"] = stringValue; } catch(MessageFormatException) { Assert.Fail("object formats should be correct"); } msg = (ActiveMQMapMessage)msg.Clone(); Assert.IsTrue(msg.Body["boolean"] is Boolean); Assert.AreEqual(msg.Body["boolean"], booleanValue); Assert.AreEqual(msg.Body.GetBool("boolean"), booleanValue); Assert.IsTrue(msg.Body["byte"] is Byte); Assert.AreEqual(msg.Body["byte"], byteValue); Assert.AreEqual(msg.Body.GetByte("byte"), byteValue); Assert.IsTrue(msg.Body["bytes"] is byte[]); Assert.AreEqual(((byte[])msg.Body["bytes"]).Length, bytesValue.Length); Assert.AreEqual((msg.Body["bytes"] as byte[]).Length, bytesValue.Length); Assert.IsTrue(msg.Body["char"] is Char); Assert.AreEqual(msg.Body["char"], charValue); Assert.AreEqual(msg.Body.GetChar("char"), charValue); Assert.IsTrue(msg.Body["double"] is Double); Assert.AreEqual(msg.Body["double"], doubleValue); Assert.AreEqual(msg.Body.GetDouble("double"), doubleValue, 0); Assert.IsTrue(msg.Body["float"] is Single); Assert.AreEqual(msg.Body["float"], floatValue); Assert.AreEqual(msg.Body.GetFloat("float"), floatValue, 0); Assert.IsTrue(msg.Body["int"] is Int32); Assert.AreEqual(msg.Body["int"], intValue); Assert.AreEqual(msg.Body.GetInt("int"), intValue); Assert.IsTrue(msg.Body["long"] is Int64); Assert.AreEqual(msg.Body["long"], longValue); Assert.AreEqual(msg.Body.GetLong("long"), longValue); Assert.IsTrue(msg.Body["short"] is Int16); Assert.AreEqual(msg.Body["short"], shortValue); Assert.AreEqual(msg.Body.GetShort("short"), shortValue); Assert.IsTrue(msg.Body["string"] is String); Assert.AreEqual(msg.Body["string"], stringValue); Assert.AreEqual(msg.Body.GetString("string"), stringValue); msg.ClearBody(); try { msg.Body["object"] = new Object(); Assert.Fail("should have thrown exception"); } catch(MessageFormatException) { } }
public void TestGetBytes() { ActiveMQMapMessage msg = new ActiveMQMapMessage(); try { byte[] bytes1 = new byte[3]; byte[] bytes2 = new byte[2]; System.Array.Copy(bytes1, 0, bytes2, 0, 2); msg.Body[this.name] = bytes1; msg.Body[this.name + "2"] = bytes2; msg = (ActiveMQMapMessage)msg.Clone(); Assert.IsTrue(System.Array.Equals(msg.Body[this.name], bytes1)); Assert.AreEqual(((byte[]) msg.Body[this.name + "2"]).Length, bytes2.Length); } catch(NMSException) { Assert.IsTrue(false); } }
public void TestGetString() { ActiveMQMapMessage msg = new ActiveMQMapMessage(); try { String str = "test"; msg.Body.SetString(this.name, str); msg = (ActiveMQMapMessage)msg.Clone(); Assert.AreEqual(msg.Body.GetString(this.name), str); } catch(NMSException) { Assert.IsTrue(false); } }