29
29
import java .util .Map ;
30
30
import java .util .regex .Matcher ;
31
31
32
- import org .junit .jupiter .api .Disabled ;
33
32
import org .junit .jupiter .api .Test ;
34
33
35
34
import org .springframework .beans .factory .annotation .Autowired ;
38
37
import org .springframework .integration .IntegrationMessageHeaderAccessor ;
39
38
import org .springframework .integration .channel .QueueChannel ;
40
39
import org .springframework .integration .config .EnableIntegration ;
41
- import org .springframework .integration .config .EnableIntegrationManagement ;
42
- import org .springframework .integration .config .IntegrationManagementConfigurer ;
43
40
import org .springframework .integration .core .MessageSource ;
44
41
import org .springframework .integration .dsl .IntegrationFlow ;
45
42
import org .springframework .integration .dsl .Pollers ;
69
66
import jcifs .smb .SmbFileInputStream ;
70
67
71
68
/**
72
- * The actual SMB share must be configured in class 'SmbTestSupport'
73
- * with the 'real' server settings for testing.
74
- *
75
- * You must create the following folder structures in your SMB share
76
- * for a successful completion of these unit tests:
77
- *
78
- * <pre class="code">
79
- * smbSource/
80
- * |-- smbSource1.txt - contains 'source1'
81
- * |-- smbSource2.txt - contains 'source2'
82
- * |-- SMBSOURCE1.TXT.a
83
- * |-- SMBSOURCE2.TXT.a
84
- * |-- subSmbSource/
85
- * |-- subSmbSource1.txt - contains 'subSource1'
86
- * |-- subSmbSource2.txt - contains 'subSource2'
87
- * |-- subSmbSource2/ - directory will be created in testSmbPutFlow
88
- * |-- subSmbSource2-1.txt - file will be created in testSmbPutFlow and deleted in testSmbRmFlow
89
- * |-- subSmbSource2-2.txt - file will be created in testSmbMputFlow
90
- * |-- subSmbSource2-3.txt - file will be created in testSmbMputFlow and renamed in testSmbMvFlow to subSmbSource-MV-Flow-Renamed.txt
91
- * smbTarget/
92
- * </pre>
93
69
*
94
70
* The intent is tests retrieve from smbSource and verify arrival in localTarget or
95
71
* send from localSource and verify arrival in remoteTarget.
96
72
*
97
73
* @author Gregory Bragg
74
+ * @author Artem Vozhdayenko
75
+ * @author Artem Bilan
98
76
*
99
77
* @since 6.0
100
78
*/
101
79
102
80
@ SpringJUnitConfig
103
81
@ DirtiesContext
104
- @ Disabled ("Actual SMB share must be configured in class [SmbTestSupport]." )
105
82
public class SmbTests extends SmbTestSupport {
106
83
107
84
@ Autowired
@@ -110,22 +87,19 @@ public class SmbTests extends SmbTestSupport {
110
87
@ Autowired
111
88
private ApplicationContext context ;
112
89
113
- @ Autowired
114
- private IntegrationManagementConfigurer integrationManagementConfigurer ;
115
-
116
90
@ Test
117
- public void testSmbInboundFlow () throws IOException {
91
+ public void testSmbInboundFlow () {
118
92
QueueChannel out = new QueueChannel ();
119
93
DirectoryScanner scanner = new DefaultDirectoryScanner ();
120
94
IntegrationFlow flow = IntegrationFlow .from (Smb .inboundAdapter (sessionFactory ())
121
- .preserveTimestamp (true )
122
- .remoteDirectory ("smbSource" )
123
- .maxFetchSize (10 )
124
- .scanner (scanner )
125
- .regexFilter (".*\\ .txt$" )
126
- .localFilename (f -> f .toUpperCase () + ".a" )
127
- .localDirectory (getTargetLocalDirectory ()),
128
- e -> e .id ("smbInboundAdapter" ).poller (Pollers .fixedDelay (100 )))
95
+ .preserveTimestamp (true )
96
+ .remoteDirectory ("smbSource" )
97
+ .maxFetchSize (10 )
98
+ .scanner (scanner )
99
+ .regexFilter (".*\\ .txt$" )
100
+ .localFilename (f -> f .toUpperCase () + ".a" )
101
+ .localDirectory (getTargetLocalDirectory ()),
102
+ e -> e .id ("smbInboundAdapter" ).poller (Pollers .fixedDelay (100 )))
129
103
.channel (out )
130
104
.get ();
131
105
IntegrationFlowRegistration registration = this .flowContext .registration (flow ).register ();
@@ -163,11 +137,11 @@ public void testSmbInboundFlow() throws IOException {
163
137
public void testSmbInboundStreamFlow () throws Exception {
164
138
QueueChannel out = new QueueChannel ();
165
139
StandardIntegrationFlow flow = IntegrationFlow .from (
166
- Smb .inboundStreamingAdapter (new SmbRemoteFileTemplate (sessionFactory ()))
167
- .remoteDirectory ("smbSource" )
168
- .maxFetchSize (11 )
169
- .regexFilter (".*\\ .txt$" ),
170
- e -> e .id ("smbInboundAdapter" ).poller (Pollers .fixedDelay (100 )))
140
+ Smb .inboundStreamingAdapter (new SmbRemoteFileTemplate (sessionFactory ()))
141
+ .remoteDirectory ("smbSource" )
142
+ .maxFetchSize (11 )
143
+ .regexFilter (".*\\ .txt$" ),
144
+ e -> e .id ("smbInboundAdapter" ).poller (Pollers .fixedDelay (100 )))
171
145
.channel (out )
172
146
.get ();
173
147
IntegrationFlowRegistration registration = this .flowContext .registration (flow ).register ();
@@ -207,7 +181,7 @@ public void testSmbOutboundFlow() {
207
181
RemoteFileTemplate <SmbFile > template = new RemoteFileTemplate <>(sessionFactory ());
208
182
SmbFile [] files = template .execute (session ->
209
183
session .list (getTargetRemoteDirectory ().getName ()));
210
- assertThat (files . length ). isEqualTo (1 );
184
+ assertThat (files ). hasSize (1 );
211
185
try {
212
186
assertThat (files [0 ].length ()).isEqualTo (3 );
213
187
}
@@ -235,7 +209,7 @@ public void testSmbOutboundFlowWithSmbRemoteTemplate() {
235
209
registration .getInputChannel ().send (message );
236
210
SmbFile [] files = smbTemplate .execute (session ->
237
211
session .list (getTargetRemoteDirectory ().getName ()));
238
- assertThat (files . length ). isEqualTo (1 );
212
+ assertThat (files ). hasSize (1 );
239
213
try {
240
214
assertThat (files [0 ].length ()).isEqualTo (3 );
241
215
}
@@ -268,7 +242,7 @@ public void testSmbOutboundFlowWithSmbRemoteTemplateAndMode() {
268
242
registration .getInputChannel ().send (message2 );
269
243
SmbFile [] files = smbTemplate .execute (session ->
270
244
session .list (getTargetRemoteDirectory ().getName ()));
271
- assertThat (files . length ). isEqualTo (1 );
245
+ assertThat (files ). hasSize (1 );
272
246
try {
273
247
assertThat (files [0 ].length ()).isEqualTo (9 );
274
248
}
@@ -331,7 +305,7 @@ public void testSmbMgetFlow() {
331
305
assertThat (result ).isNotNull ();
332
306
333
307
List <File > localFiles = (List <File >) result .getPayload ();
334
- assertThat (localFiles . size ()) .as ("unexpected local files " + localFiles ).isEqualTo (2 );
308
+ assertThat (localFiles ) .as ("unexpected local files " + localFiles ).hasSize (2 );
335
309
336
310
for (File file : localFiles ) {
337
311
assertThat (file .getPath ().replaceAll (Matcher .quoteReplacement (File .separator ), "/" )).contains (dir );
@@ -365,7 +339,7 @@ public void testSmbLsFlow() {
365
339
assertThat (result ).isNotNull ();
366
340
367
341
List <SmbFileInfo > localFiles = (List <SmbFileInfo >) result .getPayload ();
368
- assertThat (localFiles . size ()) .as ("unexpected local files " + localFiles ).isEqualTo (2 );
342
+ assertThat (localFiles ) .as ("unexpected local files " + localFiles ).hasSize (2 );
369
343
370
344
for (SmbFileInfo fileInfo : localFiles ) {
371
345
SmbFile file = fileInfo .getFileInfo ();
@@ -400,10 +374,10 @@ public void testSmbNlstFlow() {
400
374
assertThat (result ).isNotNull ();
401
375
402
376
List <String > localFilenames = (List <String >) result .getPayload ();
403
- assertThat (localFilenames . size ()) .as ("unexpected local filenames " + localFilenames ).isEqualTo (2 );
377
+ assertThat (localFilenames ) .as ("unexpected local filenames " + localFilenames ).hasSize (2 );
404
378
405
379
for (String filename : localFilenames ) {
406
- assertThat (filename .contains ("subSmbSource" ) );
380
+ assertThat (filename ) .contains ("subSmbSource" );
407
381
}
408
382
409
383
registration .destroy ();
@@ -431,8 +405,9 @@ public void testSmbPutFlow() {
431
405
assertThat (result ).isNotNull ();
432
406
433
407
String path = (String ) result .getPayload ();
434
- assertThat (path ).isNotNull ();
435
- assertThat (path .contains ("subSmbSource2" ));
408
+ assertThat (path )
409
+ .isNotNull ()
410
+ .contains ("subSmbSource2" );
436
411
437
412
registration .destroy ();
438
413
}
@@ -450,8 +425,7 @@ public void testSmbRmFlow() {
450
425
Message <?> result = out .receive (10_000 );
451
426
assertThat (result ).isNotNull ();
452
427
453
- Boolean success = (Boolean ) result .getPayload ();
454
- assertThat (success ).isTrue ();
428
+ assertThat (result .getPayload ()).isEqualTo (Boolean .TRUE );
455
429
456
430
registration .destroy ();
457
431
}
@@ -488,18 +462,19 @@ public void testSmbMputFlow() throws IOException {
488
462
assertThat (result ).isNotNull ();
489
463
490
464
List <String > remoteFilenames = (List <String >) result .getPayload ();
491
- assertThat (remoteFilenames ).isNotNull ();
492
- assertThat (remoteFilenames .size ()).as ("unexpected remote filenames " + remoteFilenames ).isEqualTo (2 );
465
+ assertThat (remoteFilenames )
466
+ .isNotNull ()
467
+ .as ("unexpected remote filenames " + remoteFilenames ).hasSize (2 );
493
468
494
469
for (String filename : remoteFilenames ) {
495
- assertThat (filename .contains ("subSmbSource2" ) );
470
+ assertThat (filename ) .contains ("subSmbSource2" );
496
471
}
497
472
498
473
registration .destroy ();
499
474
}
500
475
501
476
@ Test
502
- public void testSmbMvFlow () throws IOException {
477
+ public void testSmbMvFlow () {
503
478
QueueChannel out = new QueueChannel ();
504
479
IntegrationFlow flow = f -> f
505
480
.handle (
@@ -512,15 +487,13 @@ public void testSmbMvFlow() throws IOException {
512
487
Message <?> result = out .receive (10_000 );
513
488
assertThat (result ).isNotNull ();
514
489
515
- Boolean success = (Boolean ) result .getPayload ();
516
- assertThat (success ).isTrue ();
490
+ assertThat (result .getPayload ()).isEqualTo (Boolean .TRUE );
517
491
518
492
registration .destroy ();
519
493
}
520
494
521
495
@ Configuration
522
496
@ EnableIntegration
523
- @ EnableIntegrationManagement
524
497
public static class ContextConfiguration {
525
498
526
499
}
0 commit comments