1
2
3
4
5
6
7 package org.mule.transport.sftp.dataintegrity;
8
9 import org.mule.api.endpoint.ImmutableEndpoint;
10 import org.mule.api.transport.DispatchException;
11 import org.mule.module.client.MuleClient;
12 import org.mule.transport.sftp.SftpClient;
13
14 import java.io.IOException;
15
16 import org.junit.Test;
17
18 import static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.assertFalse;
20 import static org.junit.Assert.assertNotNull;
21 import static org.junit.Assert.assertTrue;
22
23
24
25
26
27 public class SftpCantWriteToFinalDestAfterTempDirectoryTestCase extends AbstractSftpDataIntegrityTestCase
28 {
29
30 private static String INBOUND_ENDPOINT_NAME = "inboundEndpoint";
31 private static String OUTBOUND_ENDPOINT_NAME = "outboundEndpoint";
32
33 @Override
34 protected String getConfigResources()
35 {
36 return "dataintegrity/sftp-dataintegrity-common-with-tempdir-config.xml";
37 }
38
39 @Override
40 protected void doSetUp() throws Exception
41 {
42 super.doSetUp();
43
44
45 initEndpointDirectory(INBOUND_ENDPOINT_NAME);
46 initEndpointDirectory(OUTBOUND_ENDPOINT_NAME);
47 }
48
49
50
51
52
53
54 @Test
55 public void testCantWriteToFinalDestAfterTempDirectory() throws Exception
56 {
57 MuleClient muleClient = new MuleClient(muleContext);
58
59
60 createRemoteDirectory(muleClient, OUTBOUND_ENDPOINT_NAME, "uploading");
61
62 SftpClient sftpClient = getSftpClient(muleClient, OUTBOUND_ENDPOINT_NAME);
63
64 try
65 {
66
67 remoteChmod(muleClient, sftpClient, OUTBOUND_ENDPOINT_NAME, 00500);
68
69
70
71
72 Exception exception = dispatchAndWaitForException(new DispatchParameters(INBOUND_ENDPOINT_NAME,
73 OUTBOUND_ENDPOINT_NAME), "sftp", "service");
74 assertNotNull(exception);
75 assertTrue("did not receive DispatchException, got : " + exception.getClass().toString(),
76 exception instanceof DispatchException);
77 assertTrue("did not receive IOException, got : " + exception.getCause().getClass().toString(),
78 exception.getCause() instanceof IOException);
79
80 assertEquals("Permission denied", exception.getCause().getMessage());
81
82 verifyInAndOutFiles(muleClient, INBOUND_ENDPOINT_NAME, OUTBOUND_ENDPOINT_NAME, true, false);
83
84 ImmutableEndpoint endpoint = (ImmutableEndpoint) muleClient.getProperty(OUTBOUND_ENDPOINT_NAME);
85 assertFalse("The inbound file should not be left in the TEMP-dir", super.verifyFileExists(
86 sftpClient, endpoint.getEndpointURI().getPath() + "/" + TEMP_DIR, FILE_NAME));
87 }
88 finally
89 {
90 sftpClient.disconnect();
91 }
92 }
93
94 }