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.endpoint.EndpointException;
10  import org.mule.endpoint.MuleEndpointURI;
11  import org.mule.tck.junit4.FunctionalTestCase;
12  import org.mule.transport.file.DummyFilenameParser;
13  import org.mule.transport.file.FilenameParser;
14  
15  import org.apache.commons.pool.impl.GenericObjectPool;
16  import org.junit.Test;
17  
18  import static org.junit.Assert.assertEquals;
19  import static org.junit.Assert.assertNotNull;
20  import static org.junit.Assert.assertTrue;
21  
22  /**
23   * Load a mule config and verify that the parameters are set as expected
24   */
25  public class FtpNamespaceHandlerTestCase extends FunctionalTestCase
26  {
27  
28      @Override
29      protected String getConfigResources()
30      {
31          return "ftp-namespace-config.xml";
32      }
33  
34      @Test
35      public void testConfig() throws Exception
36      {
37          FtpConnector c = (FtpConnector)muleContext.getRegistry().lookupConnector("ftpConnector");
38          assertNotNull(c);
39  
40          assertEquals("abc", c.getOutputPattern());
41          assertEquals(1234, c.getPollingFrequency());
42          assertEquals(false, c.isBinary());
43          assertEquals(false, c.isPassive());
44          assertEquals(false, c.isValidateConnections());
45          assertEquals(FTPConnectorTestCase.TestFtpConnectionFactory.class.getName(), c.getConnectionFactoryClass());
46  
47          FilenameParser parser = c.getFilenameParser();
48          assertTrue(parser.getClass().getName(), c.getFilenameParser() instanceof DummyFilenameParser);
49  
50          assertTrue(c.isConnected());
51          assertTrue(c.isStarted());
52      }
53      
54      @Test
55      public void testReceiverFtpConnector() throws EndpointException 
56      {
57          FtpConnector c = (FtpConnector)muleContext.getRegistry().lookupConnector("receiverFtpConnector");
58          assertNotNull(c);
59          
60          MuleEndpointURI uri = new MuleEndpointURI("http://localhost", null);
61          GenericObjectPool objectPool = (GenericObjectPool) c.getFtpPool(uri);
62          assertEquals(GenericObjectPool.WHEN_EXHAUSTED_FAIL, objectPool.getWhenExhaustedAction());
63      }
64  }