// /* // * 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.Text; using Apache.NMS; using Apache.NMS.Util; using Apache.NMS.Test; using Apache.NMS.Stomp.Protocol; using NUnit.Framework; namespace Apache.NMS.Stomp.Test.Protocol { [TestFixture] public class XmlPrimitiveMapMarshalerTest { private const String xmlString = @" BYTES CgoKFBQU CHAR a DOUBLE 1.5 BYTE 123 SHORT -32768 INT 5 FLOAT 1.1 LONG 256 STRING FOO BOOL true "; [Test] public void TestMarshalPrimitiveMap() { XmlPrimitiveMapMarshaler marshaler = new XmlPrimitiveMapMarshaler(); PrimitiveMap map = new PrimitiveMap(); map.SetBool("boolean", true); map.SetByte("byte", (byte)1); map["bytes1"] = new byte[1]; map.SetChar("char", 'a'); map.SetDouble("double", 1.5); map.SetFloat("float", 1.5f); map.SetInt("int", 1); map.SetLong("long", 1); map["object"] = "stringObj"; map.SetShort("short", (short)1); map.SetString("string", "string"); byte[] result = marshaler.Marshal(map); Assert.IsNotNull(result); result = marshaler.Marshal(null); Assert.IsNull(result); } [Test] public void TestUnmarshalPrimitiveMap() { XmlPrimitiveMapMarshaler marshaler = new XmlPrimitiveMapMarshaler(); byte[] rawBytes = Encoding.UTF8.GetBytes(xmlString); IPrimitiveMap result = marshaler.Unmarshal(rawBytes); Assert.IsNotNull(result); Assert.IsTrue(result.Contains("BOOL")); Assert.IsTrue(result.Contains("BYTES")); Assert.IsTrue(result.Contains("STRING")); Assert.IsTrue(result.Contains("LONG")); Assert.IsTrue(result.Contains("FLOAT")); Assert.IsTrue(result.Contains("INT")); Assert.IsTrue(result.Contains("BYTE")); Assert.IsTrue(result.Contains("SHORT")); Assert.IsTrue(result.Contains("DOUBLE")); Assert.IsTrue(result.Contains("CHAR")); } } }