View Javadoc

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