|
18 | 18 |
|
19 | 19 | import java.util.HashMap;
|
20 | 20 | import java.util.Map;
|
| 21 | +import java.util.Properties; |
21 | 22 |
|
22 | 23 | import javax.sql.DataSource;
|
23 | 24 |
|
|
30 | 31 | import org.quartz.SchedulerFactory;
|
31 | 32 | import org.quartz.impl.JobDetailImpl;
|
32 | 33 | import org.quartz.impl.SchedulerRepository;
|
| 34 | +import org.quartz.impl.jdbcjobstore.JobStoreTX; |
33 | 35 |
|
34 | 36 | import org.springframework.beans.factory.config.BeanDefinition;
|
35 | 37 | import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
|
40 | 42 | import org.springframework.core.task.TaskExecutor;
|
41 | 43 | import org.springframework.core.testfixture.EnabledForTestGroups;
|
42 | 44 | import org.springframework.jdbc.core.JdbcTemplate;
|
| 45 | +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase; |
| 46 | +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; |
43 | 47 |
|
44 | 48 | import static org.assertj.core.api.Assertions.assertThat;
|
45 | 49 | import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
@@ -396,6 +400,29 @@ public void schedulerWithHsqlDataSource() throws Exception {
|
396 | 400 | }
|
397 | 401 | }
|
398 | 402 |
|
| 403 | + @Test |
| 404 | + public void schedulerFactoryBeanWithCustomJobStore() throws Exception { |
| 405 | + StaticApplicationContext context = new StaticApplicationContext(); |
| 406 | + |
| 407 | + final String dbName = "mydb"; |
| 408 | + final EmbeddedDatabase database = new EmbeddedDatabaseBuilder().setName(dbName).build(); |
| 409 | + |
| 410 | + final Properties properties = new Properties(); |
| 411 | + properties.setProperty("org.quartz.jobStore.class", JobStoreTX.class.getName()); |
| 412 | + properties.setProperty("org.quartz.jobStore.dataSource", dbName); |
| 413 | + |
| 414 | + BeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition(SchedulerFactoryBean.class) |
| 415 | + .addPropertyValue("autoStartup", false) |
| 416 | + .addPropertyValue("dataSource", database) |
| 417 | + .addPropertyValue("quartzProperties", properties) |
| 418 | + .getBeanDefinition(); |
| 419 | + context.registerBeanDefinition("scheduler", beanDefinition); |
| 420 | + |
| 421 | + Scheduler bean = context.getBean("scheduler", Scheduler.class); |
| 422 | + |
| 423 | + assertThat(bean.getMetaData().getJobStoreClass()).isEqualTo(JobStoreTX.class); |
| 424 | + } |
| 425 | + |
399 | 426 | private ClassPathXmlApplicationContext context(String path) {
|
400 | 427 | return new ClassPathXmlApplicationContext(path, getClass());
|
401 | 428 | }
|
|
0 commit comments