1   /*
2    * $Id: XStreamWireFormatTestCase.java 11377 2008-03-16 18:18:33Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.transformers.xml.wire;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.api.transformer.wire.WireFormat;
15  import org.mule.module.xml.transformer.ObjectToXml;
16  import org.mule.module.xml.transformer.XmlToObject;
17  import org.mule.module.xml.transformer.wire.XStreamWireFormat;
18  import org.mule.tck.testmodels.fruit.Orange;
19  import org.mule.transformer.wire.AbstractMuleMessageWireFormatTestCase;
20  
21  import java.util.Properties;
22  
23  public class XStreamWireFormatTestCase extends AbstractMuleMessageWireFormatTestCase
24  {
25  
26      protected WireFormat getWireFormat() throws IllegalAccessException, InstantiationException, ClassNotFoundException
27      {
28          return new XStreamWireFormat();
29      }
30  
31      public void testGetDefaultInboundTransformer()
32          throws IllegalAccessException, InstantiationException, ClassNotFoundException
33      {
34          assertEquals(XmlToObject.class, ((XStreamWireFormat) getWireFormat()).getInboundTransformer().getClass());
35  
36      }
37  
38      public void testGetDefaultOutboundTransformer()
39          throws IllegalAccessException, InstantiationException, ClassNotFoundException
40      {
41          assertEquals(ObjectToXml.class, ((XStreamWireFormat) getWireFormat()).getOutboundTransformer().getClass());
42      }
43  
44      public void testWriteReadPayload() throws Exception
45      {
46          // Create orange to send over the wire
47          Properties messageProerties = new Properties();
48          messageProerties.put("key1", "val1");
49          Orange inOrange = new Orange();
50          inOrange.setBrand("Walmart");
51          inOrange.setMapProperties(messageProerties);
52  
53          Object outObject = readWrite(inOrange);
54  
55          // Test deserialized Fruit
56          // TODO This wire-format wraps desrialized payloads in a message. See
57          // MULE-3118
58          // See test implementation in AbstractMuleMessageWireFormatTestCase.
59          assertTrue(outObject instanceof MuleMessage);
60          assertEquals("Walmart", ((Orange) ((MuleMessage) outObject).getPayload()).getBrand());
61          assertEquals("val1", ((Orange) ((MuleMessage) outObject).getPayload()).getMapProperties().get("key1"));
62      }
63  
64  }