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