View Javadoc

1   /*
2    * $Id: XStreamWireFormatTestCase.java 22377 2011-07-11 12:41:42Z dirk.olmes $
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  import static org.junit.Assert.assertEquals;
24  import static org.junit.Assert.assertTrue;
25  
26  public class XStreamWireFormatTestCase extends AbstractMuleMessageWireFormatTestCase
27  {
28  
29      protected WireFormat getWireFormat() throws Exception
30      {
31          return createObject(XStreamWireFormat.class);
32      }
33  
34      @Override
35      public void testGetDefaultInboundTransformer() throws Exception
36      {
37          assertEquals(XmlToObject.class, ((XStreamWireFormat) getWireFormat()).getInboundTransformer().getClass());
38      }
39  
40      @Override
41      public void testGetDefaultOutboundTransformer() throws Exception
42      {
43          assertEquals(ObjectToXml.class, ((XStreamWireFormat) getWireFormat()).getOutboundTransformer().getClass());
44      }
45  
46      @Override
47      public void testWriteReadPayload() throws Exception
48      {
49          // Create orange to send over the wire
50          Properties messageProerties = new Properties();
51          messageProerties.put("key1", "val1");
52          Orange inOrange = new Orange();
53          inOrange.setBrand("Walmart");
54          inOrange.setMapProperties(messageProerties);
55  
56          Object outObject = readWrite(inOrange);
57  
58          // Test deserialized Fruit
59          // TODO This wire-format wraps desrialized payloads in a message. See
60          // MULE-3118
61          // See test implementation in AbstractMuleMessageWireFormatTestCase.
62          assertTrue(outObject instanceof MuleMessage);
63          assertEquals("Walmart", ((Orange) ((MuleMessage) outObject).getPayload()).getBrand());
64          assertEquals("val1", ((Orange) ((MuleMessage) outObject).getPayload()).getMapProperties().get("key1"));
65      }
66  
67  }