View Javadoc

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