1
2
3
4
5
6
7
8
9
10
11 package org.mule.transport.sftp;
12
13 import static org.junit.Assert.assertEquals;
14 import static org.junit.Assert.assertTrue;
15 import static org.junit.Assert.fail;
16
17 import java.util.Arrays;
18 import java.util.Collection;
19
20 import org.apache.commons.lang.NotImplementedException;
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
27
28
29
30 public class SftpDuplicateHandlingFunctionalTestCase extends AbstractSftpTestCase
31 {
32
33 private static final long TIMEOUT = 10000;
34
35
36 final static int SEND_SIZE = 1024 * 1024 * 2;
37
38 public SftpDuplicateHandlingFunctionalTestCase(ConfigVariant variant, String configResources)
39 {
40 super(variant, configResources);
41
42
43
44 setDisposeContextPerClass(true);
45
46
47 logger.info("Timeout was set to: " + System.getProperty(TEST_TIMEOUT_SYSTEM_PROPERTY, "-1"));
48 System.setProperty(TEST_TIMEOUT_SYSTEM_PROPERTY, "300000");
49 logger.info("Timeout is now set to: " + System.getProperty(TEST_TIMEOUT_SYSTEM_PROPERTY, "-1"));
50 }
51
52 @Parameters
53 public static Collection<Object[]> parameters()
54 {
55 return Arrays.asList(new Object[][]{
56 {ConfigVariant.SERVICE, "mule-sftp-duplicateHandling-test-config-service.xml"},
57 {ConfigVariant.FLOW, "mule-sftp-duplicateHandling-test-config-flow.xml"}
58 });
59 }
60
61 @Override
62 protected void doSetUp() throws Exception
63 {
64 super.doSetUp();
65
66 initEndpointDirectory("inboundEndpoint1");
67 initEndpointDirectory("inboundEndpoint2");
68 initEndpointDirectory("inboundEndpoint3");
69 initEndpointDirectory("inboundEndpoint4");
70
71
72
73 muleContext.setExceptionListener(new org.mule.transport.sftp.notification.ExceptionListener());
74 }
75
76
77
78
79 @Test
80 public void testDuplicateHandlingThrowException() throws Exception
81 {
82
83
84
85 executeBaseTest("inboundEndpoint1", "vm://test.upload1", "file1.txt", SEND_SIZE, "receiving1",
86 TIMEOUT, "sending1");
87 }
88
89
90
91
92
93 @Test
94 public void testDuplicateHandlingOverwrite() throws Exception
95 {
96
97
98
99 try
100 {
101 executeBaseTest("inboundEndpoint2", "vm://test.upload2", "file2.txt", SEND_SIZE, "receiving2",
102 TIMEOUT, "sftp", "sending2");
103 fail("Should have received an Exception");
104 }
105 catch (Exception e)
106 {
107 assertTrue("did not receive DispatchException, got : " + e.getClass().toString(),
108 e instanceof DispatchException);
109 assertTrue(
110 "did not receive NotImplementedException, got : " + e.getCause().getClass().toString(),
111 e.getCause() instanceof NotImplementedException);
112 }
113 }
114
115
116
117
118 @Test
119 public void testDuplicateHandlingAddSeqNo() throws Exception
120 {
121
122
123
124 executeBaseTest("inboundEndpoint3", "vm://test.upload3", "file3.txt", SEND_SIZE, "receiving3",
125 TIMEOUT, "receiving3");
126 }
127
128
129
130
131
132 @Test
133 public void testDuplicateHandlingAddSeqNoUsingConnector() throws Exception
134 {
135
136
137
138 executeBaseTest("inboundEndpoint4", "vm://test.upload4", "file4.txt", SEND_SIZE, "receiving4",
139 TIMEOUT, "receiving4");
140
141 MuleClient muleClient = new MuleClient(muleContext);
142 ImmutableEndpoint endpoint = getImmutableEndpoint(muleClient, "send4outbound");
143 SftpUtil util = new SftpUtil(endpoint);
144
145 assertEquals("The value on the connector should be used", "addSeqNo", util.getDuplicateHandling());
146 }
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171 }