1
2
3
4
5
6
7
8
9
10
11 package org.mule.providers.ftp;
12
13 import org.mule.MuleManager;
14 import org.mule.extras.client.MuleClient;
15 import org.mule.providers.ftp.server.NamedPayload;
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.AtomicInteger;
26 import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicReference;
27
28
29
30
31
32
33
34 public class FtpStreamingTestCase extends AbstractFtpServerTestCase
35 {
36
37 private static int PORT = 60197;
38
39 public FtpStreamingTestCase()
40 {
41 super(PORT);
42 }
43
44 protected String getConfigResources()
45 {
46 return "ftp-streaming-test.xml";
47 }
48
49 public void testSendAndReceive() throws Exception
50 {
51 final CountDownLatch latch = new CountDownLatch(1);
52 final AtomicReference message = new AtomicReference();
53 final AtomicInteger loopCount = new AtomicInteger(0);
54
55 EventCallback callback = new EventCallback()
56 {
57 public synchronized void eventReceived(UMOEventContext context, Object component)
58 {
59 try
60 {
61 logger.info("called " + loopCount.incrementAndGet() + " times");
62 FunctionalStreamingTestComponent ftc = (FunctionalStreamingTestComponent) component;
63
64 if (1 == latch.getCount())
65 {
66 message.set(ftc.getSummary());
67 latch.countDown();
68 }
69 }
70 catch (Exception e)
71 {
72 logger.error(e.getMessage(), e);
73 }
74 }
75 };
76
77 MuleClient client = new MuleClient();
78
79 UMOModel model = (UMOModel) MuleManager.getInstance().getModels().get("main");
80 FunctionalStreamingTestComponent ftc =
81 (FunctionalStreamingTestComponent) model.getComponent("testComponent").getInstance();
82
83
84
85 ftc.setEventCallback(callback, TEST_MESSAGE.length());
86
87
88 client.dispatch("tcp://localhost:60196", TEST_MESSAGE, new HashMap());
89 NamedPayload payload = awaitUpload();
90 assertNotNull(payload);
91 logger.info("received message: " + payload);
92 assertEquals(TEST_MESSAGE, new String(payload.getPayload()));
93
94
95 latch.await(getTimeout(), TimeUnit.MILLISECONDS);
96 assertEquals("Received stream; length: 16; 'Test...sage'", message.get());
97 }
98
99 }