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.transformer.wire;
8   
9   import org.mule.DefaultMuleMessage;
10  import org.mule.api.MuleMessage;
11  import org.mule.tck.testmodels.fruit.Orange;
12  
13  import java.util.HashMap;
14  import java.util.Map;
15  import java.util.Properties;
16  
17  import static org.junit.Assert.assertEquals;
18  import static org.junit.Assert.assertTrue;
19  import static org.junit.Assert.fail;
20  
21  public abstract class AbstractMuleMessageWireFormatTestCase extends AbstractWireFormatTestCase
22  {
23  
24      @Override
25      public void testWriteReadMessage() throws Exception
26      {
27          // Create message to send over wire
28          Map<String, Object> messageProerties = new HashMap<String, Object>();
29          messageProerties.put("key1", "val1");
30          MuleMessage inMessage = new DefaultMuleMessage("testMessage", messageProerties, muleContext);
31  
32          Object outMessage = readWrite(inMessage);
33  
34          // Test deserialized message
35          // NOTE: As we are using SerializedMuleMessageWireFormat we get
36          // MuleMessage rather than just the payload
37  
38          assertTrue(outMessage instanceof MuleMessage);
39          assertEquals("testMessage", ((MuleMessage) outMessage).getPayload());
40          assertEquals("val1", ((MuleMessage) outMessage).getOutboundProperty("key1"));
41      }
42  
43      @Override
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          try
54          {
55              readWrite(inOrange);
56              fail("Expected exception: MuleMessageWireFormat does not support other types");
57          }
58          catch (Exception e)
59          {
60              // Expected
61          }
62      }
63  
64  }