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