Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * $Id: SftpCantWriteToFinalDestAfterTempDirectoryTestCase.java 23812 2012-02-03 13:17:37Z asequeira $
   * --------------------------------------------------------------------------------------
   * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
   *
   * The software in this package is published under the terms of the CPAL v1.0
   * license, a copy of which has been included with this distribution in the
   * LICENSE.txt file.
   */
 
 package org.mule.transport.sftp.dataintegrity;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
 
 import org.junit.Test;
Tests that files are not deleted if the final destination is not writable when using a temp directory.
 
 {
 
     private static String INBOUND_ENDPOINT_NAME = "inboundEndpoint";
     private static String OUTBOUND_ENDPOINT_NAME = "outboundEndpoint";
 
     public SftpCantWriteToFinalDestAfterTempDirectoryTestCase(ConfigVariant variantString configResources)
     {
         super(variantconfigResources);
     }
 
     @Parameters
     public static Collection<Object[]> parameters()
     {
         return Arrays.asList(new Object[][]{
             {."dataintegrity/sftp-dataintegrity-common-with-tempdir-config-service.xml"},
             {."dataintegrity/sftp-dataintegrity-common-with-tempdir-config-flow.xml"}});
     }
 
     @Override
     protected void doSetUp() throws Exception
     {
         super.doSetUp();
         // Delete the in & outbound directories
     }

    
No write access on the outbound directory but write access to the TEMP directory. The source file should still exist and no file should exist in the TEMP directory.
 
     @Test
     public void testCantWriteToFinalDestAfterTempDirectory() throws Exception
     {
         MuleClient muleClient = new MuleClient();
 
         // Must create the temp directory before we change the access rights
         createRemoteDirectory(muleClient"uploading");
 
         SftpClient sftpClient = getSftpClient(muleClient);
 
         try
         {
             // change the chmod to "dr-x------" on the outbound-directory
             remoteChmod(muleClientsftpClient, 00500);
 
             // Send an file to the SFTP server, which the inbound-outboundEndpoint
             // then can pick up
             // Expect an error, permission denied
                 ), "sftp""service");
             assertNotNull(exception);
             assertTrue("did not receive DispatchException, got : " + exception.getClass().toString(),
                 exception instanceof DispatchException);
             assertTrue("did not receive IOException, got : " + exception.getCause().getClass().toString(),
                 exception.getCause() instanceof IOException);
 
             assertEquals("Permission denied"exception.getCause().getMessage());
 
             verifyInAndOutFiles(muleClienttruefalse);
 
             ImmutableEndpoint endpoint = (ImmutableEndpointmuleClient.getProperty();
             assertFalse("The inbound file should not be left in the TEMP-dir"super.verifyFileExists(
                 sftpClient, endpoint.getEndpointURI().getPath() + "/" + ));
         }
        finally
        {
            sftpClient.disconnect();
        }
    }
New to GrepCode? Check out our FAQ X