View Javadoc

1   /*
2    * $Id: SftpNoOutboundDirectoryTestCase.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 outbound directory doesn't exist
29   */
30  public class SftpNoOutboundDirectoryTestCase extends AbstractSftpDataIntegrityTestCase
31  {
32      private static final String ENDPOINT_NAME = "inboundEndpoint";
33  
34      public SftpNoOutboundDirectoryTestCase(ConfigVariant variant, String configResources)
35      {
36          super(variant, configResources);
37      }
38      
39      @Parameters
40      public static Collection<Object[]> parameters()
41      {
42          return Arrays.asList(new Object[][]{
43              {ConfigVariant.SERVICE, "dataintegrity/sftp-no-outbound-directory-config-service.xml"},
44              {ConfigVariant.FLOW, "dataintegrity/sftp-no-outbound-directory-config-flow.xml"}
45          });
46      }
47  
48      @Override
49      protected void doSetUp() throws Exception
50      {
51          super.doSetUp();
52  
53          // Delete the in & outbound directories
54          initEndpointDirectory(ENDPOINT_NAME);
55      }
56  
57      /**
58       * The outbound directory doesn't exist. The source file should still exist
59       */
60      @Test
61      public void testNoOutboundDirectory() throws Exception
62      {
63          MuleClient muleClient = new MuleClient(muleContext);
64  
65          // Send an file to the SFTP server, which the inbound-outboundEndpoint then
66          // can pick up
67          Exception exception = dispatchAndWaitForException(new DispatchParameters(ENDPOINT_NAME, null),
68              "sftp", "service");
69          assertNotNull(exception);
70  
71          assertTrue("expected DispatchException, but got " + exception.getClass().toString(),
72              exception instanceof DispatchException);
73          assertTrue("expected IOException, but got " + exception.getCause().getClass().toString(),
74              exception.getCause() instanceof IOException);
75          assertTrue("wrong starting message : " + exception.getCause().getMessage(), exception.getCause()
76              .getMessage()
77              .startsWith("Error 'No such file' occurred when trying to CDW to '"));
78          assertTrue("wrong ending message : " + exception.getCause().getMessage(), exception.getCause()
79              .getMessage()
80              .endsWith("/DIRECTORY-MISSING'."));
81  
82          SftpClient sftpClient = getSftpClient(muleClient, ENDPOINT_NAME);
83          try
84          {
85              ImmutableEndpoint endpoint = (ImmutableEndpoint) muleClient.getProperty(ENDPOINT_NAME);
86              assertTrue("The inbound file should still exist", super.verifyFileExists(sftpClient,
87                  endpoint.getEndpointURI(), FILE_NAME));
88          }
89          finally
90          {
91              sftpClient.disconnect();
92          }
93      }
94  
95  }