1
2
3
4
5
6
7
8
9
10
11 package org.mule.transport.sftp.dataintegrity;
12
13 import static org.junit.Assert.assertNotNull;
14 import static org.junit.Assert.assertTrue;
15
16 import java.io.IOException;
17 import java.util.Arrays;
18 import java.util.Collection;
19
20 import org.junit.Test;
21 import org.junit.runners.Parameterized.Parameters;
22 import org.mule.api.endpoint.ImmutableEndpoint;
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 SftpNoOutboundDirectoryTestCase extends AbstractSftpDataIntegrityTestCase
31 {
32 private static final String ENDPOINT_NAME = "inboundEndpoint";
33
34 public SftpNoOutboundDirectoryTestCase(ConfigVariant variant, String configResources)
35 {
36 super(variant, configResources);
37 }
38
39 @Parameters
40 public static Collection<Object[]> parameters()
41 {
42 return Arrays.asList(new Object[][]{
43 {ConfigVariant.SERVICE, "dataintegrity/sftp-no-outbound-directory-config-service.xml"},
44 {ConfigVariant.FLOW, "dataintegrity/sftp-no-outbound-directory-config-flow.xml"}
45 });
46 }
47
48 @Override
49 protected void doSetUp() throws Exception
50 {
51 super.doSetUp();
52
53
54 initEndpointDirectory(ENDPOINT_NAME);
55 }
56
57
58
59
60 @Test
61 public void testNoOutboundDirectory() throws Exception
62 {
63 MuleClient muleClient = new MuleClient(muleContext);
64
65
66
67 Exception exception = dispatchAndWaitForException(new DispatchParameters(ENDPOINT_NAME, null),
68 "sftp", "service");
69 assertNotNull(exception);
70
71 assertTrue("expected DispatchException, but got " + exception.getClass().toString(),
72 exception instanceof DispatchException);
73 assertTrue("expected IOException, but got " + exception.getCause().getClass().toString(),
74 exception.getCause() instanceof IOException);
75 assertTrue("wrong starting message : " + exception.getCause().getMessage(), exception.getCause()
76 .getMessage()
77 .startsWith("Error 'No such file' occurred when trying to CDW to '"));
78 assertTrue("wrong ending message : " + exception.getCause().getMessage(), exception.getCause()
79 .getMessage()
80 .endsWith("/DIRECTORY-MISSING'."));
81
82 SftpClient sftpClient = getSftpClient(muleClient, ENDPOINT_NAME);
83 try
84 {
85 ImmutableEndpoint endpoint = (ImmutableEndpoint) muleClient.getProperty(ENDPOINT_NAME);
86 assertTrue("The inbound file should still exist", super.verifyFileExists(sftpClient,
87 endpoint.getEndpointURI(), FILE_NAME));
88 }
89 finally
90 {
91 sftpClient.disconnect();
92 }
93 }
94
95 }