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