24
24
import org .junit .runner .RunWith ;
25
25
26
26
import org .springframework .batch .core .configuration .annotation .EnableBatchProcessing ;
27
+ import org .springframework .batch .core .listener .ChunkListenerSupport ;
28
+ import org .springframework .batch .core .listener .CompositeItemReadListener ;
29
+ import org .springframework .batch .core .listener .CompositeItemWriteListener ;
30
+ import org .springframework .batch .core .listener .SkipListenerSupport ;
31
+ import org .springframework .batch .core .listener .StepExecutionListenerSupport ;
27
32
import org .springframework .batch .core .repository .JobRepository ;
28
33
import org .springframework .batch .core .step .tasklet .TaskletStep ;
29
34
import org .springframework .batch .item .ItemReader ;
35
+ import org .springframework .batch .item .ItemStreamSupport ;
30
36
import org .springframework .batch .item .support .ListItemReader ;
37
+ import org .springframework .batch .repeat .exception .DefaultExceptionHandler ;
38
+ import org .springframework .batch .repeat .support .RepeatTemplate ;
31
39
import org .springframework .beans .factory .annotation .Autowired ;
32
40
import org .springframework .context .annotation .Configuration ;
33
41
import org .springframework .integration .channel .DirectChannel ;
34
42
import org .springframework .integration .channel .QueueChannel ;
35
43
import org .springframework .messaging .PollableChannel ;
44
+ import org .springframework .retry .backoff .NoBackOffPolicy ;
45
+ import org .springframework .retry .listener .RetryListenerSupport ;
46
+ import org .springframework .retry .policy .MapRetryContextCache ;
36
47
import org .springframework .test .context .ContextConfiguration ;
37
48
import org .springframework .test .context .junit4 .SpringRunner ;
38
49
import org .springframework .transaction .PlatformTransactionManager ;
50
+ import org .springframework .transaction .interceptor .DefaultTransactionAttribute ;
39
51
40
52
/**
41
53
* @author Mahmoud Ben Hassine
@@ -52,6 +64,10 @@ public class RemoteChunkingMasterStepBuilderTest {
52
64
@ Autowired
53
65
private PlatformTransactionManager transactionManager ;
54
66
67
+ private PollableChannel inputChannel = new QueueChannel ();
68
+ private DirectChannel outputChannel = new DirectChannel ();
69
+ private ItemReader <String > itemReader = new ListItemReader <>(Arrays .asList ("a" , "b" , "c" ));
70
+
55
71
@ Test
56
72
public void inputChannelMustNotBeNull () {
57
73
// given
@@ -146,7 +162,7 @@ public void testMandatoryInputChannel() {
146
162
public void testMandatoryOutputChannel () {
147
163
// given
148
164
RemoteChunkingMasterStepBuilder <String , String > builder = new RemoteChunkingMasterStepBuilder <String , String >("step" )
149
- .inputChannel (new QueueChannel () );
165
+ .inputChannel (this . inputChannel );
150
166
151
167
this .expectedException .expect (IllegalArgumentException .class );
152
168
this .expectedException .expectMessage ("An OutputChannel must be provided" );
@@ -160,18 +176,58 @@ public void testMandatoryOutputChannel() {
160
176
161
177
@ Test
162
178
public void testMasterStepCreation () {
163
- // given
164
- ItemReader <String > itemReader = new ListItemReader <>(Arrays .asList ("a" , "b" , "c" ));
165
- PollableChannel inputChannel = new QueueChannel ();
166
- DirectChannel outputChannel = new DirectChannel ();
179
+ // when
180
+ TaskletStep taskletStep = new RemoteChunkingMasterStepBuilder <String , String >("step" )
181
+ .reader (this .itemReader )
182
+ .repository (this .jobRepository )
183
+ .transactionManager (this .transactionManager )
184
+ .inputChannel (this .inputChannel )
185
+ .outputChannel (this .outputChannel )
186
+ .build ();
187
+
188
+ // then
189
+ Assert .assertNotNull (taskletStep );
190
+ }
167
191
192
+ /*
193
+ * The following test is to cover setters that override those from parent builders.
194
+ */
195
+ @ Test
196
+ public void testSetters () {
168
197
// when
169
198
TaskletStep taskletStep = new RemoteChunkingMasterStepBuilder <String , String >("step" )
170
- .reader (itemReader )
199
+ .reader (this .itemReader )
200
+ .readerIsTransactionalQueue ()
201
+ .writer (items -> { })
171
202
.repository (this .jobRepository )
172
203
.transactionManager (this .transactionManager )
173
- .inputChannel (inputChannel )
174
- .outputChannel (outputChannel )
204
+ .transactionAttribute (new DefaultTransactionAttribute ())
205
+ .inputChannel (this .inputChannel )
206
+ .outputChannel (this .outputChannel )
207
+ .listener (new Object ())
208
+ .listener (new SkipListenerSupport <>())
209
+ .listener (new ChunkListenerSupport ())
210
+ .listener (new StepExecutionListenerSupport ())
211
+ .listener (new CompositeItemReadListener <>())
212
+ .listener (new CompositeItemWriteListener <>())
213
+ .listener (new RetryListenerSupport ())
214
+ .skip (Exception .class )
215
+ .noSkip (RuntimeException .class )
216
+ .skipLimit (10 )
217
+ .retry (Exception .class )
218
+ .noRetry (RuntimeException .class )
219
+ .retryLimit (10 )
220
+ .retryContextCache (new MapRetryContextCache ())
221
+ .noRollback (Exception .class )
222
+ .chunk (10 )
223
+ .startLimit (3 )
224
+ .allowStartIfComplete (true )
225
+ .exceptionHandler (new DefaultExceptionHandler ())
226
+ .stepOperations (new RepeatTemplate ())
227
+ .chunkOperations (new RepeatTemplate ())
228
+ .backOffPolicy (new NoBackOffPolicy ())
229
+ .stream (new ItemStreamSupport () {})
230
+ .keyGenerator (Object ::hashCode )
175
231
.build ();
176
232
177
233
// then
0 commit comments