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
31 public class SftpWrongPassPhraseOnOutboundDirectoryTestCase extends AbstractSftpDataIntegrityTestCase
32 {
33 private static String INBOUND_ENDPOINT_NAME = "inboundEndpoint";
34
35 public SftpWrongPassPhraseOnOutboundDirectoryTestCase(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-wrong-passphrase-config-service.xml"},
45 {ConfigVariant.FLOW, "dataintegrity/sftp-wrong-passphrase-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 }
57
58
59
60
61
62
63 @Test
64 public void testWrongPassPhraseOnOutboundDirectory() throws Exception
65 {
66 MuleClient muleClient = new MuleClient(muleContext);
67 assertTrue(muleContext.isStarted());
68
69
70 final Exception exception = dispatchAndWaitForException(new DispatchParameters(INBOUND_ENDPOINT_NAME,
71 null), "sftp", "service");
72 assertNotNull(exception);
73 assertTrue("expected DispatchException, but got " + exception.getClass().toString(),
74 exception instanceof DispatchException);
75 assertTrue("expected IOException, but got " + exception.getCause().getClass().toString(),
76 exception.getCause() instanceof IOException);
77 assertTrue("wrong message : " + exception.getCause().getMessage(), exception.getCause()
78 .getMessage()
79 .startsWith("Error during login to"));
80
81 SftpClient sftpClient = getSftpClient(muleClient, INBOUND_ENDPOINT_NAME);
82 try
83 {
84 ImmutableEndpoint endpoint = (ImmutableEndpoint) muleClient.getProperty(INBOUND_ENDPOINT_NAME);
85 assertTrue("The inbound file should still exist", super.verifyFileExists(sftpClient,
86 endpoint.getEndpointURI(), FILE_NAME));
87 }
88 finally
89 {
90 sftpClient.disconnect();
91 }
92 }
93
94 }