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.assertNotNull;
15 import static org.junit.Assert.assertTrue;
16
17 import java.io.IOException;
18 import java.util.Arrays;
19 import java.util.Collection;
20
21 import org.junit.Test;
22 import org.junit.runners.Parameterized.Parameters;
23 import org.mule.api.transport.DispatchException;
24 import org.mule.module.client.MuleClient;
25 import org.mule.transport.sftp.SftpClient;
26
27
28
29
30 public class SftpCantCreateTempDirectoryTestCase extends AbstractSftpDataIntegrityTestCase
31 {
32 private static String INBOUND_ENDPOINT_NAME = "inboundEndpoint";
33 private static String OUTBOUND_ENDPOINT_NAME = "outboundEndpoint";
34
35 public SftpCantCreateTempDirectoryTestCase(ConfigVariant variant, String configResources)
36 {
37 super(variant, configResources);
38 }
39
40 @Parameters
41 public static Collection<Object[]> parameters()
42 {
43 return Arrays.asList(new Object[][]{
44 {ConfigVariant.SERVICE, "dataintegrity/sftp-dataintegrity-common-with-tempdir-config-service.xml"},
45 {ConfigVariant.FLOW, "dataintegrity/sftp-dataintegrity-common-with-tempdir-config-flow.xml"}
46 });
47 }
48
49 @Override
50 protected void doSetUp() throws Exception
51 {
52 super.doSetUp();
53
54
55 initEndpointDirectory(INBOUND_ENDPOINT_NAME);
56 initEndpointDirectory(OUTBOUND_ENDPOINT_NAME);
57 }
58
59
60
61
62
63
64
65 @Test
66 public void testCantCreateTempDirectory() throws Exception
67 {
68 MuleClient muleClient = new MuleClient(muleContext);
69
70 SftpClient sftpClient = getSftpClient(muleClient, OUTBOUND_ENDPOINT_NAME);
71
72 try
73 {
74
75
76 remoteChmod(muleClient, sftpClient, OUTBOUND_ENDPOINT_NAME, 00500);
77
78
79
80
81 Exception exception = dispatchAndWaitForException(new DispatchParameters(INBOUND_ENDPOINT_NAME,
82 OUTBOUND_ENDPOINT_NAME), "sftp", "service");
83 assertNotNull(exception);
84 assertTrue("expected DispatchException, but got : " + exception.getClass().toString(),
85 exception instanceof DispatchException);
86 assertTrue("expected IOException, but got : " + exception.getCause().getClass().toString(),
87 exception.getCause() instanceof IOException);
88 assertEquals("Could not create the directory 'uploading', caused by: Permission denied",
89 exception.getCause().getMessage());
90
91 verifyInAndOutFiles(muleClient, INBOUND_ENDPOINT_NAME, OUTBOUND_ENDPOINT_NAME, true, false);
92 }
93 finally
94 {
95 sftpClient.disconnect();
96 }
97 }
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118 }