1
2
3
4
5
6
7 package org.mule.transport.sftp.dataintegrity;
8
9 import org.mule.api.endpoint.EndpointBuilder;
10 import org.mule.api.endpoint.InboundEndpoint;
11 import org.mule.api.registry.MuleRegistry;
12 import org.mule.transport.sftp.SftpConnector;
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.assertNotNull;
20 import static org.junit.Assert.fail;
21
22 public class SftpInvalidInboundEndpointTestCase extends AbstractSftpDataIntegrityTestCase
23 {
24
25 private static final int NO_OF_INVALID_ATTEMPTS = 50;
26
27 @Override
28 protected String getConfigResources()
29 {
30 return "dataintegrity/sftp-invalid-inbound-endpoint-config.xml";
31 }
32
33 @Test
34 public void testInvalidInboundEndpoint() throws Exception
35 {
36
37 String expectedStartOfErrorMessage = "Error 'No such file' occurred when trying to CDW";
38
39 MuleRegistry registry = muleContext.getRegistry();
40
41 SftpConnector c = (SftpConnector) registry.lookupConnector("sftp");
42 assertNotNull(c);
43
44 EndpointBuilder epb = registry.lookupEndpointBuilder("InvalidEndpoint");
45 InboundEndpoint ep = epb.buildInboundEndpoint();
46
47
48
49
50
51 for (int i = 0; i < NO_OF_INVALID_ATTEMPTS; i++)
52 {
53 if (logger.isDebugEnabled())
54 logger.debug("CreateSftpClient invalid atempt #" + i + " of " + NO_OF_INVALID_ATTEMPTS);
55 try
56 {
57 c.createSftpClient(ep);
58 fail("Should have received an exception here!!!");
59 }
60 catch (IOException ioe)
61 {
62 String actualStartOfErrorMessage = ioe.getMessage().substring(0,
63 expectedStartOfErrorMessage.length());
64 assertEquals(expectedStartOfErrorMessage, actualStartOfErrorMessage);
65 }
66 }
67 }
68 }