View Javadoc

1   /*
2    * $Id: XStreamWireFormatTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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 Exception
27      {
28          return createObject(XStreamWireFormat.class);
29      }
30  
31      public void testGetDefaultInboundTransformer() throws Exception
32      {
33          assertEquals(XmlToObject.class, ((XStreamWireFormat) getWireFormat()).getInboundTransformer().getClass());
34      }
35  
36      public void testGetDefaultOutboundTransformer() throws Exception
37      {
38          assertEquals(ObjectToXml.class, ((XStreamWireFormat) getWireFormat()).getOutboundTransformer().getClass());
39      }
40  
41      @Override
42      public void testWriteReadPayload() throws Exception
43      {
44          // Create orange to send over the wire
45          Properties messageProerties = new Properties();
46          messageProerties.put("key1", "val1");
47          Orange inOrange = new Orange();
48          inOrange.setBrand("Walmart");
49          inOrange.setMapProperties(messageProerties);
50  
51          Object outObject = readWrite(inOrange);
52  
53          // Test deserialized Fruit
54          // TODO This wire-format wraps desrialized payloads in a message. See
55          // MULE-3118
56          // See test implementation in AbstractMuleMessageWireFormatTestCase.
57          assertTrue(outObject instanceof MuleMessage);
58          assertEquals("Walmart", ((Orange) ((MuleMessage) outObject).getPayload()).getBrand());
59          assertEquals("val1", ((Orange) ((MuleMessage) outObject).getPayload()).getMapProperties().get("key1"));
60      }
61  
62  }