1
2
3
4
5
6
7
8
9
10
11 package org.mule.module.sxc;
12
13 import org.mule.api.MuleException;
14 import org.mule.api.MuleMessage;
15 import org.mule.module.client.MuleClient;
16 import org.mule.tck.FunctionalTestCase;
17
18 import org.apache.commons.io.IOUtils;
19
20 public class SxcFilterTestCase extends FunctionalTestCase
21 {
22 int finished = 0;
23
24 public void testBasicXPath() throws Exception
25 {
26 final MuleClient client = new MuleClient(muleContext);
27
28 final String testData = IOUtils.toString(getClass().getResourceAsStream("/purchase-order.xml"));
29
30 MuleMessage res = client.send("vm://in", testData, null);
31 assertEquals(Boolean.TRUE, res.getPayload());
32 }
33
34 public void testAndFilter() throws Exception
35 {
36 final MuleClient client = new MuleClient(muleContext);
37
38 final String testData = IOUtils.toString(getClass().getResourceAsStream("/purchase-order.xml"));
39
40 MuleMessage res = client.send("vm://and-filter", testData, null);
41
42 assertEquals(Boolean.TRUE, res.getPayload());
43 }
44
45 public void testOrFilter() throws Exception
46 {
47 final MuleClient client = new MuleClient(muleContext);
48
49 final String testData = IOUtils.toString(getClass().getResourceAsStream("/purchase-order.xml"));
50
51 MuleMessage res = client.send("vm://or-filter", testData, null);
52
53 assertEquals(Boolean.TRUE, res.getPayload());
54 }
55
56 public void testNotFilter() throws Exception
57 {
58 final MuleClient client = new MuleClient(muleContext);
59
60 final String testData = IOUtils.toString(getClass().getResourceAsStream("/purchase-order.xml"));
61
62 MuleMessage res = client.send("vm://not-filter", testData, null);
63
64 assertEquals(Boolean.TRUE, res.getPayload());
65 }
66
67 public void xtestBenchmark() throws Exception
68 {
69 final MuleClient client = new MuleClient(muleContext);
70
71 final String testData = IOUtils.toString(getClass().getResourceAsStream("/purchase-order.xml"));
72
73 System.out.println("Warmup");
74 fire(client, testData, 1500);
75
76 System.out.println("Running....");
77
78 fire(client, testData, 1000);
79
80 Thread.sleep(1000);
81 }
82
83 private void fire(final MuleClient client, final String testData, final int count)
84 throws InterruptedException
85 {
86 long time = System.currentTimeMillis();
87 finished = 0;
88 for (int i = 0; i < 10; i++)
89 {
90 new Thread(new Runnable()
91 {
92 public void run()
93 {
94 for (int j = 0; j < count; j++)
95 {
96 try
97 {
98 client.send("vm://in", testData, null);
99 }
100 catch (MuleException e)
101 {
102 fail("Exception in worker thread");
103 }
104 }
105 finished++;
106 }
107 }).start();
108 }
109
110 while (finished < 10)
111 {
112 Thread.sleep(100);
113 }
114 System.out.println("elapsed " + (System.currentTimeMillis() - time));
115
116 }
117
118 @Override
119 protected String getConfigResources()
120 {
121 return "xpath-filter-conf.xml";
122 }
123
124 }