|
1 | 1 | /*
|
2 |
| - * Copyright 2008-2013 the original author or authors. |
| 2 | + * Copyright 2008-2021 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.
|
|
15 | 15 | */
|
16 | 16 | package org.springframework.batch.core.repository.dao;
|
17 | 17 |
|
| 18 | +import java.util.Date; |
| 19 | +import java.util.HashMap; |
| 20 | +import java.util.List; |
| 21 | +import java.util.Map; |
| 22 | + |
18 | 23 | import javax.sql.DataSource;
|
19 | 24 |
|
| 25 | +import static org.junit.Assert.assertNull; |
| 26 | +import org.junit.Test; |
20 | 27 | import org.junit.runner.RunWith;
|
| 28 | + |
| 29 | +import org.springframework.batch.core.JobExecution; |
| 30 | +import org.springframework.batch.core.JobParameter; |
| 31 | +import org.springframework.batch.core.JobParameters; |
21 | 32 | import org.springframework.beans.factory.annotation.Autowired;
|
22 | 33 | import org.springframework.jdbc.core.JdbcTemplate;
|
| 34 | +import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; |
| 35 | +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; |
| 36 | +import org.springframework.jdbc.core.namedparam.SqlParameterSource; |
23 | 37 | import org.springframework.test.context.ContextConfiguration;
|
24 | 38 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
25 | 39 | import org.springframework.test.jdbc.JdbcTestUtils;
|
| 40 | +import org.springframework.transaction.annotation.Transactional; |
26 | 41 |
|
| 42 | +/** |
| 43 | + * @author Parikshit Dutta |
| 44 | + */ |
27 | 45 | @RunWith(SpringJUnit4ClassRunner.class)
|
28 | 46 | @ContextConfiguration(locations = { "sql-dao-test.xml" })
|
29 | 47 | public class JdbcJobExecutionDaoTests extends AbstractJobExecutionDaoTests {
|
@@ -62,4 +80,35 @@ protected StepExecutionDao getStepExecutionDao() {
|
62 | 80 | return stepExecutionDao;
|
63 | 81 | }
|
64 | 82 |
|
| 83 | + @Transactional |
| 84 | + @Test |
| 85 | + public void testSavedDateIsNullForNonDateTypeJobParams() { |
| 86 | + final String FIND_DATE_PARAM_FROM_ID = "SELECT DATE_VAL " + |
| 87 | + "from %PREFIX%JOB_EXECUTION_PARAMS where JOB_EXECUTION_ID = :JOB_EXECUTION_ID"; |
| 88 | + |
| 89 | + Map<String,JobParameter> parameters = new HashMap<>(); |
| 90 | + parameters.put("string-param", new JobParameter("value")); |
| 91 | + parameters.put("long-param", new JobParameter(1L)); |
| 92 | + parameters.put("double-param", new JobParameter(1D)); |
| 93 | + |
| 94 | + JobExecution execution = new JobExecution(jobInstance, new JobParameters(parameters)); |
| 95 | + dao.saveJobExecution(execution); |
| 96 | + |
| 97 | + List<JobExecution> executions = dao.findJobExecutions(jobInstance); |
| 98 | + JobExecution savedJobExecution = executions.get(0); |
| 99 | + |
| 100 | + NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate( |
| 101 | + jdbcTemplate.getDataSource()); |
| 102 | + |
| 103 | + JdbcJobExecutionDao jdbcJobExecutionDao = (JdbcJobExecutionDao) jobExecutionDao; |
| 104 | + String query = jdbcJobExecutionDao.getQuery(FIND_DATE_PARAM_FROM_ID); |
| 105 | + |
| 106 | + SqlParameterSource namedParameters = new MapSqlParameterSource() |
| 107 | + .addValue("JOB_EXECUTION_ID", savedJobExecution.getJobId()); |
| 108 | + |
| 109 | + List<Date> paramValues = namedParameterJdbcTemplate.queryForList(query, namedParameters, Date.class); |
| 110 | + for (Date paramValue: paramValues) { |
| 111 | + assertNull(paramValue); |
| 112 | + } |
| 113 | + } |
65 | 114 | }
|
0 commit comments