1
2
3
4
5
6
7
8
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
49
50
51
52
53
54
55
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 }