Skip to content

Commit 4b6df84

Browse files
author
dsyer
committed
Add test for pojo listener in XML config
1 parent 89f3cd7 commit 4b6df84

File tree

6 files changed

+120
-2
lines changed

6 files changed

+120
-2
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
target
2+
bin
3+

archetypes/simple-cli/.springBeans

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<beansProjectDescription>
33
<version>1</version>
4-
<pluginVersion><![CDATA[2.2.8.200911091054-RELEASE]]></pluginVersion>
4+
<pluginVersion><![CDATA[2.3.3.201006182200-CI-R3784-B777]]></pluginVersion>
55
<configSuffixes>
66
<configSuffix><![CDATA[xml]]></configSuffix>
77
</configSuffixes>
88
<enableImports><![CDATA[true]]></enableImports>
99
<configs>
1010
<config>src/test/resources/test-context.xml</config>
11+
<config>src/main/resources/META-INF/spring/module-context.xml</config>
12+
<config>src/main/resources/launch-context.xml</config>
1113
</configs>
1214
<configSets>
1315
</configSets>
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
#Wed Mar 24 07:48:49 GMT 2010
1+
#Thu Jun 24 11:17:24 BST 2010
22
//com.springsource.sts.config.flow.coordinates\:http\://www.springframework.org/schema/batch\:/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/JobRepositoryDefaultParserTests-context.xml=<?xml version\="1.0" encoding\="UTF-8"?>\n<graph/>
3+
//com.springsource.sts.config.flow.coordinates\:http\://www.springframework.org/schema/batch\:/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepWithPojoListenerJobParserTests-context.xml=<?xml version\="1.0" encoding\="UTF-8"?>\n<graph>\n<element type\="job">\n<structure end\="769" endstart\="763" start\="510" startend\="524"/>\n<bounds height\="118" width\="79" x\="15" y\="17"/>\n</element>\n</graph>
34
eclipse.preferences.version=1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright 2006-2007 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.batch.core.configuration.xml;
17+
18+
import static org.junit.Assert.assertEquals;
19+
import static org.junit.Assert.assertNotNull;
20+
import static org.junit.Assert.assertTrue;
21+
22+
import org.junit.Test;
23+
import org.junit.runner.RunWith;
24+
import org.springframework.batch.core.BatchStatus;
25+
import org.springframework.batch.core.Job;
26+
import org.springframework.batch.core.JobExecution;
27+
import org.springframework.batch.core.JobParameters;
28+
import org.springframework.batch.core.repository.JobRepository;
29+
import org.springframework.beans.factory.annotation.Autowired;
30+
import org.springframework.beans.factory.annotation.Qualifier;
31+
import org.springframework.test.context.ContextConfiguration;
32+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
33+
34+
/**
35+
* @author Dave Syer
36+
*
37+
*/
38+
@ContextConfiguration
39+
@RunWith(SpringJUnit4ClassRunner.class)
40+
public class StepWithPojoListenerJobParserTests {
41+
42+
@Autowired
43+
private Job job;
44+
45+
@Autowired
46+
private JobRepository jobRepository;
47+
48+
@Autowired
49+
private TestReader reader;
50+
51+
@Autowired
52+
@Qualifier("listener")
53+
private TestPojoListener listener;
54+
55+
@Autowired
56+
private TestWriter writer;
57+
58+
@Test
59+
public void testStepWithTask() throws Exception {
60+
assertNotNull(job);
61+
JobExecution jobExecution = jobRepository.createJobExecution(job.getName(), new JobParameters());
62+
job.execute(jobExecution);
63+
assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
64+
assertEquals(1, jobExecution.getStepExecutions().size());
65+
assertTrue(reader.isExecuted());
66+
assertTrue(reader.isOpened());
67+
assertTrue(writer.isExecuted());
68+
assertTrue(listener.isExecuted());
69+
}
70+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.springframework.batch.core.configuration.xml;
2+
3+
import java.util.List;
4+
5+
import org.springframework.batch.core.annotation.AfterWrite;
6+
7+
public class TestPojoListener extends AbstractTestComponent {
8+
9+
@AfterWrite
10+
public void after(List<Object> items){
11+
executed = true;
12+
}
13+
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans:beans xmlns="http://www.springframework.org/schema/batch" xmlns:beans="http://www.springframework.org/schema/beans"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd
5+
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
6+
7+
<beans:import resource="common-context.xml" />
8+
9+
<job id="job">
10+
<step id="step">
11+
<tasklet>
12+
<chunk reader="reader" writer="writer"
13+
commit-interval="10">
14+
</chunk>
15+
<listeners>
16+
<listener ref="listener" after-write-method="after"/>
17+
</listeners>
18+
</tasklet>
19+
</step>
20+
</job>
21+
22+
<beans:bean id="reader" class="org.springframework.batch.core.configuration.xml.TestReader" />
23+
24+
<beans:bean id="writer" class="org.springframework.batch.core.configuration.xml.TestWriter" />
25+
26+
<beans:bean id="listener" class="org.springframework.batch.core.configuration.xml.TestPojoListener" />
27+
28+
</beans:beans>

0 commit comments

Comments
 (0)