1515 */
1616package org .springframework .batch .core .repository .support ;
1717
18+ import java .io .IOException ;
19+ import java .nio .file .Files ;
1820import java .time .LocalDateTime ;
19- import java .util .Map ;
2021
2122import com .mongodb .client .MongoCollection ;
2223import org .bson .Document ;
2324import org .junit .jupiter .api .Assertions ;
2425import org .junit .jupiter .api .BeforeEach ;
2526import org .junit .jupiter .api .Test ;
26- import org .springframework .test .annotation .DirtiesContext ;
27- import org .springframework .data .domain .Sort ;
28- import org .springframework .data .mongodb .core .index .Index ;
29- import org .springframework .test .context .junit .jupiter .SpringJUnitConfig ;
3027import org .testcontainers .junit .jupiter .Testcontainers ;
3128
3229import org .springframework .batch .core .ExitStatus ;
3633import org .springframework .batch .core .job .parameters .JobParametersBuilder ;
3734import org .springframework .batch .core .launch .JobOperator ;
3835import org .springframework .beans .factory .annotation .Autowired ;
36+ import org .springframework .core .io .ClassPathResource ;
3937import org .springframework .data .mongodb .core .MongoTemplate ;
38+ import org .springframework .test .annotation .DirtiesContext ;
39+ import org .springframework .test .context .junit .jupiter .SpringJUnitConfig ;
4040
4141/**
4242 * @author Mahmoud Ben Hassine
@@ -51,36 +51,9 @@ public class MongoDBJobRepositoryIntegrationTests {
5151 private MongoTemplate mongoTemplate ;
5252
5353 @ BeforeEach
54- public void setUp () {
55- // collections
56- mongoTemplate .createCollection ("BATCH_JOB_INSTANCE" );
57- mongoTemplate .createCollection ("BATCH_JOB_EXECUTION" );
58- mongoTemplate .createCollection ("BATCH_STEP_EXECUTION" );
59- // sequences
60- mongoTemplate .createCollection ("BATCH_SEQUENCES" );
61- mongoTemplate .getCollection ("BATCH_SEQUENCES" )
62- .insertOne (new Document (Map .of ("_id" , "BATCH_JOB_INSTANCE_SEQ" , "count" , 0L )));
63- mongoTemplate .getCollection ("BATCH_SEQUENCES" )
64- .insertOne (new Document (Map .of ("_id" , "BATCH_JOB_EXECUTION_SEQ" , "count" , 0L )));
65- mongoTemplate .getCollection ("BATCH_SEQUENCES" )
66- .insertOne (new Document (Map .of ("_id" , "BATCH_STEP_EXECUTION_SEQ" , "count" , 0L )));
67- // indices
68- mongoTemplate .indexOps ("BATCH_JOB_INSTANCE" )
69- .createIndex (new Index ().on ("jobName" , Sort .Direction .ASC ).named ("job_name_idx" ));
70- mongoTemplate .indexOps ("BATCH_JOB_INSTANCE" )
71- .createIndex (new Index ().on ("jobName" , Sort .Direction .ASC )
72- .on ("jobKey" , Sort .Direction .ASC )
73- .named ("job_name_key_idx" ));
74- mongoTemplate .indexOps ("BATCH_JOB_INSTANCE" )
75- .createIndex (new Index ().on ("jobInstanceId" , Sort .Direction .DESC ).named ("job_instance_idx" ));
76- mongoTemplate .indexOps ("BATCH_JOB_EXECUTION" )
77- .createIndex (new Index ().on ("jobInstanceId" , Sort .Direction .ASC ).named ("job_instance_idx" ));
78- mongoTemplate .indexOps ("BATCH_JOB_EXECUTION" )
79- .createIndex (new Index ().on ("jobInstanceId" , Sort .Direction .ASC )
80- .on ("status" , Sort .Direction .ASC )
81- .named ("job_instance_status_idx" ));
82- mongoTemplate .indexOps ("BATCH_STEP_EXECUTION" )
83- .createIndex (new Index ().on ("stepExecutionId" , Sort .Direction .ASC ).named ("step_execution_idx" ));
54+ public void setUp () throws IOException {
55+ ClassPathResource resource = new ClassPathResource ("org/springframework/batch/core/schema-mongodb.json" );
56+ Files .lines (resource .getFilePath ()).forEach (line -> mongoTemplate .executeCommand (line ));
8457 }
8558
8659 @ Test
0 commit comments