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.FunctionalTestComponent;
17
18 import edu.emory.mathcs.backport.java.util.concurrent.CountDownLatch;
19 import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
20 import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicReference;
21
22
23 public class FtpFunctionalTestCase extends AbstractFtpServerTestCase
24 {
25 private static int PORT = 60198;
26
27 public FtpFunctionalTestCase()
28 {
29 super(PORT);
30 }
31
32 protected String getConfigResources()
33 {
34 return "ftp-functional-test.xml";
35 }
36
37
38
39
40 public int getPort()
41 {
42 return PORT;
43 }
44
45 public void testSendAndRequest() throws Exception
46 {
47 CountDownLatch latch = new CountDownLatch(1);
48 AtomicReference message = new AtomicReference();
49
50 Object component = getComponent("testComponent");
51 assertNotNull(component);
52 assertTrue("FunctionalTestComponent expected", component instanceof FunctionalTestComponent);
53 FunctionalTestComponent ftc = (FunctionalTestComponent) component;
54 ftc.setEventCallback(new FunctionalEventCallback(latch, message));
55
56 MuleClient client = new MuleClient(muleContext);
57 client.dispatch(getMuleFtpEndpoint(), TEST_MESSAGE, null);
58
59
60
61
62
63
64 latch.await(getTimeout(), TimeUnit.MILLISECONDS);
65 assertEquals(TEST_MESSAGE, message.get());
66
67
68 Thread.sleep(500);
69 }
70
71 protected static class FunctionalEventCallback implements EventCallback
72 {
73 private CountDownLatch latch;
74 private AtomicReference message;
75
76 public FunctionalEventCallback(CountDownLatch latch, AtomicReference message)
77 {
78 super();
79 this.latch = latch;
80 this.message = message;
81 }
82
83 public synchronized void eventReceived(MuleEventContext context, Object component)
84 {
85 try
86 {
87 FunctionalTestComponent ftc = (FunctionalTestComponent) component;
88
89
90 if (1 == latch.getCount())
91 {
92 String o = new String((byte[])ftc.getLastReceivedMessage());
93 message.set(o);
94 latch.countDown();
95 }
96 }
97 catch (Exception e)
98 {
99 throw new IllegalStateException(e);
100 }
101 }
102 }
103 }