View Javadoc

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