View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.transport.ftp;
8   
9   import org.mule.DefaultMuleMessage;
10  import org.mule.api.client.MuleClient;
11  
12  import java.io.File;
13  
14  import edu.emory.mathcs.backport.java.util.concurrent.CountDownLatch;
15  import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
16  
17  import org.junit.Test;
18  
19  import static org.junit.Assert.assertTrue;
20  
21  public class FtpMessageDispatcherTestCase extends AbstractFtpServerTestCase
22  {  
23      private CountDownLatch latch;
24      private final String dirName = "test_dir";
25      
26      public FtpMessageDispatcherTestCase()
27      {
28          super();        
29          latch = new CountDownLatch(1);
30      }
31  
32      @Override
33      protected String getConfigResources()
34      {
35          return "ftp-message-requester-test.xml";
36      }
37  
38      @Test
39      public void dispatch() throws Exception
40      {
41          MuleClient client = muleContext.getClient();
42          client.dispatch(getMuleFtpEndpoint(), new DefaultMuleMessage(TEST_MESSAGE, muleContext));
43          
44          // check that the message arrived on the FTP server
45          assertTrue(latch.await(getTimeout(), TimeUnit.MILLISECONDS));
46  
47          String[] filesOnServer = new File(FTP_SERVER_BASE_DIR).list();
48          assertTrue(filesOnServer.length > 0);
49      }
50  
51      @Test
52      public void dispatchToPath() throws Exception
53      {
54          File testDir = new File(FTP_SERVER_BASE_DIR, dirName);
55          testDir.deleteOnExit();
56          assertTrue(testDir.mkdir());
57  
58          MuleClient client = muleContext.getClient();
59          String path = getMuleFtpEndpoint() + "/" + dirName;
60          client.dispatch(path, new DefaultMuleMessage(TEST_MESSAGE, muleContext));
61  
62          // check that the message arrived on the FTP server
63          assertTrue(latch.await(RECEIVE_TIMEOUT, TimeUnit.MILLISECONDS));
64  
65          String[] filesOnServer = testDir.list();
66          assertTrue(filesOnServer.length > 0);
67      }
68      
69      @Override
70      public void fileUploadCompleted()
71      {
72          latch.countDown();
73      }
74  }