1
2
3
4
5
6
7 package org.mule.issues;
8
9 import org.mule.api.MuleException;
10 import org.mule.api.MuleMessage;
11 import org.mule.module.client.MuleClient;
12 import org.mule.module.xml.functional.AbstractXmlFunctionalTestCase;
13
14 import org.junit.Test;
15
16 import static org.junit.Assert.assertEquals;
17 import static org.junit.Assert.assertNotNull;
18 import static org.junit.Assert.assertTrue;
19
20
21
22
23
24
25 public class MulticastRouterMule2136TestCase extends AbstractXmlFunctionalTestCase
26 {
27
28 public static final int TEST_COUNT = 2000;
29 public static final String SERIALIZED = "<org.mule.issues.MulticastRouterMule2136TestCase_-Parent>\n" +
30 " <child/>\n" +
31 "</org.mule.issues.MulticastRouterMule2136TestCase_-Parent>";
32
33 @Override
34 protected String getConfigResources()
35 {
36 return "org/mule/issues/multicast-router-mule-2136-test.xml";
37 }
38
39 protected MuleClient sendObject() throws MuleException
40 {
41 MuleClient client = new MuleClient(muleContext);
42 client.dispatch("object-in", new Parent(new Child()), null);
43 return client;
44 }
45
46 @Test
47 public void testObjectOut() throws MuleException, InterruptedException
48 {
49 request(sendObject(), "object-out", Parent.class);
50
51 Thread.sleep(3000);
52 }
53
54 @Test
55 public void testObjectXmlOut() throws MuleException
56 {
57 String xml = (String) request(sendObject(), "object-xml-out", String.class);
58 assertEquals(SERIALIZED, xml);
59 }
60
61 @Test
62 public void testXmlObjectOut() throws MuleException
63 {
64 request(sendObject(), "xml-object-out", Parent.class);
65 }
66
67 @Test
68 public void testStress() throws MuleException
69 {
70 int tenth = TEST_COUNT / 10;
71 for (int i = 0; i < TEST_COUNT; i++)
72 {
73 testObjectXmlOut();
74
75
76
77 request(new MuleClient(muleContext), "xml-object-out", Parent.class);
78
79 if (i % tenth == 0)
80 {
81 logger.info("Iteration " + i);
82 }
83 }
84 }
85
86 protected Object request(MuleClient client, String endpoint, Class<?> clazz) throws MuleException
87 {
88 MuleMessage message = client.request(endpoint, TIMEOUT);
89 assertNotNull(message);
90 assertNotNull(message.getPayload());
91
92 Class<?> payloadClass = message.getPayload().getClass();
93 String assertionMessage = String.format("expected payload of type %1s but was %2s", clazz.getName(), payloadClass);
94 assertTrue(assertionMessage, clazz.isAssignableFrom(payloadClass));
95 return message.getPayload();
96 }
97
98 public static class Parent
99 {
100 private Child child;
101
102 public Parent()
103 {
104 this(null);
105 }
106
107 public Parent(Child child)
108 {
109 setChild(child);
110 }
111
112 public Child getChild()
113 {
114 return child;
115 }
116
117 public void setChild(Child child)
118 {
119 this.child = child;
120 }
121 }
122
123 public static class Child
124 {
125
126 }
127
128 }