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