Skip to content

Commit 10271e1

Browse files
committed
BATCH-2686: Add assertions on input/output channels
1 parent 54cd2b1 commit 10271e1

File tree

4 files changed

+70
-2
lines changed

4 files changed

+70
-2
lines changed

spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/RemoteChunkingMasterStepBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ public RemoteChunkingMasterStepBuilder<I, O> throttleLimit(long throttleLimit) {
180180
public TaskletStep build() {
181181

182182
Assert.notNull(beanDefinitionRegistry, "A BeanDefinitionRegistry must be provided");
183-
Assert.notNull(inputChannel, "inputChannel must not be null");
184-
Assert.notNull(outputChannel, "outputChannel must not be null");
183+
Assert.notNull(inputChannel, "An InputChannel must be provided");
184+
Assert.notNull(outputChannel, "An OutputChannel must be provided");
185185

186186
// configure messaging template
187187
if (this.messagingTemplate == null) {

spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/RemoteChunkingWorkerBuilder.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ public RemoteChunkingWorkerBuilder<I, O> outputChannel(DirectChannel outputChann
112112
public IntegrationFlow build() {
113113

114114
Assert.notNull(itemWriter, "An ItemWriter must be provided");
115+
Assert.notNull(inputChannel, "An InputChannel must be provided");
116+
Assert.notNull(outputChannel, "An OutputChannel must be provided");
115117

116118
if(this.itemProcessor == null) {
117119
this.itemProcessor = new PassThroughItemProcessor();

spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/RemoteChunkingMasterStepBuilderTest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,39 @@ public void throttleLimitMustNotBeGreaterThanZero() {
159159
// expected exception
160160
}
161161

162+
@Test
163+
public void testMandatoryInputChannel() {
164+
// given
165+
RemoteChunkingMasterStepBuilder<String, String> builder = new RemoteChunkingMasterStepBuilder<String, String>("step")
166+
.beanDefinitionRegistry(new GenericApplicationContext());
167+
168+
expectedException.expect(IllegalArgumentException.class);
169+
expectedException.expectMessage("An InputChannel must be provided");
170+
171+
// when
172+
TaskletStep step = builder.build();
173+
174+
// then
175+
// expected exception
176+
}
177+
178+
@Test
179+
public void testMandatoryOutputChannel() {
180+
// given
181+
RemoteChunkingMasterStepBuilder<String, String> builder = new RemoteChunkingMasterStepBuilder<String, String>("step")
182+
.beanDefinitionRegistry(new GenericApplicationContext())
183+
.inputChannel(new QueueChannel());
184+
185+
expectedException.expect(IllegalArgumentException.class);
186+
expectedException.expectMessage("An OutputChannel must be provided");
187+
188+
// when
189+
TaskletStep step = builder.build();
190+
191+
// then
192+
// expected exception
193+
}
194+
162195
@Test
163196
public void testRemoteChunkHandlerRegistration() {
164197
// given

spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/RemoteChunkingWorkerBuilderTest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,39 @@ public void testMandatoryItemWriter() {
111111
// expected exception
112112
}
113113

114+
@Test
115+
public void testMandatoryInputChannel() {
116+
// given
117+
RemoteChunkingWorkerBuilder<String, String> builder = new RemoteChunkingWorkerBuilder<String, String>()
118+
.itemWriter(items -> { });
119+
120+
expectedException.expect(IllegalArgumentException.class);
121+
expectedException.expectMessage("An InputChannel must be provided");
122+
123+
// when
124+
builder.build();
125+
126+
// then
127+
// expected exception
128+
}
129+
130+
@Test
131+
public void testMandatoryOutputChannel() {
132+
// given
133+
RemoteChunkingWorkerBuilder<String, String> builder = new RemoteChunkingWorkerBuilder<String, String>()
134+
.itemWriter(items -> { })
135+
.inputChannel(new DirectChannel());
136+
137+
expectedException.expect(IllegalArgumentException.class);
138+
expectedException.expectMessage("An OutputChannel must be provided");
139+
140+
// when
141+
builder.build();
142+
143+
// then
144+
// expected exception
145+
}
146+
114147
@Test
115148
public void testIntegrationFlowCreation() {
116149
// given

0 commit comments

Comments
 (0)