|
1 |
| -/* |
2 |
| - * Copyright 2013-2018 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 |
| - * https://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.test; |
17 |
| - |
18 |
| -import static org.junit.Assert.assertEquals; |
19 |
| -import static org.junit.Assert.assertNotNull; |
20 |
| - |
21 |
| -import org.junit.Test; |
22 |
| -import org.junit.runner.RunWith; |
23 |
| -import org.springframework.batch.core.JobExecution; |
24 |
| -import org.springframework.batch.item.ExecutionContext; |
25 |
| -import org.springframework.batch.item.ItemReader; |
26 |
| -import org.springframework.batch.item.ItemStream; |
27 |
| -import org.springframework.beans.factory.annotation.Autowired; |
28 |
| -import org.springframework.test.context.ContextConfiguration; |
29 |
| -import org.springframework.test.context.TestExecutionListeners; |
30 |
| -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
31 |
| -import org.springframework.test.context.support.DependencyInjectionTestExecutionListener; |
32 |
| - |
33 |
| -/** |
34 |
| - * @author Dave Syer |
35 |
| - * @author Mahmoud Ben Hassine |
36 |
| - * @since 2.1 |
37 |
| - */ |
38 |
| -@ContextConfiguration |
39 |
| -@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, JobScopeTestExecutionListener.class }) |
40 |
| -@RunWith(SpringJUnit4ClassRunner.class) |
41 |
| -public class JobScopeTestExecutionListenerIntegrationTests { |
42 |
| - |
43 |
| - @Autowired |
44 |
| - private ItemReader<String> reader; |
45 |
| - |
46 |
| - @Autowired |
47 |
| - private ItemStream stream; |
48 |
| - |
49 |
| - public JobExecution getJobExecution() { |
50 |
| - // Assert that dependencies are already injected... |
51 |
| - assertNotNull(reader); |
52 |
| - // Then create the execution for the job scope... |
53 |
| - JobExecution execution = MetaDataInstanceFactory.createJobExecution(); |
54 |
| - execution.getExecutionContext().putString("input.file", "classpath:/org/springframework/batch/test/simple.txt"); |
55 |
| - return execution; |
56 |
| - } |
57 |
| - |
58 |
| - @Test |
59 |
| - public void testJob() throws Exception { |
60 |
| - stream.open(new ExecutionContext()); |
61 |
| - assertEquals("foo", reader.read()); |
62 |
| - } |
63 |
| - |
64 |
| -} |
| 1 | +/* |
| 2 | + * Copyright 2013-2023 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 | + * https://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.test; |
| 17 | + |
| 18 | +import static org.junit.Assert.assertEquals; |
| 19 | +import static org.junit.Assert.assertNotNull; |
| 20 | +import static org.junit.Assert.assertNull; |
| 21 | + |
| 22 | +import org.junit.Test; |
| 23 | +import org.junit.runner.RunWith; |
| 24 | +import org.springframework.batch.core.JobExecution; |
| 25 | +import org.springframework.batch.item.ExecutionContext; |
| 26 | +import org.springframework.batch.item.ItemReader; |
| 27 | +import org.springframework.batch.item.ItemStream; |
| 28 | +import org.springframework.beans.factory.annotation.Autowired; |
| 29 | +import org.springframework.test.context.ContextConfiguration; |
| 30 | +import org.springframework.test.context.TestExecutionListeners; |
| 31 | +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
| 32 | +import org.springframework.test.context.support.DependencyInjectionTestExecutionListener; |
| 33 | + |
| 34 | +/** |
| 35 | + * @author Dave Syer |
| 36 | + * @author Mahmoud Ben Hassine |
| 37 | + * @since 2.1 |
| 38 | + */ |
| 39 | +@ContextConfiguration |
| 40 | +@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, JobScopeTestExecutionListener.class }) |
| 41 | +@RunWith(SpringJUnit4ClassRunner.class) |
| 42 | +public class JobScopeTestExecutionListenerIntegrationTests { |
| 43 | + |
| 44 | + @Autowired |
| 45 | + private ItemReader<String> reader; |
| 46 | + |
| 47 | + @Autowired |
| 48 | + private ItemStream stream; |
| 49 | + |
| 50 | + public JobExecution getJobExecution() { |
| 51 | + // Assert that dependencies are already injected... |
| 52 | + assertNotNull(reader); |
| 53 | + // Then create the execution for the job scope... |
| 54 | + JobExecution execution = MetaDataInstanceFactory.createJobExecution(); |
| 55 | + execution.getExecutionContext().putString("input.file", "classpath:/org/springframework/batch/test/simple.txt"); |
| 56 | + return execution; |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + public void testJob() throws Exception { |
| 61 | + stream.open(new ExecutionContext()); |
| 62 | + assertEquals("foo", reader.read()); |
| 63 | + assertEquals("bar", reader.read()); |
| 64 | + assertNull(reader.read()); |
| 65 | + } |
| 66 | + |
| 67 | +} |
0 commit comments