View Javadoc

1   /*
2    * $Id: AbstractMuleMessageWireFormatTestCase.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.transformer.wire;
12  
13  import org.mule.DefaultMuleMessage;
14  import org.mule.api.MuleMessage;
15  import org.mule.tck.testmodels.fruit.Orange;
16  
17  import java.util.HashMap;
18  import java.util.Map;
19  import java.util.Properties;
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  }