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