View Javadoc

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