View Javadoc

1   /*
2    * $Id: RemoteDispatcherSerializationTestCase.java 20321 2010-11-24 15:21:24Z dfeist $
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.test.integration.client;
12  
13  import org.mule.DefaultMuleMessage;
14  import org.mule.api.MuleMessage;
15  import org.mule.api.transformer.wire.WireFormat;
16  import org.mule.module.client.remoting.notification.RemoteDispatcherNotification;
17  import org.mule.tck.AbstractMuleTestCase;
18  import org.mule.tck.testmodels.fruit.Apple;
19  import org.mule.transformer.wire.SerializationWireFormat;
20  
21  import java.io.ByteArrayInputStream;
22  import java.io.ByteArrayOutputStream;
23  import java.util.HashMap;
24  import java.util.Map;
25  
26  public class RemoteDispatcherSerializationTestCase extends AbstractMuleTestCase
27  {
28      protected RemoteDispatcherNotification getNotification()
29      {
30          Map<String, Object> props = new HashMap<String, Object>();
31          props.put("key1", "value1");
32          
33          Apple apple = new Apple();
34          apple.wash();
35          
36          MuleMessage message = new DefaultMuleMessage(apple, props, muleContext);
37          RemoteDispatcherNotification notification = new RemoteDispatcherNotification(message,
38              RemoteDispatcherNotification.ACTION_SEND, "vm://foo");
39          notification.setProperty("foo", "bar");
40          return notification;
41      }
42      
43      public void testNotificationJavaSerialization() throws Exception
44      {
45          doTestNotificationSerialization(createObject(SerializationWireFormat.class));
46      }
47  
48      // TODO MULE-3118
49  //    public void testNotificationXmlSerialization() throws Exception
50  //    {
51  //        XStreamWireFormat wireFormat = new XStreamWireFormat();
52  //        wireFormat.setMuleContext(muleContext);
53  //        wireFormat.setTransferObjectClass(RemoteDispatcherNotification.class);
54  //
55  //        doTestNotificationSerialization(wireFormat);
56  //    }            
57  
58      public void doTestNotificationSerialization(WireFormat wf) throws Exception
59      {
60          ByteArrayOutputStream baos = new ByteArrayOutputStream();
61          wf.write(baos, getNotification(), "UTF-8");
62  
63          Object result = wf.read(new ByteArrayInputStream(baos.toByteArray()));
64  
65          assertNotNull(result);
66          assertTrue(result instanceof RemoteDispatcherNotification);
67          doTestNotification((RemoteDispatcherNotification)result);
68      }
69  
70      protected void doTestNotification(RemoteDispatcherNotification n) throws Exception
71      {
72          assertEquals("bar", n.getProperty("foo"));
73          MuleMessage m = n.getMessage();
74          assertTrue(m.getPayload() instanceof Apple);
75          assertTrue(((Apple)m.getPayload()).isWashed());
76          assertEquals("value1", m.getOutboundProperty("key1"));
77  
78      }
79  }