BATCH-1208: Modified PlaceholderTargetSource to remove the path from resolveStringValue() that handles values that start with "#{" and end with "}". This was causing problems for values like "#{run.id}" or "#{integer}-#{integer}" where replacements were expected. The special path was added to handle references, where a replacement should not take place. Since a replacement is not expected, removing the path caused an exception to be thrown to indicate that no replacement had occurred. This exception was changed to a logging statement to allow this case.
This commit is contained in:
@@ -29,7 +29,6 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.JobParametersBuilder;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.job.AbstractJob;
|
||||
@@ -113,9 +112,10 @@ public class ListPreparedStatementSetterTests {
|
||||
this.simpleJdbcTemplate.update("insert into FOO values (?,?,?)", 0, "zero", 0);
|
||||
this.simpleJdbcTemplate.update("insert into FOO values (?,?,?)", 1, "one", 1);
|
||||
this.simpleJdbcTemplate.update("insert into FOO values (?,?,?)", 2, "two", 2);
|
||||
this.simpleJdbcTemplate.update("insert into FOO values (?,?,?)", 3, "three", 3);
|
||||
|
||||
JobParameters params = new JobParametersBuilder().addLong("start.id", 1L).toJobParameters();
|
||||
JobExecution jobExecution = this.jobLauncher.run(this.job, params);
|
||||
JobParametersBuilder builder = new JobParametersBuilder().addLong("min.id", 1L).addLong("max.id", 2L);
|
||||
JobExecution jobExecution = this.jobLauncher.run(this.job, builder.toJobParameters());
|
||||
assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
|
||||
|
||||
List<Foo> foos = fooStoringItemWriter.getFoos();
|
||||
|
||||
@@ -74,15 +74,8 @@ public class PlaceholderTargetSourceErrorTests extends ContextFactorySupport {
|
||||
|
||||
@Test
|
||||
public void testPartialReplaceMissingProperty() throws Exception {
|
||||
try {
|
||||
Node target = (Node) createValue("name", "#{garbage}-bar").getTarget();
|
||||
assertEquals("bar", target.getName());
|
||||
fail("Expected IllegalStateException");
|
||||
}
|
||||
catch (Exception e) {
|
||||
String message = e.getMessage();
|
||||
assertTrue("Wrong message: " + message, message.toLowerCase().contains("cannot bind"));
|
||||
}
|
||||
Node target = (Node) createValue("name", "#{garbage}-bar").getTarget();
|
||||
assertEquals("#{garbage}-bar", target.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -39,6 +39,10 @@ public class PlaceholderTargetSourceTests extends ContextFactorySupport {
|
||||
@Qualifier("withMultiple")
|
||||
private PlaceholderTargetSource withMultiple;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("withMultipleStartAndEnd")
|
||||
private PlaceholderTargetSource withMultipleStartAndEnd;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("withEmbeddedDate")
|
||||
private PlaceholderTargetSource withEmbeddedDate;
|
||||
@@ -155,6 +159,12 @@ public class PlaceholderTargetSourceTests extends ContextFactorySupport {
|
||||
assertEquals("bar-4321-4321", target.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMultipleStartAndEnd() {
|
||||
Node target = (Node) withMultipleStartAndEnd.getTarget();
|
||||
assertEquals("4321-4321", target.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetEmbeddedDate() {
|
||||
Node target = (Node) withEmbeddedDate.getTarget();
|
||||
@@ -165,7 +175,9 @@ public class PlaceholderTargetSourceTests extends ContextFactorySupport {
|
||||
@Test
|
||||
public void testGetDate() {
|
||||
Node target = (Node) withDate.getTarget();
|
||||
assertEquals(1L, target.getDate().getTime());
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
|
||||
String date = sdf.format(new Date(1L));
|
||||
assertEquals(date, sdf.format(target.getDate()));
|
||||
}
|
||||
|
||||
public static interface Node {
|
||||
|
||||
Reference in New Issue
Block a user