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.api.MuleEventContext;
10  import org.mule.api.MuleMessage;
11  import org.mule.tck.functional.EventCallback;
12  import org.mule.tck.functional.FunctionalStreamingTestComponent;
13  
14  import java.io.InputStream;
15  
16  import edu.emory.mathcs.backport.java.util.concurrent.CountDownLatch;
17  import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
18  import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicReference;
19  import org.junit.Test;
20  
21  import static org.junit.Assert.assertNotNull;
22  import static org.junit.Assert.assertTrue;
23  import static org.junit.Assert.fail;
24  
25  public class FtpStreamingTestCase extends AbstractFtpServerTestCase
26  {
27  
28      @Override
29      protected String getConfigResources()
30      {
31          return "ftp-streaming-test.xml";
32      }
33  
34      @Test
35      public void testRequest() throws Exception
36      {
37          final CountDownLatch latch = new CountDownLatch(1);
38          final AtomicReference messageHolder = new AtomicReference();
39  
40          EventCallback callback = new EventCallback()
41          {
42              public synchronized void eventReceived(MuleEventContext context, Object component)
43              {
44                  try
45                  {
46                      if (1 == latch.getCount())
47                      {
48                          messageHolder.set(context.getMessage());
49                          latch.countDown();
50                      }
51                  }
52                  catch (Exception e)
53                  {
54                      fail();
55                  }
56              }
57          };
58  
59          Object component = getComponent("testComponent");
60          assertTrue("FunctionalStreamingTestComponent expected", 
61              component instanceof FunctionalStreamingTestComponent);
62          FunctionalStreamingTestComponent ftc = (FunctionalStreamingTestComponent) component;
63          ftc.setEventCallback(callback, TEST_MESSAGE.length());
64         
65          createFileOnFtpServer("input.txt");
66                 
67          // poll and pull back through test service
68          assertTrue(latch.await(getTimeout(), TimeUnit.MILLISECONDS));
69  
70          MuleMessage message = (MuleMessage) messageHolder.get();
71          assertNotNull(message);
72          assertTrue(message.getPayload() instanceof InputStream);
73      }
74  }