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