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.junit4.AbstractMuleContextTestCase;
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 import org.junit.Test;
27
28 import static org.junit.Assert.assertEquals;
29 import static org.junit.Assert.assertNotNull;
30 import static org.junit.Assert.assertTrue;
31
32 public class RemoteDispatcherSerializationTestCase extends AbstractMuleContextTestCase
33 {
34 protected RemoteDispatcherNotification getNotification()
35 {
36 Map<String, Object> props = new HashMap<String, Object>();
37 props.put("key1", "value1");
38
39 Apple apple = new Apple();
40 apple.wash();
41
42 MuleMessage message = new DefaultMuleMessage(apple, props, muleContext);
43 RemoteDispatcherNotification notification = new RemoteDispatcherNotification(message,
44 RemoteDispatcherNotification.ACTION_SEND, "vm://foo");
45 notification.setProperty("foo", "bar");
46 return notification;
47 }
48
49 @Test
50 public void testNotificationJavaSerialization() throws Exception
51 {
52 doTestNotificationSerialization(createObject(SerializationWireFormat.class));
53 }
54
55
56
57
58
59
60
61
62
63
64
65
66 public void doTestNotificationSerialization(WireFormat wf) throws Exception
67 {
68 ByteArrayOutputStream baos = new ByteArrayOutputStream();
69 wf.write(baos, getNotification(), "UTF-8");
70
71 Object result = wf.read(new ByteArrayInputStream(baos.toByteArray()));
72
73 assertNotNull(result);
74 assertTrue(result instanceof RemoteDispatcherNotification);
75 doTestNotification((RemoteDispatcherNotification)result);
76 }
77
78 protected void doTestNotification(RemoteDispatcherNotification n) throws Exception
79 {
80 assertEquals("bar", n.getProperty("foo"));
81 MuleMessage m = n.getMessage();
82 assertTrue(m.getPayload() instanceof Apple);
83 assertTrue(((Apple)m.getPayload()).isWashed());
84 assertEquals("value1", m.getOutboundProperty("key1"));
85
86 }
87 }