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.sftp;
8   
9   import org.mule.api.endpoint.ImmutableEndpoint;
10  import org.mule.module.client.MuleClient;
11  
12  import org.junit.Test;
13  
14  import static org.junit.Assert.assertTrue;
15  
16  /**
17   * @author Magnus Larsson <code>SftpExpressionFilenameParserTestCase</code> tests
18   *         usage of the Expression Filename Parser instead of the default Legacy
19   *         Parser.
20   */
21  public class SftpExpressionFilenameParserTestCase extends AbstractSftpTestCase
22  {
23  
24      protected static final long TIMEOUT = 10000;
25      private static final String OUTBOUND_ENDPOINT_NAME = "outboundEndpoint";
26      private static final String INBOUND_ENDPOINT_NAME = "inboundEndpoint";
27  
28      @Override
29      protected String getConfigResources()
30      {
31          return "mule-sftp-expressionFilenameParser-config.xml";
32      }
33  
34      @Override
35      protected void doSetUp() throws Exception
36      {
37          super.doSetUp();
38  
39          initEndpointDirectory(INBOUND_ENDPOINT_NAME);
40          initEndpointDirectory(OUTBOUND_ENDPOINT_NAME);
41      }
42  
43      @Test
44      public void testExpressionFilenameParser() throws Exception
45      {
46          MuleClient muleClient = new MuleClient(muleContext);
47          dispatchAndWaitForDelivery(new DispatchParameters(INBOUND_ENDPOINT_NAME, OUTBOUND_ENDPOINT_NAME));
48  
49          SftpClient sftpClient = null;
50          try
51          {
52              // Make sure a new file with name according to the notation has been
53              // created
54              sftpClient = getSftpClient(muleClient, OUTBOUND_ENDPOINT_NAME);
55              ImmutableEndpoint endpoint = (ImmutableEndpoint) muleClient.getProperty(OUTBOUND_ENDPOINT_NAME);
56              assertTrue("A new file in the outbound endpoint should exist", super.verifyFileExists(sftpClient,
57                  endpoint.getEndpointURI().getPath(), FILE_NAME));
58          }
59          finally
60          {
61              sftpClient.disconnect();
62          }
63      }
64  }