View Javadoc

1   /*
2    * $Id: AbstractMuleMessageWireFormatTestCase.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.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  import static org.junit.Assert.assertEquals;
22  import static org.junit.Assert.assertTrue;
23  import static org.junit.Assert.fail;
24  
25  public abstract class AbstractMuleMessageWireFormatTestCase extends AbstractWireFormatTestCase
26  {
27  
28      @Override
29      public void testWriteReadMessage() throws Exception
30      {
31          // Create message to send over wire
32          Map<String, Object> messageProerties = new HashMap<String, Object>();
33          messageProerties.put("key1", "val1");
34          MuleMessage inMessage = new DefaultMuleMessage("testMessage", messageProerties, muleContext);
35  
36          Object outMessage = readWrite(inMessage);
37  
38          // Test deserialized message
39          // NOTE: As we are using SerializedMuleMessageWireFormat we get
40          // MuleMessage rather than just the payload
41  
42          assertTrue(outMessage instanceof MuleMessage);
43          assertEquals("testMessage", ((MuleMessage) outMessage).getPayload());
44          assertEquals("val1", ((MuleMessage) outMessage).getOutboundProperty("key1"));
45      }
46  
47      @Override
48      public void testWriteReadPayload() throws Exception
49      {
50          // Create orange to send over the wire
51          Properties messageProerties = new Properties();
52          messageProerties.put("key1", "val1");
53          Orange inOrange = new Orange();
54          inOrange.setBrand("Walmart");
55          inOrange.setMapProperties(messageProerties);
56  
57          try
58          {
59              readWrite(inOrange);
60              fail("Expected exception: MuleMessageWireFormat does not support other types");
61          }
62          catch (Exception e)
63          {
64              // Expected
65          }
66      }
67  
68  }