View Javadoc

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