-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
91 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/test/java/com/springbatch/excel/tutorial/BachIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.springbatch.excel.tutorial; | ||
import com.springbatch.excel.tutorial.batch.BatchConfiguration; | ||
import com.springbatch.excel.tutorial.batch.listeners.JobCompletionListener; | ||
import com.springbatch.excel.tutorial.domain.Employee; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.batch.core.Job; | ||
import org.springframework.batch.core.JobExecution; | ||
import org.springframework.batch.core.JobParameter; | ||
import org.springframework.batch.core.JobParameters; | ||
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; | ||
import org.springframework.batch.core.launch.JobLauncher; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.data.mongodb.core.MongoTemplate; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
|
||
import java.util.*; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
|
||
|
||
@ExtendWith(SpringExtension.class) | ||
@EnableBatchProcessing | ||
@ComponentScan(basePackages = "com.springbatch.excel.tutorial") | ||
@SpringBootTest(classes = {BatchConfiguration.class, JobCompletionListener.class}) | ||
class BatchIntegrationTest { | ||
|
||
@Autowired | ||
private JobLauncher jobLauncher; | ||
|
||
@Autowired | ||
private Job jsonFileProcessingJob; | ||
|
||
@Autowired | ||
private MongoTemplate mongoTemplate; | ||
|
||
@Test | ||
void testBatchJob() throws Exception { | ||
String absolutePath = Objects.requireNonNull(getClass().getResource("/data/processing/employee.xlsx")).getPath(); | ||
|
||
// Créez les paramètres du job | ||
Map<String, JobParameter> jobParameters = new HashMap<>(); | ||
jobParameters.put("filePath", new JobParameter(absolutePath)); | ||
jobParameters.put("currentTime", new JobParameter(new Date())); | ||
|
||
// Lancez le job avec les paramètres | ||
JobExecution jobExecution = jobLauncher.run(jsonFileProcessingJob,new JobParameters(jobParameters)); | ||
|
||
// Vérifiez que le job s'est terminé avec succès | ||
assertThat(jobExecution.getExitStatus().getExitCode()).isEqualTo("COMPLETED"); | ||
|
||
List<Employee> couponOffers = mongoTemplate.findAll(Employee.class); | ||
assertThat(couponOffers.size()).isEqualTo(100); | ||
|
||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
spring: | ||
data: | ||
mongodb: | ||
host: localhost | ||
port: 27017 | ||
database: spring_batch_excel_mongodb_db | ||
# username: admin | ||
# password: pass | ||
auto-index-creation: true | ||
|
||
jackson: | ||
default-property-inclusion: NON_NULL | ||
#disabled job run at startup | ||
batch: | ||
job: | ||
enabled: false | ||
|
||
# Enable Logging mongo queries | ||
logging: | ||
level: | ||
org.springframework.data.mongodb.core.MongoTemplate: DEBUG | ||
|
||
employee: | ||
excel: | ||
processingfolder: data/processing/ | ||
resultsfolder: data/results/ |
Empty file.
Binary file not shown.
Empty file.