1
2
3
4
5
6
7 package org.mule.transport.sftp.dataintegrity;
8
9 import org.mule.api.endpoint.ImmutableEndpoint;
10 import org.mule.api.transport.DispatchException;
11 import org.mule.module.client.MuleClient;
12 import org.mule.transport.sftp.SftpClient;
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.assertTrue;
21
22
23
24
25
26
27
28
29 public class SftpCheckDuplicateFileHandlingTestCase extends AbstractSftpDataIntegrityTestCase
30 {
31
32 private static String INBOUND_ENDPOINT_NAME = "inboundEndpoint";
33 private static String OUTBOUND_ENDPOINT_NAME = "outboundEndpoint";
34
35 private static String INBOUND_ENDPOINT_NAME2 = "inboundEndpoint2";
36 private static String OUTBOUND_ENDPOINT_NAME2 = "outboundEndpoint2";
37
38 @Override
39 protected String getConfigResources()
40 {
41 return "dataintegrity/sftp-dataintegrity-duplicate-handling.xml";
42 }
43
44 @Override
45 protected void doSetUp() throws Exception
46 {
47 initEndpointDirectories(new String[]{"serviceDuplicateHandlingRename",
48 "serviceDuplicateHandlingThrowException"}, new String[]{INBOUND_ENDPOINT_NAME,
49 INBOUND_ENDPOINT_NAME2, OUTBOUND_ENDPOINT_NAME, OUTBOUND_ENDPOINT_NAME2});
50
51 muleContext.setExceptionListener(new org.mule.transport.sftp.notification.ExceptionListener());
52 }
53
54
55
56
57
58 @Test
59 public void testDuplicateChangeNameHandling() throws Exception
60 {
61
62 MuleClient muleClient = new MuleClient(muleContext);
63 SftpClient sftpClient = getSftpClient(muleClient, OUTBOUND_ENDPOINT_NAME);
64
65 try
66 {
67
68
69
70 dispatchAndWaitForDelivery(new DispatchParameters(INBOUND_ENDPOINT_NAME, OUTBOUND_ENDPOINT_NAME));
71
72
73 verifyInAndOutFiles(muleClient, INBOUND_ENDPOINT_NAME, OUTBOUND_ENDPOINT_NAME, false, true);
74
75
76 dispatchAndWaitForDelivery(new DispatchParameters(INBOUND_ENDPOINT_NAME, OUTBOUND_ENDPOINT_NAME));
77
78
79 verifyInAndOutFiles(muleClient, INBOUND_ENDPOINT_NAME, OUTBOUND_ENDPOINT_NAME, false, true);
80
81
82 ImmutableEndpoint endpoint = (ImmutableEndpoint) muleClient.getProperty(OUTBOUND_ENDPOINT_NAME);
83 assertTrue("A new file in the outbound endpoint should exist", verifyFileExists(sftpClient,
84 endpoint.getEndpointURI().getPath(), "file_1.txt"));
85
86 }
87 finally
88 {
89 sftpClient.disconnect();
90 }
91 }
92
93
94
95
96
97 @Test
98 public void testDuplicateDefaultExceptionHandling() throws Exception
99 {
100
101 MuleClient muleClient = new MuleClient(muleContext);
102 SftpClient sftpClient = getSftpClient(muleClient, OUTBOUND_ENDPOINT_NAME2);
103
104 try
105 {
106
107
108
109 dispatchAndWaitForDelivery(new DispatchParameters(INBOUND_ENDPOINT_NAME2, OUTBOUND_ENDPOINT_NAME2));
110
111 verifyInAndOutFiles(muleClient, INBOUND_ENDPOINT_NAME2, OUTBOUND_ENDPOINT_NAME2, false, true);
112
113 Exception exception = dispatchAndWaitForException(new DispatchParameters(INBOUND_ENDPOINT_NAME2,
114 OUTBOUND_ENDPOINT_NAME2), "sftp", "serviceDuplicateHandlingThrowException");
115 assertNotNull(exception);
116 assertTrue(exception instanceof DispatchException);
117 assertTrue(exception.getCause() instanceof IOException);
118 assertEquals("Failure", exception.getCause().getMessage());
119
120 verifyInAndOutFiles(muleClient, INBOUND_ENDPOINT_NAME2, OUTBOUND_ENDPOINT_NAME2, true, true);
121
122 }
123 finally
124 {
125 sftpClient.disconnect();
126 }
127 }
128 }