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.dataintegrity;
8   
9   import org.mule.api.endpoint.ImmutableEndpoint;
10  import org.mule.api.transport.DispatchException;
11  import org.mule.module.client.MuleClient;
12  import org.mule.transport.sftp.SftpClient;
13  
14  import java.io.IOException;
15  
16  import org.junit.Test;
17  
18  import static org.junit.Assert.assertNotNull;
19  import static org.junit.Assert.assertTrue;
20  
21  /**
22   * Verify that the original file is not lost if the password for the outbound
23   * endpoint is wrong
24   */
25  public class SftpWrongPassPhraseOnOutboundDirectoryTestCase extends AbstractSftpDataIntegrityTestCase
26  {
27  
28      private static String INBOUND_ENDPOINT_NAME = "inboundEndpoint";
29  
30      @Override
31      protected String getConfigResources()
32      {
33          return "dataintegrity/sftp-wrong-passphrase-config.xml";
34      }
35  
36      @Override
37      protected void doSetUp() throws Exception
38      {
39          super.doSetUp();
40  
41          // Delete the in & outbound directories
42          initEndpointDirectory(INBOUND_ENDPOINT_NAME);
43      }
44  
45      /**
46       * The outbound directory doesn't exist. The source file should still exist
47       * 
48       * @throws Exception
49       */
50      @Test
51      public void testWrongPassPhraseOnOutboundDirectory() throws Exception
52      {
53          MuleClient muleClient = new MuleClient(muleContext);
54          assertTrue(muleContext.isStarted());
55          // Send an file to the SFTP server, which the inbound-outboundEndpoint then
56          // can pick up
57          final Exception exception = dispatchAndWaitForException(new DispatchParameters(INBOUND_ENDPOINT_NAME,
58              null), "sftp", "service");
59          assertNotNull(exception);
60          assertTrue("expected DispatchException, but got " + exception.getClass().toString(),
61              exception instanceof DispatchException);
62          assertTrue("expected IOException, but got " + exception.getCause().getClass().toString(),
63              exception.getCause() instanceof IOException);
64          assertTrue("wrong message : " + exception.getCause().getMessage(), exception.getCause()
65              .getMessage()
66              .startsWith("Error during login to"));
67  
68          SftpClient sftpClient = getSftpClient(muleClient, INBOUND_ENDPOINT_NAME);
69          try
70          {
71              ImmutableEndpoint endpoint = (ImmutableEndpoint) muleClient.getProperty(INBOUND_ENDPOINT_NAME);
72              assertTrue("The inbound file should still exist", super.verifyFileExists(sftpClient,
73                  endpoint.getEndpointURI(), FILE_NAME));
74          }
75          finally
76          {
77              sftpClient.disconnect();
78          }
79      }
80  
81  }