17
17
package org .springframework .integration .sftp .outbound ;
18
18
19
19
import static org .assertj .core .api .Assertions .assertThat ;
20
+ import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
20
21
import static org .assertj .core .api .Assertions .fail ;
21
22
import static org .mockito .Mockito .spy ;
22
23
import static org .mockito .Mockito .verify ;
66
67
import org .springframework .messaging .MessagingException ;
67
68
import org .springframework .messaging .PollableChannel ;
68
69
import org .springframework .messaging .support .GenericMessage ;
69
- import org .springframework .test .context . ContextConfiguration ;
70
- import org .springframework .test .context .junit4 .SpringJUnit4ClassRunner ;
70
+ import org .springframework .test .annotation . DirtiesContext ;
71
+ import org .springframework .test .context .junit4 .SpringRunner ;
71
72
import org .springframework .util .FileCopyUtils ;
72
73
73
74
import com .jcraft .jsch .ChannelSftp ;
76
77
/**
77
78
* @author Artem Bilan
78
79
* @author Gary Russell
80
+ *
79
81
* @since 3.0
80
82
*/
81
- @ ContextConfiguration
82
- @ RunWith ( SpringJUnit4ClassRunner . class )
83
+ @ RunWith ( SpringRunner . class )
84
+ @ DirtiesContext
83
85
public class SftpServerOutboundTests extends SftpTestSupport {
84
86
85
87
@ Autowired
@@ -165,17 +167,11 @@ public void testInt2866LocalDirectoryExpressionGET() {
165
167
166
168
@ Test
167
169
public void testInt2866InvalidLocalDirectoryExpression () {
168
- try {
169
- this .invalidDirExpression .send (new GenericMessage <Object >("sftpSource/ sftpSource1.txt" ));
170
- fail ("Exception expected." );
171
- }
172
- catch (Exception e ) {
173
- Throwable cause = e .getCause ();
174
- assertThat (cause ).isNotNull ();
175
- cause = cause .getCause ();
176
- assertThat (cause ).isInstanceOf (IllegalArgumentException .class );
177
- assertThat (cause .getMessage ()).startsWith ("Failed to make local directory" );
178
- }
170
+ assertThatExceptionOfType (Exception .class )
171
+ .isThrownBy (() ->
172
+ this .invalidDirExpression .send (new GenericMessage <Object >("sftpSource/ sftpSource1.txt" )))
173
+ .withRootCauseInstanceOf (IllegalArgumentException .class )
174
+ .withMessageContaining ("Failed to make local directory" );
179
175
}
180
176
181
177
@ Test
@@ -190,15 +186,12 @@ public void testInt2866LocalDirectoryExpressionMGET() {
190
186
191
187
assertThat (localFiles ).hasSizeGreaterThan (0 );
192
188
193
- boolean assertedModified = false ;
194
189
for (File file : localFiles ) {
195
190
assertThat (file .getPath ().replaceAll (Matcher .quoteReplacement (File .separator ), "/" )).contains (dir );
196
191
if (file .getPath ().contains ("localTarget1" )) {
197
- assertedModified = assertPreserved (modified , file );
192
+ assertPreserved (modified , file );
198
193
}
199
194
}
200
- assertThat (assertedModified ).isTrue ();
201
-
202
195
dir = "sftpSource/subSftpSource/" ;
203
196
this .inboundMGet .send (new GenericMessage <Object >(dir + "*.txt" ));
204
197
result = this .output .receive (1000 );
@@ -225,14 +218,12 @@ public void testInt3172LocalDirectoryExpressionMGETRecursive() throws IOExceptio
225
218
List <File > localFiles = (List <File >) result .getPayload ();
226
219
assertThat (localFiles ).hasSize (3 );
227
220
228
- boolean assertedModified = false ;
229
221
for (File file : localFiles ) {
230
222
assertThat (file .getPath ().replaceAll (Matcher .quoteReplacement (File .separator ), "/" )).contains (dir );
231
223
if (file .getPath ().contains ("localTarget1" )) {
232
- assertedModified = assertPreserved (modified , file );
224
+ assertPreserved (modified , file );
233
225
}
234
226
}
235
- assertThat (assertedModified ).isTrue ();
236
227
assertThat (localFiles .get (2 ).getPath ().replaceAll (Matcher .quoteReplacement (File .separator ), "/" ))
237
228
.contains (dir + "subSftpSource" );
238
229
@@ -270,10 +261,9 @@ private long setModifiedOnSource1() {
270
261
return modified ;
271
262
}
272
263
273
- private boolean assertPreserved (long modified , File file ) {
264
+ private void assertPreserved (long modified , File file ) {
274
265
assertThat (Math .abs (file .lastModified () - modified ))
275
266
.as ("lastModified wrong by " + (modified - file .lastModified ())).isLessThan (1_000 );
276
- return true ;
277
267
}
278
268
279
269
@ Test
@@ -480,7 +470,7 @@ public void testInt3088MPutRecursive() {
480
470
while (output .receive (0 ) != null ) {
481
471
// drain
482
472
}
483
- this .inboundMPutRecursive .send (new GenericMessage <File >(getSourceLocalDirectory ()));
473
+ this .inboundMPutRecursive .send (new GenericMessage <>(getSourceLocalDirectory ()));
484
474
@ SuppressWarnings ("unchecked" )
485
475
Message <List <String >> out = (Message <List <String >>) this .output .receive (1000 );
486
476
assertThat (out ).isNotNull ();
@@ -504,7 +494,7 @@ public void testInt3088MPutRecursiveFiltered() {
504
494
while (output .receive (0 ) != null ) {
505
495
// drain
506
496
}
507
- this .inboundMPutRecursiveFiltered .send (new GenericMessage <File >(getSourceLocalDirectory ()));
497
+ this .inboundMPutRecursiveFiltered .send (new GenericMessage <>(getSourceLocalDirectory ()));
508
498
@ SuppressWarnings ("unchecked" )
509
499
Message <List <String >> out = (Message <List <String >>) this .output .receive (1000 );
510
500
assertThat (out ).isNotNull ();
@@ -559,7 +549,7 @@ public void testStream() {
559
549
560
550
@ Test
561
551
public void testMessageSessionCallback () {
562
- this .inboundCallback .send (new GenericMessage <String >("foo" ));
552
+ this .inboundCallback .send (new GenericMessage <>("foo" ));
563
553
Message <?> receive = this .output .receive (10000 );
564
554
assertThat (receive ).isNotNull ();
565
555
assertThat (receive .getPayload ()).isEqualTo ("FOO" );
@@ -576,7 +566,7 @@ private static final class TestMessageSessionCallback
576
566
implements MessageSessionCallback <LsEntry , Object > {
577
567
578
568
@ Override
579
- public Object doInSession (Session <ChannelSftp .LsEntry > session , Message <?> requestMessage ) throws IOException {
569
+ public Object doInSession (Session <ChannelSftp .LsEntry > session , Message <?> requestMessage ) {
580
570
return ((String ) requestMessage .getPayload ()).toUpperCase ();
581
571
}
582
572
@@ -627,6 +617,7 @@ public MessageChannel eventChannel() {
627
617
return true ;
628
618
};
629
619
}
620
+
630
621
}
631
622
632
623
}
0 commit comments