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.module.client.MuleClient;
11  import org.mule.transport.sftp.AbstractSftpTestCase;
12  import org.mule.transport.sftp.SftpClient;
13  
14  import java.io.IOException;
15  
16  import static org.junit.Assert.assertFalse;
17  import static org.junit.Assert.assertTrue;
18  
19  public abstract class AbstractSftpDataIntegrityTestCase extends AbstractSftpTestCase
20  {
21  
22      protected static final String TEMP_DIR = "uploading";
23  
24      protected void verifyInAndOutFiles(MuleClient muleClient,
25                                         String inboundEndpointName,
26                                         String outboundEndpointName,
27                                         boolean shouldInboundFileStillExist,
28                                         boolean shouldOutboundFileExist) throws IOException
29      {
30          SftpClient sftpClientInbound = getSftpClient(muleClient, inboundEndpointName);
31          SftpClient sftpClientOutbound = getSftpClient(muleClient, outboundEndpointName);
32  
33          try
34          {
35              ImmutableEndpoint inboundEndpoint = (ImmutableEndpoint) muleClient.getProperty(inboundEndpointName);
36  
37              ImmutableEndpoint outboundEndpoint = (ImmutableEndpoint) muleClient.getProperty(outboundEndpointName);
38  
39              if (shouldInboundFileStillExist)
40              {
41                  assertTrue("The inbound file should still exist", super.verifyFileExists(sftpClientInbound,
42                      inboundEndpoint.getEndpointURI(), FILE_NAME));
43              }
44              else
45              {
46                  assertFalse("The inbound file should have been deleted", super.verifyFileExists(
47                      sftpClientInbound, inboundEndpoint.getEndpointURI(), FILE_NAME));
48              }
49  
50              if (shouldOutboundFileExist)
51              {
52                  assertTrue("The outbound file should exist", super.verifyFileExists(sftpClientOutbound,
53                      outboundEndpoint.getEndpointURI(), FILE_NAME));
54              }
55              else
56              {
57                  assertFalse("The outbound file should have been deleted", super.verifyFileExists(
58                      sftpClientOutbound, outboundEndpoint.getEndpointURI(), FILE_NAME));
59              }
60          }
61          finally
62          {
63              sftpClientInbound.disconnect();
64              sftpClientOutbound.disconnect();
65          }
66      }
67  
68  }