|
1 | 1 | /*
|
2 |
| - * Copyright 2006-2022 the original author or authors. |
| 2 | + * Copyright 2006-2023 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
18 | 18 | import org.junit.jupiter.api.Test;
|
19 | 19 |
|
20 | 20 | import org.springframework.batch.core.JobExecution;
|
| 21 | +import org.springframework.batch.core.JobParameter; |
21 | 22 | import org.springframework.batch.core.JobParameters;
|
22 | 23 | import org.springframework.batch.core.JobParametersBuilder;
|
23 | 24 | import org.springframework.batch.core.StepExecution;
|
24 | 25 |
|
| 26 | +import static org.assertj.core.api.Assertions.assertThat; |
25 | 27 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
26 | 28 | import static org.junit.jupiter.api.Assertions.assertNotNull;
|
27 | 29 | import static org.junit.jupiter.api.Assertions.assertNull;
|
@@ -109,4 +111,25 @@ void testDontUseParentParameters() {
|
109 | 111 | assertNotNull(jobParameters.getParameter("foo").getValue());
|
110 | 112 | }
|
111 | 113 |
|
| 114 | + @Test |
| 115 | + public void testGetKeysFromParentParametersWhenNotInExecutionContext() { |
| 116 | + DefaultJobParametersExtractor extractor = new DefaultJobParametersExtractor(); |
| 117 | + extractor.setUseAllParentParameters(false); |
| 118 | + |
| 119 | + JobExecution jobExecution = new JobExecution(0L, |
| 120 | + new JobParametersBuilder().addString("parentParam", "val").addDouble("foo", 22.2).toJobParameters()); |
| 121 | + |
| 122 | + StepExecution stepExecution = new StepExecution("step", jobExecution); |
| 123 | + |
| 124 | + stepExecution.getExecutionContext().put("foo", "11.1,java.lang.Double"); |
| 125 | + extractor.setKeys(new String[] { "foo", "parentParam" }); |
| 126 | + |
| 127 | + JobParameters jobParameters = extractor.getJobParameters(null, stepExecution); |
| 128 | + |
| 129 | + assertThat(jobParameters.getParameter("parentParam")).isNotNull() |
| 130 | + .extracting(JobParameter::getValue) |
| 131 | + .isEqualTo("val"); |
| 132 | + assertEquals(11.1, jobParameters.getDouble("foo")); |
| 133 | + } |
| 134 | + |
112 | 135 | }
|
0 commit comments