1
2
3
4
5
6
7
8
9
10
11 package org.mule.module.xml.functional;
12
13 import org.mule.api.MuleException;
14 import org.mule.api.MuleMessage;
15 import org.mule.module.client.MuleClient;
16
17 import java.io.IOException;
18 import java.util.Arrays;
19 import java.util.Collection;
20 import java.util.LinkedList;
21 import java.util.List;
22
23 import org.dom4j.Document;
24 import org.dom4j.Element;
25 import org.junit.runners.Parameterized.Parameters;
26
27 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.assertNotNull;
29 import static org.junit.Assert.assertTrue;
30
31 public abstract class AbstractXmlSplitterOutboundFunctionalTestCase extends AbstractXmlFunctionalTestCase
32 {
33 public static final String SERVICE_SPLITTER = "service splitter";
34 public static final String ROUND_ROBIN_DET = "round robin deterministic";
35 public static final String ROUND_ROBIN_INDET = "round robin indeterministic";
36 public static final String SPLITTER_ENDPOINT_PREFIX = "service";
37 public static final String ROUND_ROBIN_ENDPOINT_PREFIX = "robin";
38 public static final String NAME = "name";
39
40 public AbstractXmlSplitterOutboundFunctionalTestCase(ConfigVariant variant, String configResources)
41 {
42 super(variant, configResources);
43 }
44
45 @Parameters
46 public static Collection<Object[]> parameters()
47 {
48 return Arrays.asList(new Object[][]{
49 {ConfigVariant.SERVICE, "org/mule/module/xml/xml-outbound-functional-test.xml"}
50
51 });
52 }
53
54 protected void doSend(String endpoint) throws IOException, MuleException
55 {
56 String xml = getConfigAsString();
57 MuleClient client = new MuleClient(muleContext);
58 client.dispatch(endpoint, xml, null);
59 }
60
61 protected void assertService(String prefix, int index, String service) throws MuleException, IOException
62 {
63 MuleClient client = new MuleClient(muleContext);
64 MuleMessage response = client.request(prefix + index, TIMEOUT);
65 assertNotNull(response);
66 assertNotNull(response.getPayload());
67 assertTrue(response.getPayload().getClass().getName(), response.getPayload() instanceof Document);
68 Document document = (Document) response.getPayload();
69 assertEquals("service", document.getRootElement().getName());
70 Element element = document.getRootElement();
71 assertEquals(service, element.attributeValue(NAME));
72 }
73
74 protected void assertServices(String prefix, int index, String[] services)
75 throws MuleException, IOException
76 {
77 List remaining = new LinkedList(Arrays.asList(services));
78
79 while (remaining.size() > 0)
80 {
81 MuleClient client = new MuleClient(muleContext);
82 MuleMessage response = client.request(prefix + index, TIMEOUT);
83 assertNotNull(response);
84 assertNotNull(response.getPayload());
85 assertTrue(response.getPayload().getClass().getName(), response.getPayload() instanceof Document);
86 Document document = (Document) response.getPayload();
87 assertEquals("service", document.getRootElement().getName());
88 Element element = document.getRootElement();
89 String name = element.attributeValue(NAME);
90 assertTrue(name, remaining.contains(name));
91 int size = remaining.size();
92 remaining.remove(name);
93
94
95 assertEquals(size, remaining.size() + 1);
96 }
97 }
98
99 }