|
1 | 1 | /* |
2 | | - * Copyright 2006-2019 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. |
|
45 | 45 | import org.springframework.batch.core.Step; |
46 | 46 | import org.springframework.batch.core.StepExecution; |
47 | 47 | import org.springframework.batch.core.UnexpectedJobExecutionException; |
| 48 | +import org.springframework.batch.core.explore.JobExplorer; |
| 49 | +import org.springframework.batch.core.explore.support.SimpleJobExplorer; |
48 | 50 | import org.springframework.batch.core.listener.JobExecutionListenerSupport; |
49 | 51 | import org.springframework.batch.core.repository.JobRepository; |
50 | 52 | import org.springframework.batch.core.repository.dao.ExecutionContextDao; |
|
66 | 68 | * @author Lucas Ward |
67 | 69 | * @author Will Schipp |
68 | 70 | * @author Mahmoud Ben Hassine |
| 71 | + * @author Jinwoo Bae |
69 | 72 | */ |
70 | 73 | public class SimpleJobTests { |
71 | 74 |
|
72 | 75 | private JobRepository jobRepository; |
73 | 76 |
|
| 77 | + private JobExplorer jobExplorer; |
| 78 | + |
74 | 79 | private JobInstanceDao jobInstanceDao; |
75 | 80 |
|
76 | 81 | private JobExecutionDao jobExecutionDao; |
@@ -105,9 +110,11 @@ public void setUp() throws Exception { |
105 | 110 | stepExecutionDao = new MapStepExecutionDao(); |
106 | 111 | ecDao = new MapExecutionContextDao(); |
107 | 112 | jobRepository = new SimpleJobRepository(jobInstanceDao, jobExecutionDao, stepExecutionDao, ecDao); |
| 113 | + jobExplorer = new SimpleJobExplorer(jobInstanceDao, jobExecutionDao, stepExecutionDao, ecDao); |
108 | 114 | job = new SimpleJob(); |
109 | 115 | job.setJobRepository(jobRepository); |
110 | 116 |
|
| 117 | + |
111 | 118 | step1 = new StubStep("TestStep1", jobRepository); |
112 | 119 | step1.setCallback(new Runnable() { |
113 | 120 | @Override |
@@ -524,6 +531,43 @@ public void testGetStepNotExists() { |
524 | 531 | assertNull(step); |
525 | 532 | } |
526 | 533 |
|
| 534 | + @Test |
| 535 | + public void testGetMultipleJobParameters() throws Exception { |
| 536 | + StubStep failStep = new StubStep("failStep", jobRepository); |
| 537 | + |
| 538 | + failStep.setCallback(new Runnable() { |
| 539 | + @Override |
| 540 | + public void run() { |
| 541 | + throw new RuntimeException("An error occurred."); |
| 542 | + } |
| 543 | + }); |
| 544 | + |
| 545 | + job.setName("parametersTestJob"); |
| 546 | + job.setSteps(Arrays.asList(new Step[] { failStep })); |
| 547 | + |
| 548 | + JobParameters firstJobParameters = new JobParametersBuilder().addString("JobExecutionParameter", "first", false) |
| 549 | + .toJobParameters(); |
| 550 | + JobExecution jobexecution = jobRepository.createJobExecution(job.getName(), firstJobParameters); |
| 551 | + job.execute(jobexecution); |
| 552 | + |
| 553 | + List<JobExecution> jobExecutionList = jobExplorer.getJobExecutions(jobexecution.getJobInstance()); |
| 554 | + |
| 555 | + assertEquals(jobExecutionList.size(), 1); |
| 556 | + assertEquals(jobExecutionList.get(0).getJobParameters().getString("JobExecutionParameter"), "first"); |
| 557 | + |
| 558 | + JobParameters secondJobParameters = new JobParametersBuilder() |
| 559 | + .addString("JobExecutionParameter", "second", false).toJobParameters(); |
| 560 | + jobexecution = jobRepository.createJobExecution(job.getName(), secondJobParameters); |
| 561 | + job.execute(jobexecution); |
| 562 | + |
| 563 | + jobExecutionList = jobExplorer.getJobExecutions(jobexecution.getJobInstance()); |
| 564 | + |
| 565 | + assertEquals(jobExecutionList.size(), 2); |
| 566 | + assertEquals(jobExecutionList.get(0).getJobParameters().getString("JobExecutionParameter"), "second"); |
| 567 | + assertEquals(jobExecutionList.get(1).getJobParameters().getString("JobExecutionParameter"), "first"); |
| 568 | + |
| 569 | + } |
| 570 | + |
527 | 571 | /* |
528 | 572 | * Check JobRepository to ensure status is being saved. |
529 | 573 | */ |
|
0 commit comments