1
2
3
4
5
6
7
8
9
10
11 package org.mule.components.script;
12
13 import org.mule.MuleManager;
14 import org.mule.extras.client.MuleClient;
15 import org.mule.tck.FunctionalTestCase;
16 import org.mule.tck.functional.EventCallback;
17 import org.mule.tck.functional.FunctionalStreamingTestComponent;
18 import org.mule.umo.UMOEventContext;
19 import org.mule.umo.model.UMOModel;
20
21 import java.util.HashMap;
22
23 import edu.emory.mathcs.backport.java.util.concurrent.CountDownLatch;
24 import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
25 import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicReference;
26
27 public class StreamingScriptComponentTestCase extends FunctionalTestCase
28 {
29 public static final int TIMEOUT = 3000;
30
31 public static final String TEST_MESSAGE = "World";
32
33 public static final String RESULT = "Received stream; length: 11; 'Hell...orld'";
34
35 public StreamingScriptComponentTestCase()
36 {
37 setDisposeManagerPerSuite(true);
38 }
39
40 protected String getConfigResources()
41 {
42 return "groovy-streaming-test.xml";
43 }
44
45 public void testFunctionBehaviour() throws Exception
46 {
47 final CountDownLatch latch = new CountDownLatch(1);
48 final AtomicReference message = new AtomicReference();
49
50 EventCallback callback = new EventCallback()
51 {
52 public synchronized void eventReceived(UMOEventContext context, Object component)
53 {
54 try
55 {
56 FunctionalStreamingTestComponent ftc = (FunctionalStreamingTestComponent) component;
57
58 if (1 == latch.getCount())
59 {
60 message.set(ftc.getSummary());
61 assertEquals(RESULT, message.get());
62 latch.countDown();
63 }
64 }
65 catch (Exception e)
66 {
67 logger.error(e.getMessage(), e);
68 }
69 }
70 };
71
72 UMOModel model = (UMOModel) MuleManager.getInstance().getModels().get("streaming-model");
73 FunctionalStreamingTestComponent ftc = (FunctionalStreamingTestComponent) model.getComponent(
74 "testComponent").getInstance();
75 assertNotNull(ftc);
76 ftc.setEventCallback(callback, TEST_MESSAGE.length());
77
78 MuleClient client = new MuleClient();
79 client.dispatch("tcp://localhost:65432", TEST_MESSAGE, new HashMap());
80
81 latch.await(10, TimeUnit.SECONDS);
82 assertEquals(RESULT, message.get());
83 }
84 }