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