forked from spring-projects/spring-batch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BatchPropertyContextTests.java
205 lines (170 loc) · 9.4 KB
/
BatchPropertyContextTests.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*
* Copyright 2013-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.jsr.configuration.support;
import static org.junit.Assert.assertEquals;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.junit.Before;
import org.junit.Test;
/**
* <p>
* Test cases around {@link BatchPropertyContext}.
* </p>
*
* @author Chris Schaefer
*/
public class BatchPropertyContextTests {
private Properties jobProperties = new Properties();
private Map<String, Properties> stepProperties = new HashMap<>();
private Map<String, Properties> artifactProperties = new HashMap<>();
private Map<String, Map<String, Properties>> partitionProperties = new HashMap<>();
private Map<String, Map<String, Properties>> stepArtifactProperties = new HashMap<>();
@SuppressWarnings("serial")
@Before
public void setUp() {
Properties step1Properties = new Properties();
step1Properties.setProperty("step1PropertyName1", "step1PropertyValue1");
step1Properties.setProperty("step1PropertyName2", "step1PropertyValue2");
this.stepProperties.put("step1", step1Properties);
Properties step2Properties = new Properties();
step2Properties.setProperty("step2PropertyName1", "step2PropertyValue1");
step2Properties.setProperty("step2PropertyName2", "step2PropertyValue2");
this.stepProperties.put("step2", step2Properties);
Properties jobProperties = new Properties();
jobProperties.setProperty("jobProperty1", "jobProperty1value");
jobProperties.setProperty("jobProperty2", "jobProperty2value");
this.jobProperties.putAll(jobProperties);
Properties artifactProperties = new Properties();
artifactProperties.setProperty("deciderProperty1", "deciderProperty1value");
artifactProperties.setProperty("deciderProperty2", "deciderProperty2value");
this.artifactProperties.put("decider1", artifactProperties);
final Properties stepArtifactProperties = new Properties();
stepArtifactProperties.setProperty("readerProperty1", "readerProperty1value");
stepArtifactProperties.setProperty("readerProperty2", "readerProperty2value");
this.stepArtifactProperties.put("step1", Collections.singletonMap("reader", stepArtifactProperties));
final Properties partitionProperties = new Properties();
partitionProperties.setProperty("writerProperty1", "writerProperty1valuePartition0");
partitionProperties.setProperty("writerProperty2", "writerProperty2valuePartition0");
this.partitionProperties.put("step2:partition0", Collections.singletonMap("writer", partitionProperties));
final Properties partitionStepProperties = new Properties();
partitionStepProperties.setProperty("writerProperty1Step", "writerProperty1");
partitionStepProperties.setProperty("writerProperty2Step", "writerProperty2");
this.partitionProperties.put("step2", Collections.singletonMap("writer", partitionStepProperties));
}
@Test
public void testStepLevelProperties() {
BatchPropertyContext batchPropertyContext = new BatchPropertyContext();
batchPropertyContext.setJobProperties(jobProperties);
batchPropertyContext.setStepProperties(stepProperties);
Properties step1Properties = batchPropertyContext.getStepProperties("step1");
assertEquals(2, step1Properties.size());
assertEquals("step1PropertyValue1", step1Properties.getProperty("step1PropertyName1"));
assertEquals("step1PropertyValue2", step1Properties.getProperty("step1PropertyName2"));
Properties step2Properties = batchPropertyContext.getStepProperties("step2");
assertEquals(2, step2Properties.size());
assertEquals("step2PropertyValue1", step2Properties.getProperty("step2PropertyName1"));
assertEquals("step2PropertyValue2", step2Properties.getProperty("step2PropertyName2"));
}
@Test
public void testJobLevelProperties() {
BatchPropertyContext batchPropertyContext = new BatchPropertyContext();
batchPropertyContext.setJobProperties(jobProperties);
Properties jobProperties = batchPropertyContext.getJobProperties();
assertEquals(2, jobProperties.size());
assertEquals("jobProperty1value", jobProperties.getProperty("jobProperty1"));
assertEquals("jobProperty2value", jobProperties.getProperty("jobProperty2"));
}
@Test
public void testAddPropertiesToExistingStep() {
BatchPropertyContext batchPropertyContext = new BatchPropertyContext();
batchPropertyContext.setJobProperties(jobProperties);
batchPropertyContext.setStepProperties(stepProperties);
Properties step1 = batchPropertyContext.getStepProperties("step1");
assertEquals(2, step1.size());
assertEquals("step1PropertyValue1", step1.getProperty("step1PropertyName1"));
assertEquals("step1PropertyValue2", step1.getProperty("step1PropertyName2"));
Properties step1properties = new Properties();
step1properties.setProperty("newStep1PropertyName", "newStep1PropertyValue");
batchPropertyContext.setStepProperties("step1", step1properties);
Properties step1updated = batchPropertyContext.getStepProperties("step1");
assertEquals(3, step1updated.size());
assertEquals("step1PropertyValue1", step1updated.getProperty("step1PropertyName1"));
assertEquals("step1PropertyValue2", step1updated.getProperty("step1PropertyName2"));
assertEquals("newStep1PropertyValue", step1updated.getProperty("newStep1PropertyName"));
}
@Test
public void testNonStepLevelArtifactProperties() {
BatchPropertyContext batchPropertyContext = new BatchPropertyContext();
batchPropertyContext.setJobProperties(jobProperties);
batchPropertyContext.setArtifactProperties(artifactProperties);
batchPropertyContext.setStepProperties(stepProperties);
Properties artifactProperties = batchPropertyContext.getArtifactProperties("decider1");
assertEquals(2, artifactProperties.size());
assertEquals("deciderProperty1value", artifactProperties.getProperty("deciderProperty1"));
assertEquals("deciderProperty2value", artifactProperties.getProperty("deciderProperty2"));
}
@Test
public void testStepLevelArtifactProperties() {
BatchPropertyContext batchPropertyContext = new BatchPropertyContext();
batchPropertyContext.setJobProperties(jobProperties);
batchPropertyContext.setArtifactProperties(artifactProperties);
batchPropertyContext.setStepProperties(stepProperties);
batchPropertyContext.setStepArtifactProperties(stepArtifactProperties);
Properties artifactProperties = batchPropertyContext.getStepArtifactProperties("step1", "reader");
assertEquals(4, artifactProperties.size());
assertEquals("readerProperty1value", artifactProperties.getProperty("readerProperty1"));
assertEquals("readerProperty2value", artifactProperties.getProperty("readerProperty2"));
assertEquals("step1PropertyValue1", artifactProperties.getProperty("step1PropertyName1"));
assertEquals("step1PropertyValue2", artifactProperties.getProperty("step1PropertyName2"));
}
@Test
public void testArtifactNonOverridingJobProperties() {
BatchPropertyContext batchPropertyContext = new BatchPropertyContext();
batchPropertyContext.setJobProperties(jobProperties);
batchPropertyContext.setArtifactProperties(artifactProperties);
Properties jobProperties = new Properties();
jobProperties.setProperty("deciderProperty1", "decider1PropertyOverride");
batchPropertyContext.setJobProperties(jobProperties);
Properties step1 = batchPropertyContext.getArtifactProperties("decider1");
assertEquals(2, step1.size());
assertEquals("deciderProperty1value", step1.getProperty("deciderProperty1"));
assertEquals("deciderProperty2value", step1.getProperty("deciderProperty2"));
Properties job = batchPropertyContext.getJobProperties();
assertEquals(3, job.size());
assertEquals("decider1PropertyOverride", job.getProperty("deciderProperty1"));
assertEquals("jobProperty1value", job.getProperty("jobProperty1"));
assertEquals("jobProperty2value", job.getProperty("jobProperty2"));
}
@Test
public void testPartitionProperties() {
BatchPropertyContext batchPropertyContext = new BatchPropertyContext();
batchPropertyContext.setJobProperties(jobProperties);
batchPropertyContext.setArtifactProperties(artifactProperties);
batchPropertyContext.setStepProperties(stepProperties);
batchPropertyContext.setStepArtifactProperties(stepArtifactProperties);
batchPropertyContext.setStepArtifactProperties(partitionProperties);
Properties artifactProperties = batchPropertyContext.getStepArtifactProperties("step2:partition0", "writer");
assertEquals(6, artifactProperties.size());
assertEquals("writerProperty1", artifactProperties.getProperty("writerProperty1Step"));
assertEquals("writerProperty2", artifactProperties.getProperty("writerProperty2Step"));
assertEquals("writerProperty1valuePartition0", artifactProperties.getProperty("writerProperty1"));
assertEquals("writerProperty2valuePartition0", artifactProperties.getProperty("writerProperty2"));
assertEquals("step2PropertyValue1", artifactProperties.getProperty("step2PropertyName1"));
assertEquals("step2PropertyValue2", artifactProperties.getProperty("step2PropertyName2"));
}
}