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