1
1
/*
2
- * Copyright 2022-2023 the original author or authors.
2
+ * Copyright 2022-2024 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -164,7 +164,7 @@ public void testSmbInboundStreamFlow() throws Exception {
164
164
}
165
165
166
166
@ Test
167
- public void testSmbOutboundFlow () {
167
+ public void testSmbOutboundFlow () throws SmbException {
168
168
IntegrationFlow flow = f -> f
169
169
.handle (Smb .outboundAdapter (sessionFactory (), FileExistsMode .REPLACE )
170
170
.useTemporaryFileName (false )
@@ -181,18 +181,13 @@ public void testSmbOutboundFlow() {
181
181
SmbFile [] files = template .execute (session ->
182
182
session .list (getTargetRemoteDirectory ().getName ()));
183
183
assertThat (files ).hasSize (1 );
184
- try {
185
- assertThat (files [0 ].length ()).isEqualTo (3 );
186
- }
187
- catch (SmbException se ) {
188
- se .printStackTrace ();
189
- }
184
+ assertThat (files [0 ].length ()).isEqualTo (3 );
190
185
191
186
registration .destroy ();
192
187
}
193
188
194
189
@ Test
195
- public void testSmbOutboundFlowWithSmbRemoteTemplate () {
190
+ public void testSmbOutboundFlowWithSmbRemoteTemplate () throws SmbException {
196
191
SmbRemoteFileTemplate smbTemplate = new SmbRemoteFileTemplate (sessionFactory ());
197
192
IntegrationFlow flow = f -> f
198
193
.handle (Smb .outboundAdapter (smbTemplate )
@@ -209,18 +204,13 @@ public void testSmbOutboundFlowWithSmbRemoteTemplate() {
209
204
SmbFile [] files = smbTemplate .execute (session ->
210
205
session .list (getTargetRemoteDirectory ().getName ()));
211
206
assertThat (files ).hasSize (1 );
212
- try {
213
- assertThat (files [0 ].length ()).isEqualTo (3 );
214
- }
215
- catch (SmbException se ) {
216
- se .printStackTrace ();
217
- }
207
+ assertThat (files [0 ].length ()).isEqualTo (3 );
218
208
219
209
registration .destroy ();
220
210
}
221
211
222
212
@ Test
223
- public void testSmbOutboundFlowWithSmbRemoteTemplateAndMode () {
213
+ public void testSmbOutboundFlowWithSmbRemoteTemplateAndMode () throws SmbException {
224
214
SmbRemoteFileTemplate smbTemplate = new SmbRemoteFileTemplate (sessionFactory ());
225
215
IntegrationFlow flow = f -> f
226
216
.handle (Smb .outboundAdapter (smbTemplate , FileExistsMode .APPEND )
@@ -242,18 +232,33 @@ public void testSmbOutboundFlowWithSmbRemoteTemplateAndMode() {
242
232
SmbFile [] files = smbTemplate .execute (session ->
243
233
session .list (getTargetRemoteDirectory ().getName ()));
244
234
assertThat (files ).hasSize (1 );
245
- try {
246
- assertThat (files [0 ].length ()).isEqualTo (9 );
247
- }
248
- catch (SmbException se ) {
249
- se .printStackTrace ();
250
- }
235
+ assertThat (files [0 ].length ()).isEqualTo (9 );
251
236
252
237
registration .destroy ();
253
238
}
254
239
255
240
@ Test
256
241
public void testSmbGetFlow () {
242
+ QueueChannel out = new QueueChannel ();
243
+ IntegrationFlow flow = f -> f
244
+ .handle (
245
+ Smb .outboundGateway (sessionFactory (), AbstractRemoteFileOutboundGateway .Command .GET , "payload" )
246
+ .localDirectoryExpression ("'" + getTargetLocalDirectoryName () + "'" ))
247
+ .channel (out );
248
+ IntegrationFlowRegistration registration = this .flowContext .registration (flow ).register ();
249
+ String fileName = "smbSource/subSmbSource/subSmbSource2.txt" ;
250
+ registration .getInputChannel ().send (new GenericMessage <>(fileName ));
251
+ Message <?> result = out .receive (10_000 );
252
+ assertThat (result ).isNotNull ();
253
+
254
+ File sfis = (File ) result .getPayload ();
255
+ assertThat (sfis ).hasFileName ("subSmbSource2.txt" );
256
+
257
+ registration .destroy ();
258
+ }
259
+
260
+ @ Test
261
+ public void testSmbGetStreamFlow () throws IOException {
257
262
QueueChannel out = new QueueChannel ();
258
263
IntegrationFlow flow = f -> f
259
264
.handle (
@@ -271,14 +276,10 @@ public void testSmbGetFlow() {
271
276
Message <?> result = out .receive (10_000 );
272
277
assertThat (result ).isNotNull ();
273
278
274
- SmbFileInputStream sfis = (SmbFileInputStream ) result .getPayload ();
275
- assertThat (sfis ).isNotNull ();
276
-
277
- try {
278
- sfis .close ();
279
- }
280
- catch (IOException ioe ) {
279
+ try (SmbFileInputStream sfis = (SmbFileInputStream ) result .getPayload ()) {
280
+ assertThat (sfis ).isNotNull ();
281
281
}
282
+
282
283
registration .destroy ();
283
284
}
284
285
0 commit comments