View Javadoc

1   /*
2    * $Id: SftpExpressionFilenameParserTestCase.java 22475 2011-07-20 14:30:04Z justin.calleja $
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.sftp;
12  
13  import static org.junit.Assert.assertTrue;
14  
15  import java.util.Arrays;
16  import java.util.Collection;
17  
18  import org.junit.Test;
19  import org.junit.runners.Parameterized.Parameters;
20  import org.mule.api.endpoint.ImmutableEndpoint;
21  import org.mule.module.client.MuleClient;
22  
23  /**
24   * @author Magnus Larsson <code>SftpExpressionFilenameParserTestCase</code> tests
25   *         usage of the Expression Filename Parser instead of the default Legacy
26   *         Parser.
27   */
28  public class SftpExpressionFilenameParserTestCase extends AbstractSftpTestCase
29  {
30  
31      protected static final long TIMEOUT = 10000;
32      private static final String OUTBOUND_ENDPOINT_NAME = "outboundEndpoint";
33      private static final String INBOUND_ENDPOINT_NAME = "inboundEndpoint";
34  
35      public SftpExpressionFilenameParserTestCase(ConfigVariant variant, String configResources)
36      {
37          super(variant, configResources);
38      }
39      
40      @Parameters
41      public static Collection<Object[]> parameters()
42      {
43          return Arrays.asList(new Object[][]{
44              {ConfigVariant.SERVICE, "mule-sftp-expressionFilenameParser-config.xml"},
45              {ConfigVariant.FLOW, "mule-sftp-expressionFilenameParser-config.xml"}
46          });
47      }
48      
49      @Override
50      protected void doSetUp() throws Exception
51      {
52          super.doSetUp();
53  
54          initEndpointDirectory(INBOUND_ENDPOINT_NAME);
55          initEndpointDirectory(OUTBOUND_ENDPOINT_NAME);
56      }
57  
58      @Test
59      public void testExpressionFilenameParser() throws Exception
60      {
61          MuleClient muleClient = new MuleClient(muleContext);
62          dispatchAndWaitForDelivery(new DispatchParameters(INBOUND_ENDPOINT_NAME, OUTBOUND_ENDPOINT_NAME));
63  
64          SftpClient sftpClient = null;
65          try
66          {
67              // Make sure a new file with name according to the notation has been
68              // created
69              sftpClient = getSftpClient(muleClient, OUTBOUND_ENDPOINT_NAME);
70              ImmutableEndpoint endpoint = (ImmutableEndpoint) muleClient.getProperty(OUTBOUND_ENDPOINT_NAME);
71              assertTrue("A new file in the outbound endpoint should exist", super.verifyFileExists(sftpClient,
72                  endpoint.getEndpointURI().getPath(), FILE_NAME));
73          }
74          finally
75          {
76              sftpClient.disconnect();
77          }
78      }
79  }