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.LinkedList;
20 import java.util.List;
21
22 import org.dom4j.Document;
23 import org.dom4j.Element;
24
25 public abstract class AbstractXmlSplitterOutboundFunctionalTestCase extends AbstractXmlFunctionalTestCase
26 {
27
28 public static final String SERVICE_SPLITTER = "service splitter";
29 public static final String ROUND_ROBIN_DET = "round robin deterministic";
30 public static final String ROUND_ROBIN_INDET = "round robin indeterministic";
31 public static final String SPLITTER_ENDPOINT_PREFIX = "service";
32 public static final String ROUND_ROBIN_ENDPOINT_PREFIX = "robin";
33 public static final String NAME = "name";
34
35 protected String getConfigResources()
36 {
37 return "org/mule/module/xml/xml-outbound-functional-test.xml";
38 }
39
40 protected void doSend(String endpoint) throws IOException, MuleException
41 {
42 String xml = getConfigAsString();
43 MuleClient client = new MuleClient(muleContext);
44 client.dispatch(endpoint, xml, null);
45 }
46
47 protected void assertService(String prefix, int index, String service) throws MuleException, IOException
48 {
49 MuleClient client = new MuleClient(muleContext);
50 MuleMessage response = client.request(prefix + index, TIMEOUT);
51 assertNotNull(response);
52 assertNotNull(response.getPayload());
53 assertTrue(response.getPayload().getClass().getName(), response.getPayload() instanceof Document);
54 Document document = (Document) response.getPayload();
55 assertEquals("service", document.getRootElement().getName());
56 Element element = document.getRootElement();
57 assertEquals(service, element.attributeValue(NAME));
58 }
59
60 protected void assertServices(String prefix, int index, String[] services) throws MuleException, IOException
61 {
62 List remaining = new LinkedList(Arrays.asList(services));
63 while (remaining.size() > 0)
64 {
65 MuleClient client = new MuleClient(muleContext);
66 MuleMessage response = client.request(prefix + index, TIMEOUT);
67 assertNotNull(response);
68 assertNotNull(response.getPayload());
69 assertTrue(response.getPayload().getClass().getName(), response.getPayload() instanceof Document);
70 Document document = (Document) response.getPayload();
71 assertEquals("service", document.getRootElement().getName());
72 Element element = document.getRootElement();
73 String name = element.attributeValue(NAME);
74 assertTrue(name, remaining.contains(name));
75 int size = remaining.size();
76 remaining.remove(name);
77
78
79 assertEquals(size, remaining.size() + 1);
80 }
81 }
82
83 }